Bug #8378

json/generator/generator.c: warning: array subscript has type 'char'

Added by Akira Tanaka 12 months ago. Updated 12 months ago.

[ruby-dev:47325]
Status:Closed
Priority:Normal
Assignee:-
Category:-
Target version:-
ruby -v:r40599 ruby 2.1.0dev (2013-05-07) [i386-cygwin] Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN

Description

ふと、cygwin を target とする cross-compile をしてみたところ、
以下の警告を見つけました。
(たぶん cross でなくても警告されると思います)

make[2]: Entering directory `/extdisk/chkbuild/chkbuild/tmp/build/20130507T115727Z/ruby/ext/json/generator'
compiling generator.c
generator.c: In function 'isArrayOrObject':
generator.c:897:5: warning: array subscript has type 'char' [-Wchar-subscripts]
generator.c:898:5: warning: array subscript has type 'char' [-Wchar-subscripts]
linking shared-object json/ext/generator.so

http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-cygwin/log/20130507T115727Z.log.html.gz

コードを見てみると以下のようになっていて、
char * を dereference した結果を isspace に渡しています。

895 char p = RSTRINGPTR(string), *q = p + stringlen - 1;
896 if (string_len < 2) return 0;
897 for (; p < q && isspace(
p); p++);
898 for (; q > p && isspace(q); q--);
899 return (
p == '[' && q == ']') || (p == '{' && *q == '}');

char が signed な環境では、*p や *q は負になるかもしれないのでよろしくなくて、
*(unsigned char *)p とかにしたほうがいんじゃないでしょうか。

Associated revisions

Revision 40609
Added by Yui NARUSE 12 months ago

  • ext/json/generator/generator.c (isArrayOrObject): cast char to unsigned char. [Bug #8378]

History

#1 Updated by Yui NARUSE 12 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40609.
Akira, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/json/generator/generator.c (isArrayOrObject): cast char to unsigned char. [Bug #8378]

Also available in: Atom PDF