diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-05-23 06:16:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-05-23 06:16:20 +0000 |
commit | 228604473da9819e031ea2b48017f9246d1dbd48 (patch) | |
tree | 7d717cb465bafaefda8c17c790da103ce94209dc | |
parent | 2e4ffa7a447f94f2aaa44c206db845da029be484 (diff) |
* pack.c (pack_unpack): sign-extend if sizeof long is bigger than
32. (ruby-bugs-ja:PR#472)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | pack.c | 18 |
2 files changed, 23 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Fri May 23 15:16:16 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net> + + * pack.c (pack_unpack): sign-extend if sizeof long is bigger than + 32. (ruby-bugs-ja:PR#472) + Thu May 22 18:07:46 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net> * lib/token.c: single- and double-quoted root-level fix. @@ -351,6 +351,18 @@ num2u32(x) # endif #endif +#if SIZEOF_LONG == SIZE32 || SIZEOF_INT == SIZE32 +# define EXTEND32(x) ((I32)(x)) +#else +/* invariant in modulo 1<<31 */ +# define EXTEND32(x) (I32)(((1<<31)-1-(x))^~(~0<<31)) +#endif +#if SIZEOF_SHORT == SIZE16 +# define EXTEND16(x) (short)(x) +#else +# define EXTEND16(x) (short)(((1<<15)-1-(x))^~(~0<<15)) +#endif + #ifdef HAVE_LONG_LONG # define QUAD_SIZE sizeof(LONG_LONG) #else @@ -1317,6 +1329,9 @@ pack_unpack(str, fmt) while (len-- > 0) { short tmp = 0; memcpy(OFF16(&tmp), s, NATINT_LEN(short,2)); +#if SIZEOF_SHORT != SIZE16 + if (!natint) tmp = EXTEND16(tmp); +#endif s += NATINT_LEN(short,2); rb_ary_push(ary, INT2FIX(tmp)); } @@ -1361,6 +1376,9 @@ pack_unpack(str, fmt) while (len-- > 0) { long tmp = 0; memcpy(OFF32(&tmp), s, NATINT_LEN(long,4)); +#if SIZEOF_LONG != SIZE32 + if (!natint) tmp = EXTEND32(tmp); +#endif s += NATINT_LEN(long,4); rb_ary_push(ary, LONG2NUM(tmp)); } |