Skip to content

Fix __builtin_{smulll,saddll}_overflow() usage #2205

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 1 commit into from
May 2, 2019
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
4 changes: 2 additions & 2 deletions CoreFoundation/String.subproj/CFString.c
Original file line number Diff line number Diff line change
Expand Up @@ -6442,9 +6442,9 @@ reswtch:switch (ch) {
return true;
}
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {
int64_t number = 0;
long long number = 0;
do {
if (__builtin_smulll_overflow(number, 10, &number) || __builtin_saddll_overflow(number, ch - '0', &number)) {
if (__builtin_smulll_overflow(number, 10, &number) || __builtin_saddll_overflow(number, ch - '0', &number) || number > INT64_MAX) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a tautological comparison? number is a long long which is signed. INT64_MAX is signed. So the value of the condition is always false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long long is only defined to be at least 64 bits but could be more if ever ported to other platforms. This is a bit of a nit-picking change but it should make it technically correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What platform(s) currently define it to something other than 64-bit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay taking pedantic correctness fixes, since this is code intended to be portable.

if (errorPtr) *errorPtr = __CFCreateOverflowError();
return false;
}
Expand Down