From e68aed92f594456b596d9b3d8c0fba00406fe76d Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Mon, 22 Dec 2014 20:12:22 +0000 Subject: [PATCH] pack(): avoid << of negative values Treat the string as U8* rather than char* when doing all the bit shifts for uuencode. That stops these warnings under ASan: pp_pack.c:1890:34: runtime error: left shift of negative value -127 pp_pack.c:1891:34: runtime error: left shift of negative value -126 pp_pack.c:1899:34: runtime error: left shift of negative value -1 pp_pack.c:1900:30: runtime error: left shift of negative value -31 --- pp_pack.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pp_pack.c b/pp_pack.c index 9ed8c59..60462eb 100644 --- a/pp_pack.c +++ b/pp_pack.c @@ -1882,7 +1882,7 @@ PP(pp_unpack) } STATIC U8 * -doencodes(U8 *h, const char *s, I32 len) +doencodes(U8 *h, const U8 *s, I32 len) { *h++ = PL_uuemap[len]; while (len > 2) { @@ -1894,7 +1894,7 @@ doencodes(U8 *h, const char *s, I32 len) len -= 3; } if (len > 0) { - const char r = (len > 1 ? s[1] : '\0'); + const U8 r = (len > 1 ? s[1] : '\0'); *h++ = PL_uuemap[(077 & (s[0] >> 2))]; *h++ = PL_uuemap[(077 & (((s[0] << 4) & 060) | ((r >> 4) & 017)))]; *h++ = PL_uuemap[(077 & ((r << 2) & 074))]; @@ -3110,9 +3110,9 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) "aptr=%p, aend=%p, buffer=%p, todo=%ld", aptr, aend, buffer, (long) todo); } - end = doencodes(hunk, buffer, todo); + end = doencodes(hunk, (const U8 *)buffer, todo); } else { - end = doencodes(hunk, aptr, todo); + end = doencodes(hunk, (const U8 *)aptr, todo); aptr += todo; } PUSH_BYTES(utf8, cur, hunk, end-hunk, 0); -- 1.8.3.1