summaryrefslogtreecommitdiffstats
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-09-19 08:54:13 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-09-19 08:54:13 (GMT)
commite84b74039bb28b6ae7e4e9291566ee7f13532f93 (patch)
tree1854eeebcd3781bdd569ade7be36508d877c0ee8 /Python/marshal.c
parenta3c6a8a30ea6fe481aa7397c8acb53f8a483c93d (diff)
downloadcpython-e84b74039bb28b6ae7e4e9291566ee7f13532f93.zip
cpython-e84b74039bb28b6ae7e4e9291566ee7f13532f93.tar.gz
cpython-e84b74039bb28b6ae7e4e9291566ee7f13532f93.tar.bz2
Obscure marshal fixes:
When reading a short, sign-extend on platforms where shorts are bigger than 16 bits. When reading a long, repair the unportable sign extension that was being done for 64-bit machines (it assumed that signed right shift sign-extends).
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 91d322b..f8953ce 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -307,7 +307,8 @@ r_short(RFILE *p)
register short x;
x = r_byte(p);
x |= r_byte(p) << 8;
- /* XXX If your short is > 16 bits, add sign-extension here!!! */
+ /* Sign-extension, in case short greater than 16 bits */
+ x |= -(x & 0x8000);
return x;
}
@@ -330,8 +331,7 @@ r_long(RFILE *p)
}
#if SIZEOF_LONG > 4
/* Sign extension for 64-bit machines */
- x <<= (8*sizeof(long) - 32);
- x >>= (8*sizeof(long) - 32);
+ x |= -(x & 0x80000000L);
#endif
return x;
}
@@ -342,7 +342,7 @@ r_long64(RFILE *p)
register long x;
x = r_long(p);
#if SIZEOF_LONG > 4
- x = (x & 0xFFFFFFFF) | (r_long(p) << 32);
+ x = (x & 0xFFFFFFFFL) | (r_long(p) << 32);
#else
if (r_long(p) != 0) {
PyObject *f = PySys_GetObject("stderr");