summaryrefslogtreecommitdiff
path: root/include/ruby/ruby.h
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-09-26 11:35:01 +0900
committerYusuke Endoh <mame@ruby-lang.org>2019-09-26 11:35:01 +0900
commit1fe73dc8609c4bac9e517dc70f602a16dae556cc (patch)
tree852c00b143358a8d5f8c4b1ff114082b9664eff4 /include/ruby/ruby.h
parent5357ceb1ca454e2b3c5c173c638054cf705e4752 (diff)
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=] ```
Diffstat (limited to 'include/ruby/ruby.h')
-rw-r--r--include/ruby/ruby.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 6f7708009a..bb7b889361 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -2589,7 +2589,7 @@ rb_scan_args_set(int argc, const VALUE *argv,
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();