From b1a9d92a65fe6a6d537465d47d18a7ffa7aed593 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Thu, 4 Jun 2020 11:56:19 +0200 Subject: [PATCH 1/2] Changes type to avoid undefined behaviour of shifting left negative value --- CoreFoundation/NumberDate.subproj/CFTimeZone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CoreFoundation/NumberDate.subproj/CFTimeZone.c b/CoreFoundation/NumberDate.subproj/CFTimeZone.c index 973cf1cceb..ceee3b891d 100644 --- a/CoreFoundation/NumberDate.subproj/CFTimeZone.c +++ b/CoreFoundation/NumberDate.subproj/CFTimeZone.c @@ -485,7 +485,7 @@ static CFIndex __CFBSearchTZPeriods(CFTimeZoneRef tz, CFAbsoluteTime at) { CF_INLINE int32_t __CFDetzcode(const unsigned char *bufp) { - int32_t result = (bufp[0] & 0x80) ? ~0L : 0L; + uint32_t result = (bufp[0] & 0x80) ? ~0L : 0L; result = (result << 8) | (bufp[0] & 0xff); result = (result << 8) | (bufp[1] & 0xff); result = (result << 8) | (bufp[2] & 0xff); From 3457298082d74e5958b59a2e1533a58882506784 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Fri, 19 Jun 2020 02:32:11 +0200 Subject: [PATCH 2/2] Adds comment and explicit cast. --- CoreFoundation/NumberDate.subproj/CFTimeZone.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CoreFoundation/NumberDate.subproj/CFTimeZone.c b/CoreFoundation/NumberDate.subproj/CFTimeZone.c index ceee3b891d..271a515f97 100644 --- a/CoreFoundation/NumberDate.subproj/CFTimeZone.c +++ b/CoreFoundation/NumberDate.subproj/CFTimeZone.c @@ -485,12 +485,13 @@ static CFIndex __CFBSearchTZPeriods(CFTimeZoneRef tz, CFAbsoluteTime at) { CF_INLINE int32_t __CFDetzcode(const unsigned char *bufp) { + // `result` is uint32_t to avoid undefined behaviour of shifting left negative values uint32_t result = (bufp[0] & 0x80) ? ~0L : 0L; result = (result << 8) | (bufp[0] & 0xff); result = (result << 8) | (bufp[1] & 0xff); result = (result << 8) | (bufp[2] & 0xff); result = (result << 8) | (bufp[3] & 0xff); - return result; + return (int32_t)result; } CF_INLINE void __CFEntzcode(int32_t value, unsigned char *bufp) {