Feature #8890
closed[PATCH] Eliminate less-than-zero checks for unsigned variables
Description
According to section 7.17 of C99 standard (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) size_t is an unsigned type. What do you think about the following patch which changes less-than-zero checks to equal-zero for unsigned (including size_t) variables?
These checks were found with 'cppcheck' static analysis tool.
Files
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Description updated (diff)
Currently we don't assume C99, but C89.
Updated by tonyo (Anton Ovchinnikov) over 10 years ago
OK, same for C89: http://port70.net/~nsz/c/c89/c89-draft.html, section 4.1.5.
Updated by kosaki (Motohiro KOSAKI) over 10 years ago
It would be nice configure script abort if detect signed size_t. It protects us from crazy and invalid platform issue.
Other than that, the patch looks good to me.
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r42920.
Anton, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
Eliminate less-than-zero checks for unsigned variables
- ext/bigdecimal/bigdecimal.c, ext/digest/md5/md5.c,
ext/json/fbuffer/fbuffer.h, ext/json/generator/generator.c:
Eliminate less-than-zero checks for unsigned variables.
According to section 4.1.5 of C89 standard, size_t is an unsigned
type. These checks were found with 'cppcheck' static analysis tool.
[ruby-core:57117] [Feature #8890]