From 41c44503bb87b01beab47665479128c346a4814d Mon Sep 17 00:00:00 2001 From: Sam Kimbrel Date: Mon, 20 Jun 2011 22:24:42 -0700 Subject: [PATCH] [perl #92432] Storable::nfreeze shouldn't stringify ints Storable::nfreeze's integer size check doesn't work correctly: Using nfreeze to store an int larger than one byte produces a frozen representation that thaws into a stringified integer, without my having done string operations on the scalar beforehand. I've confirmed this bug with the three versions I had available to me: 5.8.9 on 64-bit CentOS 4, 5.12.1 on 64-bit OS X 10.6, and 5.14.0 on 64-bit Debian squeeze. The constants involved in the comparisons get created as 32-bit integers, which wrap around and cause the comparison to yield true when it shouldn't. This patch casts the constants before using them, which should make this port correctly to 64-bit architectures. Running tests on a 64-bit Debian host shows no problems. --- dist/Storable/Storable.xs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/Storable/Storable.xs b/dist/Storable/Storable.xs index c6f9f70..fb25a78 100644 --- a/dist/Storable/Storable.xs +++ b/dist/Storable/Storable.xs @@ -2117,9 +2117,9 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv) if ( #ifdef SVf_IVisUV /* Sorry. This isn't in 5.005_56 (IIRC) or earlier. */ - ((flags & SVf_IVisUV) && SvUV(sv) > 0x7FFFFFFF) || + ((flags & SVf_IVisUV) && SvUV(sv) > (UV)0x7FFFFFFF) || #endif - (iv > 0x7FFFFFFF) || (iv < -0x80000000)) { + (iv > (IV)0x7FFFFFFF) || (iv < -(IV)0x80000000)) { /* Bigger than 32 bits. */ TRACEME(("large network order integer as string, value = %"IVdf, iv)); goto string_readlen; -- 2.7.4