Skip to content

Commit 5f788e2

Browse files
authored
Merge pull request swiftlang#73 from swiftwasm/master
[pull] swiftwasm from master
2 parents 02cbf14 + 19a8e4e commit 5f788e2

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
@@ -487,12 +487,13 @@ static CFIndex __CFBSearchTZPeriods(CFTimeZoneRef tz, CFAbsoluteTime at) {
487487

488488

489489
CF_INLINE int32_t __CFDetzcode(const unsigned char *bufp) {
490-
int32_t result = (bufp[0] & 0x80) ? ~0L : 0L;
490+
// `result` is uint32_t to avoid undefined behaviour of shifting left negative values
491+
uint32_t result = (bufp[0] & 0x80) ? ~0L : 0L;
491492
result = (result << 8) | (bufp[0] & 0xff);
492493
result = (result << 8) | (bufp[1] & 0xff);
493494
result = (result << 8) | (bufp[2] & 0xff);
494495
result = (result << 8) | (bufp[3] & 0xff);
495-
return result;
496+
return (int32_t)result;
496497
}
497498

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

0 commit comments

Comments
 (0)