Bug #8378
closedjson/generator/generator.c: warning: array subscript has type 'char'
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 = RSTRING_PTR(string), *q = p + string_len - 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 とかにしたほうがいんじゃないでしょうか。
Updated by naruse (Yui NARUSE) over 11 years 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]