Skip to content

Changes type avoiding undefined behaviour shifting left negative value in CFTimeZone #2812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CoreFoundation/NumberDate.subproj/CFTimeZone.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,13 @@ static CFIndex __CFBSearchTZPeriods(CFTimeZoneRef tz, CFAbsoluteTime at) {


CF_INLINE int32_t __CFDetzcode(const unsigned char *bufp) {
int32_t result = (bufp[0] & 0x80) ? ~0L : 0L;
// `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) {
Expand Down