Hi there,
i previously had a function which can wait for a array of threads to finish - implemented in C99:
bool fpl__Win32ThreadWaitForMultiple(fplThreadHandle **threads, const size_t count, const fplTimeoutValue timeout) {
for (size_t index = 0; index < count; ++index) {
fplThreadHandle *thread = threads[index];
if (thread == fpl_null) {
return false;
}
// ... Check the thread
}
return true;
}
This was fine for a very long time, but now i encountered a case where my thread handle pointers are not following in order (Not contiguously), so i introduced a "stride" argument to account for that:
bool fpl__Win32ThreadWaitForMultiple(fplThreadHandle **threads, const size_t count, const size_t stride, const fplTimeoutValue timeout {
for (size_t index = 0; index < count; ++index) {
fplThreadHandle *thread = *(fplThreadHandle **)((uint8_t *)threads + index * stride);
if (thread == fpl_null) {
return false;
}
// ... Check the thread
}
return true;
}
This works fine unless you pass an invalid stride which results in either a invalid memory address or just garbage.
Now it comes the actual question -> Is there a way to detect such garbage memory addresses? Obviously a NULL check is not sufficient enough.
Visual studio reported a 0x21 as a write access violation...
I understand that i can detect any cases, but i would love to detect at least the most common cases.
I dont assume i can just check for "0x0000000000000021" on x64 isn´t it?