| Issue 9: | fastmemcmp_inlined is incorrect | |
| 1 person starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem?
char a[] = {0, 0, 0, 0x80};
char b[] = {0, 0, 0, 0x01};
assert(fastmemcmp_inlined(a, b, 4) == memcmp(a, b, 4));
What is the expected output? What do you see instead?
memcmp is supposed to be bytewise lexicographic comparison, but there is a bug in the inlined implementation:
while (a < a_limit) {
int d = static_cast<uint32>(*a++) - static_cast<uint32>(*b++);
if (d) return d;
}
incorrectly upcasts from 'const char *' to uint32, which has sign-extension behavior.
The arguments here should probably be made into const void * to match the signature of memcmp.
What version of the product are you using? On what operating system?
68c456e59482a26c595a9f4c5cc3d661e56a21b0
Jan 18, 2013
Project Member
#1
p...@google.com
Status:
Fixed
|