From 640815dcd6fa74bfd103ec89bd5acce6a371bcf8 Mon Sep 17 00:00:00 2001 From: Eugene Hermann <39246518+eughermann@users.noreply.github.com> Date: Wed, 25 Jul 2018 14:07:03 -0700 Subject: Fix Undefined Behavior, left shift of negative value, signed integer overflow. ubsan output: .../google_toolbox_for_mac/Foundation/GTMStringEncoding.m:204:16: runtime error: left shift of 10368305 by 8 places cannot be represented in type 'int' .../google_toolbox_for_mac/Foundation/GTMStringEncoding.m:312:16: runtime error: left shift of 42406098 by 6 places cannot be represented in type 'int' TESTED=Earth iOS --featires=ubsan --- Foundation/GTMStringEncoding.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Foundation') diff --git a/Foundation/GTMStringEncoding.m b/Foundation/GTMStringEncoding.m index 7578e86..6bc496c 100644 --- a/Foundation/GTMStringEncoding.m +++ b/Foundation/GTMStringEncoding.m @@ -196,7 +196,7 @@ GTM_INLINE int lcm(int a, int b) { unsigned char *outBuf = (unsigned char *)[outData mutableBytes]; NSUInteger outPos = 0; - int buffer = inBuf[inPos++]; + unsigned int buffer = inBuf[inPos++]; int bitsLeft = 8; while (bitsLeft > 0 || inPos < inLen) { if (bitsLeft < shift_) { @@ -275,7 +275,7 @@ GTM_INLINE int lcm(int a, int b) { unsigned char *outBuf = (unsigned char *)[outData mutableBytes]; NSUInteger outPos = 0; - int buffer = 0; + unsigned int buffer = 0; int bitsLeft = 0; BOOL expectPad = NO; for (NSUInteger i = 0; i < inLen; i++) { -- cgit v1.2.3