use snprintf instead of sprintf

This commit is contained in:
Brad Grantham
2024-07-08 07:39:53 -07:00
parent afd1101a74
commit c4abb87a15
2 changed files with 10 additions and 10 deletions
+4 -4
View File
@@ -1608,7 +1608,7 @@ struct MAINboard : board_base
sw->enabled = true;
if(debug & DEBUG_SWITCH) printf("Set %s\n", sw->name.c_str());
post_soft_switch_mode_change();
static char reason[512]; sprintf(reason, "set %s", sw->name.c_str());
static char reason[512]; snprintf(reason, sizeof(reason), "set %s", sw->name.c_str());
repage_regions(reason);
}
return true;
@@ -1619,7 +1619,7 @@ struct MAINboard : board_base
sw->enabled = false;
if(debug & DEBUG_SWITCH) printf("Clear %s\n", sw->name.c_str());
post_soft_switch_mode_change();
static char reason[512]; sprintf(reason, "clear %s", sw->name.c_str());
static char reason[512]; snprintf(reason, sizeof(reason), "clear %s", sw->name.c_str());
repage_regions(reason);
}
return true;
@@ -1856,7 +1856,7 @@ struct MAINboard : board_base
sw->enabled = true;
if(debug & DEBUG_SWITCH) printf("Set %s\n", sw->name.c_str());
post_soft_switch_mode_change();
static char reason[512]; sprintf(reason, "set %s", sw->name.c_str());
static char reason[512]; snprintf(reason, sizeof(reason), "set %s", sw->name.c_str());
repage_regions(reason);
}
return true;
@@ -1867,7 +1867,7 @@ struct MAINboard : board_base
sw->enabled = false;
if(debug & DEBUG_SWITCH) printf("Clear %s\n", sw->name.c_str());
post_soft_switch_mode_change();
static char reason[512]; sprintf(reason, "clear %s", sw->name.c_str());
static char reason[512]; snprintf(reason, sizeof(reason), "clear %s", sw->name.c_str());
repage_regions(reason);
}
return true;
+6 -6
View File
@@ -1935,17 +1935,17 @@ void iterate(const ModeHistory& history, unsigned long long current_byte, float
{
static char speed_cstr[10];
if(megahertz >= 100000.0) {
sprintf(speed_cstr, "very fast");
snprintf(speed_cstr, sizeof(speed_cstr), "very fast");
} else if(megahertz >= 10000.0) {
sprintf(speed_cstr, "%5.2f GHz", megahertz);
snprintf(speed_cstr, sizeof(speed_cstr), "%5.2f GHz", megahertz);
} else if(megahertz >= 1000.0) {
sprintf(speed_cstr, "%5.3f GHz", megahertz);
snprintf(speed_cstr, sizeof(speed_cstr), "%5.3f GHz", megahertz);
} else if(megahertz >= 100.0) {
sprintf(speed_cstr, "%5.1f MHz", megahertz);
snprintf(speed_cstr, sizeof(speed_cstr), "%5.1f MHz", megahertz);
} else if(megahertz >= 10.0) {
sprintf(speed_cstr, "%5.2f MHz", megahertz);
snprintf(speed_cstr, sizeof(speed_cstr), "%5.2f MHz", megahertz);
} else {
sprintf(speed_cstr, "%5.3f MHz", megahertz);
snprintf(speed_cstr, sizeof(speed_cstr), "%5.3f MHz", megahertz);
}
speed_textbox->set_content(speed_cstr);
}