diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-26 17:11:12 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-26 17:11:12 +0000 |
commit | 40465862bdb23bddfe1d8b52f21962a4ccb9208a (patch) | |
tree | 27b85c6c7934833a436f56e7adb747b0e61ea1f5 /pack.c | |
parent | 9e159579e0a074e5723c4eec4381ea56979b5b95 (diff) | |
download | ruby-40465862bdb23bddfe1d8b52f21962a4ccb9208a.tar.gz |
* io.c (next_argv): warn always for stdin on inplace edit mode.
* io.c (read_all): need to check string value.
* io.c (argf_read): allow ARGF.read(nil). [ruby-dev:22433]
* io.c (rb_f_backquote): need not to check nil result.
[ruby-core:02078]
* io.c (rb_io_getline): should return nil when read_all gives
empty string, even when nil rs is specified. [ruby-core:02077]
* pack.c (pack_pack): add sign check for 'i', and 'l'.
[ruby-dev:22427]
* bignum.c (rb_quad_pack): add range check for 'quad int'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r-- | pack.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -377,15 +377,15 @@ num2u32(x) #endif #if SIZEOF_LONG == SIZE32 || SIZEOF_INT == SIZE32 -# define EXTEND32(x) ((I32)(x)) +# define EXTEND32(x) #else /* invariant in modulo 1<<31 */ -# define EXTEND32(x) (I32)(((1<<31)-1-(x))^~(~0<<31)) +# define EXTEND32(x) do {if (!natint) {(x) = (I32)(((1<<31)-1-(x))^~(~0<<31))}} while(0) #endif #if SIZEOF_SHORT == SIZE16 -# define EXTEND16(x) (short)(x) +# define EXTEND16(x) #else -# define EXTEND16(x) (short)(((1<<15)-1-(x))^~(~0<<15)) +# define EXTEND16(x) do { if (!natint) {(x) = (short)(((1<<15)-1-(x))^~(~0<<15))}} while(0) #endif #ifdef HAVE_LONG_LONG @@ -725,9 +725,12 @@ pack_pack(ary, fmt) from = NEXTFROM; if (NIL_P(from)) i = 0; - else { + else if (type == 'i') { i = NATINT_I32(from); } + else { + i = NATINT_U32(from); + } rb_str_buf_cat(res, OFF32(&i), NATINT_LEN(int,4)); } break; @@ -739,6 +742,9 @@ pack_pack(ary, fmt) from = NEXTFROM; if (NIL_P(from)) l = 0; + else if (type == 'l') { + l = NATINT_I32(from); + } else { l = NATINT_U32(from); } @@ -1558,9 +1564,7 @@ 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 + EXTEND16(tmp); s += NATINT_LEN(short,2); rb_ary_push(ary, INT2FIX(tmp)); } @@ -1605,15 +1609,12 @@ 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 + EXTEND32(tmp); s += NATINT_LEN(long,4); rb_ary_push(ary, LONG2NUM(tmp)); } PACK_ITEM_ADJUST(); break; - case 'L': PACK_LENGTH_ADJUST(unsigned long,4); while (len-- > 0) { |