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

Replace sprintf() with snprintf() (#536) #551

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions src/googletest.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,11 @@ static inline string Munge(const string& filename) {
string result;
while (fgets(buf, 4095, fp)) {
string line = MungeLine(buf);
char null_str[256];
char ptr_str[256];
sprintf(null_str, "%p", static_cast<void*>(NULL));
sprintf(ptr_str, "%p", reinterpret_cast<void*>(PTR_TEST_VALUE));
const size_t str_size = 256;
char null_str[str_size];
char ptr_str[str_size];
snprintf(null_str, str_size, "%p", static_cast<void*>(NULL));
snprintf(ptr_str, str_size, "%p", reinterpret_cast<void*>(PTR_TEST_VALUE));

StringReplace(&line, "__NULLP__", null_str);
StringReplace(&line, "__PTRTEST__", ptr_str);
Expand Down
5 changes: 3 additions & 2 deletions src/stl_logging_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ static void TestSTLLogging() {
for (int i = 0; i < 100; i++) {
v.push_back(i);
if (i > 0) expected += ' ';
char buf[256];
sprintf(buf, "%d", i);
const size_t buf_size = 256;
char buf[buf_size];
snprintf(buf, buf_size, "%d", i);
expected += buf;
}
v.push_back(100);
Expand Down