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

stacktrace.cpp: Fix snprintf() usage #3916

Merged
merged 3 commits into from
Aug 3, 2023
Merged
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
6 changes: 3 additions & 3 deletions stl/src/stacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace {
constexpr size_t max_disp_num = sizeof("+0x1122334455667788") - 1; // maximum possible offset

off = string_fill(fill, off + max_disp_num, str, [displacement, off](char* s, size_t) {
const int ret = std::snprintf(s + off, max_disp_num, "+0x%llX", displacement);
const int ret = std::snprintf(s + off, max_disp_num + 1, "+0x%llX", displacement);
if (ret <= 0) {
std::abort(); // formatting error
}
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace {
constexpr size_t max_line_num = sizeof("(4294967295): ") - 1; // maximum possible line number

off = string_fill(fill, off + max_line_num, str, [line, off](char* s, size_t) {
const int ret = std::snprintf(s + off, max_line_num, "(%u): ", line);
const int ret = std::snprintf(s + off, max_line_num + 1, "(%u): ", line);
if (ret <= 0) {
std::abort(); // formatting error
}
Expand Down Expand Up @@ -320,7 +320,7 @@ void __stdcall __std_stacktrace_to_string(const void* const* const _Addresses, c
constexpr size_t max_entry_num = sizeof("65536> ") - 1; // maximum possible entry number

off = string_fill(_Fill, off + max_entry_num, _Str, [off, i](char* s, size_t) {
const int ret = std::snprintf(s + off, max_entry_num, "%u> ", static_cast<unsigned int>(i));
const int ret = std::snprintf(s + off, max_entry_num + 1, "%u> ", static_cast<unsigned int>(i));
if (ret <= 0) {
std::abort(); // formatting error
}
Expand Down