[前][次][番号順一覧][スレッド一覧]

ruby-changes:57905

From: Yusuke <ko1@a...>
Date: Thu, 26 Sep 2019 11:39:56 +0900 (JST)
Subject: [ruby-changes:57905] 1fe73dc860 (master): include/ruby/ruby.h: suppress a false-positive warning of GCC

https://git.ruby-lang.org/ruby.git/commit/?id=1fe73dc860

From 1fe73dc8609c4bac9e517dc70f602a16dae556cc Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Thu, 26 Sep 2019 11:35:01 +0900
Subject: include/ruby/ruby.h: suppress a false-positive warning of GCC

GCC emits a lot of false positives for rb_scan_args because:

* `rb_scan_args(argc, argv, "*:", NULL, &opts);` makes `n_mand == 0`,
* `n_mand == argc + 1` implies `argc == -1`, and
* `memcpy(ptr, argv, sizeof(VALUE)*argc);` explodes

However, we know that argc is never so big, thus this is a false
positive.  This change suppresses it by adding a condition `n_mand > 0`.

```
In file included from /usr/include/string.h:494,
                 from ./include/ruby/defines.h:145,
                 from ./include/ruby/ruby.h:29,
                 from ./include/ruby/encoding.h:27,
                 from dir.c:14:
In function 'memcpy',
    inlined from 'ruby_nonempty_memcpy.part.0' at ./include/ruby/ruby.h:1763:17,
    inlined from 'ruby_nonempty_memcpy' at ./include/ruby/ruby.h:1760:1,
    inlined from 'rb_scan_args_set' at ./include/ruby/ruby.h:2594:9,
    inlined from 'dir_s_aref' at dir.c:2774:12:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:10: warning: '__builtin___memcpy_chk' pointer overflow between offset 0 and size [-8, 9223372036854775807] [-Warray-bounds]
   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:10: warning:
'__builtin___memcpy_chk' specified size 18446744073709551608 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
```

diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 6f77080..bb7b889 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -2589,7 +2589,7 @@ rb_scan_args_set(int argc, const VALUE *argv, https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2589
             rb_warn("The keyword argument is passed as the last hash parameter");
         }
     }
-    if (f_hash && n_mand == argc+1 && empty_keyword_given) {
+    if (f_hash && n_mand > 0 && n_mand == argc+1 && empty_keyword_given) {
         VALUE *ptr = (VALUE *)rb_alloc_tmp_buffer2(&tmp_buffer, argc+1, sizeof(VALUE));
         memcpy(ptr, argv, sizeof(VALUE)*argc);
         ptr[argc] = rb_hash_new();
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]