[ruby-dev:18365] Re: compile with -Wall
From:
nobu.nakada@...
Date:
2002-09-24 01:13:18 UTC
List:
ruby-dev #18365
なかだです。
At Mon, 23 Sep 2002 23:36:18 +0900,
Nobuyoshi-Nakada wrote:
> parse.yを-Wallでコンパイルしたら結構いろいろ警告が出たので確認
他のも確認してみました。ほとんどは条件式に代入を直接使ってると
か、使用してない変数/関数というものですが、いくつかまずそうな点
も。
* dir.c (glob_helper): "**"で再帰中に例外が起きると未初期化の
dirpでclosedir()してしまう
* eval.c (call_trace_func, rb_eval, rb_call0): EXEC_TAG()で復帰
するはずの変数がvolatileになっていない
* eval.c (eval, rb_thread_schedule, rb_thread_start_0): 上と同
様(ただし、頻繁に使われている変数なのであまりvolatileにした
くない)
*(volatile VALUE *)&value = value;って効果あるもんでしょうか。
* regex.c (re_compile_pattern): おそらくplain charからの暗黙の
型変換は危険
Index: dir.c
===================================================================
RCS file: /cvs/ruby/src/ruby/dir.c,v
retrieving revision 1.75
diff -u -2 -p -r1.75 dir.c
--- dir.c 13 Sep 2002 14:46:44 -0000 1.75
+++ dir.c 23 Sep 2002 23:47:04 -0000
@@ -157,5 +157,5 @@ fnmatch(pat, string, flags)
int nocase = flags & FNM_CASEFOLD;
- while (c = *pat++) {
+ while ((c = *pat++) != 0) {
switch (c) {
case '?':
@@ -790,5 +790,5 @@ glob_helper(path, sub, flags, func, arg)
status = glob_helper(buf, t, flags, func, arg);
free(buf);
- if (status) goto finalize;
+ if (status) break;
continue;
}
@@ -802,5 +802,5 @@ glob_helper(path, sub, flags, func, arg)
status = glob_call_func(func, buf, arg);
free(buf);
- if (status) goto finalize;
+ if (status) break;
continue;
}
@@ -811,6 +811,6 @@ glob_helper(path, sub, flags, func, arg)
}
}
- finalize:
closedir(dirp);
+ finalize:
free(base);
free(magic);
Index: eval.c
===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.334
diff -u -2 -p -r1.334 eval.c
--- eval.c 23 Sep 2002 15:48:42 -0000 1.334
+++ eval.c 24 Sep 2002 00:17:30 -0000
@@ -999,5 +999,5 @@ error_print()
if (RSTRING(epath)->ptr[0] == '#') epath = 0;
- if (tail = strchr(einfo, '\n')) {
+ if ((tail = strchr(einfo, '\n')) != 0) {
len = tail - einfo;
tail++; /* skip newline */
@@ -1865,5 +1865,5 @@ is_defined(self, node, buf)
check_bound:
{
- int call = nd_type(node)== NODE_CALL;
+ int call = nd_type(node) == NODE_CALL;
val = CLASS_OF(val);
@@ -2056,5 +2056,5 @@ call_trace_func(event, node, self, id, k
int state;
struct FRAME *prev;
- NODE *node_save[2];
+ NODE *volatile node_save[2];
VALUE srcfile;
@@ -2787,5 +2787,5 @@ rb_eval(self, n)
{
struct FRAME frame;
- NODE *saved_cref = 0;
+ NODE *volatile saved_cref = 0;
frame = *ruby_frame;
@@ -4119,5 +4119,5 @@ rb_rescue2(b_proc, data1, r_proc, data2,
va_init_list(args, data2);
- while (eclass = va_arg(args, VALUE)) {
+ while ((eclass = va_arg(args, VALUE)) != 0) {
if (rb_obj_is_kind_of(ruby_errinfo, eclass)) {
handle = Qtrue;
@@ -4542,5 +4542,5 @@ rb_call0(klass, recv, id, oid, argc, arg
int state;
VALUE *local_vars; /* OK */
- NODE *saved_cref = 0;
+ NODE *volatile saved_cref = 0;
PUSH_SCOPE();
@@ -4979,5 +4979,5 @@ eval(self, src, scope, file, line)
}
- Data_Get_Struct(scope, struct BLOCK, data);
+ Data_Get_Struct(scope, struct BLOCK, *(struct BLOCK *volatile *)&data);
/* PUSH BLOCK from data */
frame = data->frame;
@@ -5015,4 +5015,5 @@ eval(self, src, scope, file, line)
line = ruby_sourceline;
}
+ *(char *volatile *)&file = file;
PUSH_CLASS();
ruby_class = ruby_cbase;
@@ -5047,4 +5048,5 @@ eval(self, src, scope, file, line)
ruby_block = old_block;
ruby_dyna_vars = old_dyna_vars;
+ data = (*(struct BLOCK *volatile *)&data);
data->vmode = scope_vmode; /* write back visibility mode */
scope_vmode = old_vmode;
@@ -8085,4 +8086,5 @@ rb_thread_schedule()
return;
}
+ *(volatile rb_thread_t *)&next = next;
/* context switch */
@@ -8093,4 +8095,5 @@ rb_thread_schedule()
}
+ next = *(volatile rb_thread_t *)&next;
curr_thread = next;
if (next->status == THREAD_TO_KILL) {
@@ -8713,4 +8716,5 @@ rb_thread_start_0(fn, arg, th_arg)
saved_block = ruby_block = dummy.prev;
}
+ *(struct BLOCK *volatile *)&saved_block = saved_block;
scope_dup(ruby_scope);
@@ -8738,4 +8742,5 @@ rb_thread_start_0(fn, arg, th_arg)
rb_thread_remove(th);
+ saved_block = *(struct BLOCK *volatile *)&saved_block;
while (saved_block) {
struct BLOCK *tmp = saved_block;
Index: marshal.c
===================================================================
RCS file: /cvs/ruby/src/ruby/marshal.c,v
retrieving revision 1.71
diff -u -2 -p -r1.71 marshal.c
--- marshal.c 17 Sep 2002 09:36:05 -0000 1.71
+++ marshal.c 24 Sep 2002 00:25:10 -0000
@@ -294,5 +294,4 @@ w_uclass(obj, base_klass, arg)
{
VALUE klass = CLASS_OF(obj);
- char *path;
w_extended(klass, arg);
@@ -372,5 +371,5 @@ w_object(obj, arg, limit)
if (OBJ_TAINTED(obj)) arg->taint = Qtrue;
- if (ivtbl = rb_generic_ivar_table(obj)) {
+ if ((ivtbl = rb_generic_ivar_table(obj)) != 0) {
w_byte(TYPE_IVAR, arg);
}
Index: process.c
===================================================================
RCS file: /cvs/ruby/src/ruby/process.c,v
retrieving revision 1.56
diff -u -2 -p -r1.56 process.c
--- process.c 17 Sep 2002 13:52:45 -0000 1.56
+++ process.c 24 Sep 2002 00:33:06 -0000
@@ -553,6 +553,6 @@ rb_proc_exec(str)
ss = ALLOCA_N(char, s-str+1);
strcpy(ss, str);
- if (*a++ = strtok(ss, " \t")) {
- while (t = strtok(NULL, " \t")) {
+ if ((*a++ = strtok(ss, " \t")) != 0) {
+ while ((t = strtok(NULL, " \t")) != 0) {
*a++ = t;
}
Index: re.c
===================================================================
RCS file: /cvs/ruby/src/ruby/re.c,v
retrieving revision 1.82
diff -u -2 -p -r1.82 re.c
--- re.c 16 Sep 2002 15:56:31 -0000 1.82
+++ re.c 23 Sep 2002 23:44:37 -0000
@@ -80,5 +80,6 @@ rb_memcicmp(p1, p2, len)
while (len--) {
- if (tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++])
+ tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++];
+ if (tmp)
return tmp;
}
@@ -525,21 +526,4 @@ match_alloc(klass)
return (VALUE)match;
-}
-
-static VALUE
-match_clone(match)
- VALUE match;
-{
- NEWOBJ(clone, struct RMatch);
- CLONESETUP(clone, match);
-
- clone->str = RMATCH(match)->str;
- clone->regs = 0;
-
- clone->regs = ALLOC(struct re_registers);
- clone->regs->allocated = 0;
- re_copy_registers(clone->regs, RMATCH(match)->regs);
-
- return (VALUE)clone;
}
Index: regex.c
===================================================================
RCS file: /cvs/ruby/src/ruby/regex.c,v
retrieving revision 1.72
diff -u -2 -p -r1.72 regex.c
--- regex.c 14 Jun 2002 06:27:18 -0000 1.72
+++ regex.c 23 Sep 2002 23:39:15 -0000
@@ -1684,7 +1684,7 @@ re_compile_pattern(pattern, size, bufp)
b[-1]--;
if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH)
- memmove(&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH],
+ memmove(&b[(unsigned char)b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH],
2 + EXTRACT_UNSIGNED(&b[(1 << BYTEWIDTH) / BYTEWIDTH])*8);
- b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[b[-1]])*8;
+ b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[(unsigned char)b[-1]])*8;
break;
@@ -2195,7 +2195,7 @@ re_compile_pattern(pattern, size, bufp)
b[-1]--;
if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH)
- memmove(&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH],
+ memmove(&b[(unsigned char)b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH],
2 + EXTRACT_UNSIGNED(&b[(1 << BYTEWIDTH) / BYTEWIDTH])*8);
- b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[b[-1]])*8;
+ b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[(unsigned char)b[-1]])*8;
break;
Index: ruby.c
===================================================================
RCS file: /cvs/ruby/src/ruby/ruby.c,v
retrieving revision 1.67
diff -u -2 -p -r1.67 ruby.c
--- ruby.c 22 Sep 2002 12:52:18 -0000 1.67
+++ ruby.c 23 Sep 2002 23:24:42 -0000
@@ -188,5 +188,5 @@ ruby_incpush(path)
while (*p) {
while (*p == sep) p++;
- if (s = strchr(p, sep)) {
+ if ((s = strchr(p, sep)) != 0) {
rb_ary_push(ary, rubylib_mangled_path(p, (int)(s-p)));
p = s + 1;
@@ -357,5 +357,5 @@ process_sflag()
s[0] = '$';
- if (p = strchr(s, '=')) {
+ if ((p = strchr(s, '=')) != 0) {
*p++ = '\0';
rb_gv_set(s, rb_str_new2(p));
@@ -598,5 +598,5 @@ proc_options(argc, argv)
case '-':
- if (!s[1] || s[1] == '\r' && !s[2]) {
+ if (!s[1] || (s[1] == '\r' && !s[2])) {
argc--,argv++;
goto switch_end;
@@ -785,5 +785,5 @@ load_file(fname, script)
&& RSTRING(line)->ptr[0] == '#'
&& RSTRING(line)->ptr[1] == '!') {
- if (p = strstr(RSTRING(line)->ptr, "ruby")) {
+ if ((p = strstr(RSTRING(line)->ptr, "ruby")) != 0) {
goto start_read;
}
@@ -837,5 +837,5 @@ load_file(fname, script)
if (RSTRING(line)->ptr[RSTRING(line)->len-2] == '\r')
RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0';
- if (p = strstr(p, " -")) {
+ if ((p = strstr(p, " -")) != 0) {
p++; /* skip space before `-' */
while (*p == '-') {
Index: struct.c
===================================================================
RCS file: /cvs/ruby/src/ruby/struct.c,v
retrieving revision 1.37
diff -u -2 -p -r1.37 struct.c
--- struct.c 3 Sep 2002 05:20:06 -0000 1.37
+++ struct.c 23 Sep 2002 23:39:24 -0000
@@ -214,5 +214,5 @@ rb_struct_define(name, va_alist)
va_init_list(ar, name);
- while (mem = va_arg(ar, char*)) {
+ while ((mem = va_arg(ar, char*)) != 0) {
ID slot = rb_intern(mem);
rb_ary_push(ary, ID2SYM(slot));
--
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
中田 伸悦