-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Medium
-
Code Generation Tools
-
CODEGEN-7227
-
-
-
default
-
Avoid writing a do-while loop in which the loop variable wraps around on the first iteration. For instance, use a signed loop variable or a while-loop.
-
The attached file contains an implementation of strnlen.
size_t strnlen_wtf(const char *s, size_t maxlen)
{
size_t n = (size_t)-1;
do n++; while ( (*s++) && (n < maxlen) );
return n;
}
Build it ...
% cl2000 -o2 -s try1.c
Inspect the resulting assembly to see that it is optimized into a function that always returns the value 0.
Please see the associated forum thread for more context.