Skip to content
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

8308071: [REDO] update for deprecated sprintf for src/utils #13995

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/utils/hsdis/binutils/hsdis-binutils.c
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ static const char* format_insn_close(const char* close,
case dis_noninsn: type = "noninsn"; break;
}

size_t used_size = snprintf(buf, bufsize, "%s", close);
int used_size = snprintf(buf, bufsize, "%s", close);
if ((used_size < 0) || (used_size >= bufsize)) {

Choose a reason for hiding this comment

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

(used_size < 0) is tautologically false, since used_size is a size_t, so unsigned. I'm somewhat surprised
this doesn't trigger a warning from some compiler.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to use int to replace size_t.. Thank you for the catching.

Choose a reason for hiding this comment

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

bufsize is size_t, so that's a comparison between signed and unsigned values, which I think some compilers
will warn about. Maybe the preceding check for negative is getting rid of that? But will that still occur in
a slowdebug build, or will the lack of optimization lead to a warning?

Copy link
Member Author

Choose a reason for hiding this comment

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

As always, this comment helps a lot. Thank you!

Updated to cast int to size_t explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

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

@kimbarrett Did you have a chance to have another look? Please let me know if you prefer to the update that the returned value of snprintf() is not checked because the memory size has been checked previously.

return close;
}