diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-10-17 16:15:42 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-10-18 03:54:28 +0000 |
| commit | db357848950d54128d6505621037872e7575697a (patch) | |
| tree | 6117178a81b7c119bc95c4579a472e5c9584992b | |
| parent | 7989a2ff46e0dc8dc26b1571215768801fa04463 (diff) | |
[ruby/zlib] Initialize const member
```
/github/workspace/src/ext/zlib/zlib.c:2608:25: warning: default initialization of an object of type 'struct read_raw_arg' with const member leaves the object uninitialized [-Wdefault-const-init-field-unsafe]
2608 | struct read_raw_arg ra;
| ^
/github/workspace/src/ext/zlib/zlib.c:2450:14: note: member 'argv' declared 'const' here
2450 | const VALUE argv[2]; /* for rb_funcallv */
| ^
```
https://github.com/ruby/zlib/commit/dfa1fcbd37
| -rw-r--r-- | ext/zlib/zlib.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 0b9c4d65ee..640c28122c 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -2444,17 +2444,16 @@ struct gzfile { #define GZFILE_READ_SIZE 2048 +enum { read_raw_arg_len, read_raw_arg_buf, read_raw_arg__count}; struct read_raw_arg { VALUE io; - union { - const VALUE argv[2]; /* for rb_funcallv */ - struct { - VALUE len; - VALUE buf; - } in; - } as; + const VALUE argv[read_raw_arg__count]; /* for rb_funcallv */ }; +#define read_raw_arg_argc(ra) \ + ((int)read_raw_arg__count - NIL_P((ra)->argv[read_raw_arg__count - 1])) +#define read_raw_arg_init(io, len, buf) { io, { len, buf } } + static void gzfile_mark(void *p) { @@ -2580,9 +2579,9 @@ gzfile_read_raw_partial(VALUE arg) { struct read_raw_arg *ra = (struct read_raw_arg *)arg; VALUE str; - int argc = NIL_P(ra->as.argv[1]) ? 1 : 2; + int argc = read_raw_arg_argc(ra); - str = rb_funcallv(ra->io, id_readpartial, argc, ra->as.argv); + str = rb_funcallv(ra->io, id_readpartial, argc, ra->argv); Check_Type(str, T_STRING); return str; } @@ -2593,8 +2592,8 @@ gzfile_read_raw_rescue(VALUE arg, VALUE _) struct read_raw_arg *ra = (struct read_raw_arg *)arg; VALUE str = Qnil; if (rb_obj_is_kind_of(rb_errinfo(), rb_eNoMethodError)) { - int argc = NIL_P(ra->as.argv[1]) ? 1 : 2; - str = rb_funcallv(ra->io, id_read, argc, ra->as.argv); + int argc = read_raw_arg_argc(ra); + str = rb_funcallv(ra->io, id_read, argc, ra->argv); if (!NIL_P(str)) { Check_Type(str, T_STRING); } @@ -2605,11 +2604,8 @@ gzfile_read_raw_rescue(VALUE arg, VALUE _) static VALUE gzfile_read_raw(struct gzfile *gz, VALUE outbuf) { - struct read_raw_arg ra; - - ra.io = gz->io; - ra.as.in.len = INT2FIX(GZFILE_READ_SIZE); - ra.as.in.buf = outbuf; + struct read_raw_arg ra = + read_raw_arg_init(gz->io, INT2FIX(GZFILE_READ_SIZE), outbuf); return rb_rescue2(gzfile_read_raw_partial, (VALUE)&ra, gzfile_read_raw_rescue, (VALUE)&ra, |
