Skip to content

Commit b3fa771

Browse files
author
Rob Percival
committed
Fixes format-security error when compiling ruby_193_compatible.h
When compiling the extension for Ruby 1.9 on a system that treats format-security warnings as errors (i.e. the Makefile generated for the extension contains "-Werror=format-security"), compilation would fail with the following error: ``` compiling atomic_boolean.c In file included from atomic_boolean.c:5:0: ruby_193_compatible.h: In function 'rb_error_arity': ruby_193_compatible.h:20:3: warning: passing argument 2 of 'rb_raise' makes pointer from integer without a cast [enabled by default] rb_raise(rb_eTypeError, err_mess); ^ In file included from /usr/include/ruby-1.9.1/ruby.h:32:0, from atomic_boolean.c:1: /usr/include/ruby-1.9.1/ruby/ruby.h:1172:27: note: expected 'const char *' but argument is of type 'VALUE' PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3); ^ /usr/include/ruby-1.9.1/ruby/ruby.h:42:3: note: in definition of macro 'PRINTF_ARGS' decl __attribute__((format(printf, string_index, first_to_check))) ^ /usr/include/ruby-1.9.1/ruby/ruby.h:1172:13: note: in expansion of macro 'NORETURN' PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3); ^ In file included from atomic_boolean.c:5:0: ruby_193_compatible.h:20:3: error: format not a string literal and no format arguments [-Werror=format-security] rb_raise(rb_eTypeError, err_mess); ^ cc1: some warnings being treated as errors make: *** [atomic_boolean.o] Error 1 ``` This updates these functions to work more like the original copies (found in the Ruby 2.0+ source code), which avoids this compilation error.
1 parent 0d044be commit b3fa771

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ext/concurrent/ruby_193_compatible.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#define UNLIMITED_ARGUMENTS (-1)
77

8-
static inline void rb_error_arity(int argc, int min, int max)
8+
static inline VALUE rb_error_arity(int argc, int min, int max)
99
{
1010
VALUE err_mess = 0;
1111
if (min == max) {
@@ -17,12 +17,12 @@ static inline void rb_error_arity(int argc, int min, int max)
1717
else {
1818
err_mess = rb_sprintf("wrong number of arguments (%d for %d..%d)", argc, min, max);
1919
}
20-
rb_raise(rb_eTypeError, err_mess);
20+
return rb_exc_new3(rb_eTypeError, err_mess);
2121
}
2222

2323
#define rb_check_arity(argc, min, max) do { \
2424
if (((argc) < (min)) || ((argc) > (max) && (max) != UNLIMITED_ARGUMENTS)) \
25-
rb_error_arity(argc, min, max); \
25+
rb_exc_raise(rb_error_arity(argc, min, max)); \
2626
} while(0)
2727

2828
#endif

0 commit comments

Comments
 (0)