Feature #8890

[PATCH] Eliminate less-than-zero checks for unsigned variables

Added by Anton Ovchinnikov 8 months ago. Updated 7 months ago.

[ruby-core:57117]
Status:Closed
Priority:Low
Assignee:-
Category:-
Target version:-

Description

According to section 7.17 of C99 standard (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) sizet is an unsigned type. What do you think about the following patch which changes less-than-zero checks to equal-zero for unsigned (including sizet) variables?

These checks were found with 'cppcheck' static analysis tool.

0001-Eliminate-less-than-zero-checks-for-unsigned-variabl.patch Magnifier (3.04 KB) Anton Ovchinnikov, 09/11/2013 06:37 AM

Associated revisions

Revision 42920
Added by Nobuyoshi Nakada 7 months ago

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. [Feature #8890]

Revision 42921
Added by Nobuyoshi Nakada 7 months ago

configure.in: size_t must be unsigned

  • configure.in (RUBYCHECKSIGNEDNESS): macro to check signedness of a type.
  • configure.in (size_t): must be unsigned. [Feature #8890]

History

#1 Updated by Nobuyoshi Nakada 7 months ago

  • Description updated (diff)

Currently we don't assume C99, but C89.

#2 Updated by Anton Ovchinnikov 7 months ago

OK, same for C89: http://port70.net/~nsz/c/c89/c89-draft.html, section 4.1.5.

#3 Updated by Motohiro KOSAKI 7 months 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.

#4 Updated by Nobuyoshi Nakada 7 months 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. [Feature #8890]

Also available in: Atom PDF