Skip to content

Commit

Permalink
Fixing some unsafe snprintf usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
indigodarkwolf committed Dec 29, 2023
1 parent 5d84aee commit 4d2cc36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/ieee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@ static void set_activity(bool active)

static void set_error(int e, int t, int s)
{
snprintf(error, sizeof(error), "%02x,%s,%02d,%02d\r", e, error_string(e), t, s);
error_len = static_cast<int>(strlen(error));
error_len = snprintf(error, sizeof(error), "%02x,%s,%02d,%02d\r", e, error_string(e), t, s);
error_pos = 0;
uint8_t cbdos_flags = get_kernal_cbdos_flags();
if (e < 0x10 || e == 0x73) {
Expand Down
4 changes: 4 additions & 0 deletions src/overlay/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,27 @@ static void draw_debugger_cpu_status()
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
char stack_line[256];
snprintf(stack_line, sizeof(stack_line), "$%02X:$%04X", bank, pc);
stack_line[255] = '\0';
pushed = ImGui::Selectable(stack_line, false, 0, ImGui::CalcTextSize(stack_line));
ImGui::PopStyleColor();
} else {
char stack_line[256];
snprintf(stack_line, sizeof(stack_line), "$%02X:$%04X: %s", bank, pc, label);
stack_line[255] = '\0';
pushed = ImGui::Selectable(stack_line, false, 0, ImGui::CalcTextSize(stack_line));
}
} else {
if (label == nullptr) {
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
char stack_line[256];
snprintf(stack_line, sizeof(stack_line), "$%04X", pc);
stack_line[255] = '\0';
pushed = ImGui::Selectable(stack_line, false, 0, ImGui::CalcTextSize(stack_line));
ImGui::PopStyleColor();
} else {
char stack_line[256];
snprintf(stack_line, sizeof(stack_line), "$%04X: %s", pc, label);
stack_line[255] = '\0';
pushed = ImGui::Selectable(stack_line, false, 0, ImGui::CalcTextSize(stack_line));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/overlay/psg_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ void draw_debugger_vera_psg()
char rate_txt[15];
float rate_hz = rate <= 128 ? (float)SAMPLERATE * rate / 128 : 0;
snprintf(rate_txt, 15, "%d (%.0f Hz)", rate, rate_hz);
rate_txt[14] = '\0';
ImGui::SetNextItemWidth(avail / 2 - 48);
if (ImGui::SliderInt("Rate", &rate_i, 0, 128, rate_txt, ImGuiSliderFlags_AlwaysClamp)) {
pcm_write_rate(rate_i);
Expand Down

0 comments on commit 4d2cc36

Please sign in to comment.