Skip to content

Commit 3457298

Browse files
committed
Adds comment and explicit cast.
1 parent b1a9d92 commit 3457298

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 2 additions & 1 deletion
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+
// `result` is uint32_t to avoid undefined behaviour of shifting left negative values
488489
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)