diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-04-02 15:37:37 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-05-11 13:54:09 +0900 |
| commit | eb053e7446607f5e70215bf508499ef6bab3aa4a (patch) | |
| tree | 964783ef8ca9555f69ef946aba3c9ff0bdae26d7 /pack.c | |
| parent | 793f4c9572b9d888f0d40fb9d4ec783ea23486e4 (diff) | |
[Feature #21979] Allow negative offset in unpack
Diffstat (limited to 'pack.c')
| -rw-r--r-- | pack.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -1024,9 +1024,10 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) StringValue(fmt); rb_must_asciicompat(fmt); - if (offset < 0) rb_raise(rb_eArgError, "offset can't be negative"); len = RSTRING_LEN(str); - if (offset > len) rb_raise(rb_eArgError, "offset outside of string"); + if (offset < 0 ? (offset += len) < 0 : offset > len) { + rb_raise(rb_eArgError, "offset outside of string"); + } s = RSTRING_PTR(str); send = s + len; |
