diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-07 11:33:42 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-14 14:38:14 +0900 |
commit | efe5e6e8d05d607dde38ece66e035b8e746e65fb (patch) | |
tree | 21aac5d5e12748700ad00384680960c23e15aa72 /process.c | |
parent | e50fcca9a79d8e25b33ad3611df6bf4627faafbf (diff) | |
download | ruby-efe5e6e8d05d607dde38ece66e035b8e746e65fb.tar.gz |
Negative value to Process::Status method for compatibility
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -877,12 +877,19 @@ pst_equal(VALUE st1, VALUE st2) * sprintf('%x', stat.to_i) # => "100" * stat & 0x00 # => 0 * + * ArgumentError is raised if +mask+ is negative. */ static VALUE pst_bitand(VALUE st1, VALUE st2) { - int status = PST2INT(st1) & NUM2INT(st2); + int status = PST2INT(st1); + int mask = NUM2INT(st2); + + if (mask < 0) { + rb_raise(rb_eArgError, "negative mask value: %d", mask); + } + status &= mask; return INT2NUM(status); } @@ -900,13 +907,19 @@ pst_bitand(VALUE st1, VALUE st2) * stat >> 1 # => 128 * stat >> 2 # => 64 * - * The behavior is unspecified if +places+ is negative. + * ArgumentError is raised if +places+ is negative. */ static VALUE pst_rshift(VALUE st1, VALUE st2) { - int status = PST2INT(st1) >> NUM2INT(st2); + int status = PST2INT(st1); + int places = NUM2INT(st2); + + if (places < 0) { + rb_raise(rb_eArgError, "negative shift value: %d", places); + } + status >>= places; return INT2NUM(status); } |