Project

General

Profile

Feature #8890

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

Added by tonyo (Anton Ovchinnikov) over 7 years ago. Updated over 7 years ago.

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

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 7 years ago

  • Description updated (diff)

Currently we don't assume C99, but C89.

Updated by kosaki (Motohiro KOSAKI) over 7 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.

#4

Updated by nobu (Nobuyoshi Nakada) over 7 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]

Also available in: Atom PDF