Skip to content

Commit

Permalink
Merge pull request #551 from aesophor/replace-sprintf
Browse files Browse the repository at this point in the history
Replace sprintf() with snprintf() (#536)
  • Loading branch information
sergiud committed Sep 29, 2020
2 parents 8ee2bb5 + 2e87f98 commit 4c5a60c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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

0 comments on commit 4c5a60c

Please sign in to comment.