-
-
Notifications
You must be signed in to change notification settings - Fork 758
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
ICU-22251 Move sprintf to snprintf. #2291
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good. Looks mechanical, except for the calculation of the buffer size. I didn't review all of those carefully, but the ones I did all looked right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New stuff looks good too.
9014fd9
to
f7794db
Compare
Hooray! The files in the branch are the same across the force-push. 😃 ~ Your Friendly Jira-GitHub PR Checker Bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't think that you should be hardcoding any of these numbers, that wouldn't get us any real improved memory safety, it would just move the places where things could go wrong.
Instead, existing code like this:
char tmp[16];
sprintf(tmp, "%d", value);
Should be replaced with new code like this:
char tmp[16];
snprintf(tmp, sizeof tmp, "%d", value);
Or, when that's not possible, some kind of logic / argument passing that ensures that the value used is ultimately calculated by the compiler from the actual buffer size.
DONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, and I think Fredrik's recommendation is a good one and makes the code more readable and bulletproof. But I think you missed a couple spots...
@@ -1157,7 +1157,7 @@ static void TestICUDataName() | |||
} | |||
|
|||
/* Only major number is needed. */ | |||
sprintf(expectDataName, "%s%d%c", | |||
snprintf(expectDataName, 20, "%s%d%c", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you didn't use sizeof
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
somehow I missed this
d360b58
to
eb580c1
Compare
Hooray! The files in the branch are the same across the force-push. 😃 ~ Your Friendly Jira-GitHub PR Checker Bot |
PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all looks fine. Cut and print.
done |
Checklist