This is a shitty way to test for a buffer full of zeros.
bool testZeros(unsigned char *p, int len)
{
for (int i = 0; i < len; i++)
{
if (*p != 0)
return false;
}
return true;
}
It's like a teenager who gets a job doing surveys. He goes to the first house on the street, knocks, gets no answer. He writes "Not Home" in his log book. Then he shrugs and writes "Not Home" next to all the slots for all the other houses on the street, too. Goes home and jerks off for a hour. And he does this every day for a year.
And then someone spends weeks trying to figure out why nobody from that block is ever home.

Even if it had the p++ line in it, there’s got to be a more optimal solution, especially if it’s called very frequently. (I’m guessing it’s not though, or it would have been found much sooner.). If nothing else one could cast p to a long*, and only do a quarter of the comparisons, as long as one remembered to check the odd bytes at the end of the array.
multi-platform development beat those kinds of optimizations out of me pretty well.
sizeof(int) can be 4 or 8. and some platforms would scream (well, crash) if you tried to cast an unaligned ptr to an int (and the alignment varies across platform – 4, 8, etc). for my own stuff, on Windows, i’ll spend an afternoon fiddling with timing on stuff like that. but i try to just keep stuff like that very simple, at work.
Huh, weird that this comment even posted. I was trying to do it from the mobile version of the site, which I don’t think I’ve ever posted a comment from, and when I clicked Post Comment it would tell me there was a field I had not filled in. Hmm… Only three fields there, and all have text in them. Click Post again, same message. Give up.
and my previous comment was the 5th attempt. the first four were from teh WordPress iOS app. the ‘PUBLISH’ button at the bottom of the form would never ‘click’. it just sat there mocking me.