Skip to content

Commit

Permalink
Fix buffer size we pass to strftime in json.cc
Browse files Browse the repository at this point in the history
We skip over the first character in the buffer that we pass to
`strftime`. Hence, we also need subtract one from the total size that
`strftime` is allowed to write to.
  • Loading branch information
Neverlord committed Dec 17, 2023
1 parent 5a1c185 commit ca464eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/format/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ size_t encode_to_buf(timestamp value, std::array<char, 32>& buf) {
localtime_r(&secs, &time_buf);
#endif
buf[0] = '"';
auto pos = strftime(buf.data() + 1, buf.size(), "%FT%T", &time_buf) + 1;
auto pos = strftime(buf.data() + 1, buf.size() - 1, "%FT%T", &time_buf) + 1;
buf[pos++] = '.';
if (msecs > 0) {
assert(msecs < 1000);
Expand Down

0 comments on commit ca464eb

Please sign in to comment.