Skip to content

Commit 19a8e4e

Browse files
authored
Merge pull request #2812 from valeriyvan/CFTimeZone
2 parents 6a1be26 + 3457298 commit 19a8e4e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,13 @@ static CFIndex __CFBSearchTZPeriods(CFTimeZoneRef tz, CFAbsoluteTime at) {
485485

486486

487487
CF_INLINE int32_t __CFDetzcode(const unsigned char *bufp) {
488-
int32_t result = (bufp[0] & 0x80) ? ~0L : 0L;
488+
// `result` is uint32_t to avoid undefined behaviour of shifting left negative values
489+
uint32_t result = (bufp[0] & 0x80) ? ~0L : 0L;
489490
result = (result << 8) | (bufp[0] & 0xff);
490491
result = (result << 8) | (bufp[1] & 0xff);
491492
result = (result << 8) | (bufp[2] & 0xff);
492493
result = (result << 8) | (bufp[3] & 0xff);
493-
return result;
494+
return (int32_t)result;
494495
}
495496

496497
CF_INLINE void __CFEntzcode(int32_t value, unsigned char *bufp) {

0 commit comments

Comments
 (0)