Replace a LOT of sprintf with snprintf, and a few strcpy with truncate_cpy

This commit is contained in:
Henrik Rydgård committed 2023-04-28 21:04:05 +02:00
1 parent c02634c161
commit 6945deec01
39 files changed
+170 -193

No files matched your search

+6 -6
View File
@@ -1284,7 +1284,7 @@ void ProgressBar::GetContentDimensions(const UIContext &dc, float &w, float &h)
void ProgressBar::Draw(UIContext &dc) {
char temp[32];
sprintf(temp, "%i%%", (int)(progress_ * 100.0f));
snprintf(temp, sizeof(temp), "%d%%", (int)(progress_ * 100.0f));
dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x + bounds_.w * progress_, bounds_.y2(), 0xc0c0c0c0);
dc.SetFontStyle(dc.theme->uiFont);
dc.DrawTextRect(temp, bounds_, 0xFFFFFFFF, ALIGN_CENTER);
@@ -1443,17 +1443,17 @@ void Slider::Draw(UIContext &dc) {
dc.Draw()->DrawImage(dc.theme->sliderKnob, knobX, bounds_.centerY(), 1.0f, knobStyle.fgColor, ALIGN_CENTER);
char temp[64];
if (showPercent_)
sprintf(temp, "%i%%", *value_);
snprintf(temp, sizeof(temp), "%d%%", *value_);
else
sprintf(temp, "%i", *value_);
snprintf(temp, sizeof(temp), "%d", *value_);
dc.SetFontStyle(dc.theme->uiFont);
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), dc.theme->popupStyle.fgColor, ALIGN_CENTER | FLAG_DYNAMIC_ASCII);
}
std::string Slider::DescribeText() const {
if (showPercent_)
return StringFromFormat("%i%% / %i%%", *value_, maxValue_);
return StringFromFormat("%i / %i", *value_, maxValue_);
return StringFromFormat("%d%% / %d%%", *value_, maxValue_);
return StringFromFormat("%d / %d", *value_, maxValue_);
}
void Slider::Update() {
@@ -1567,7 +1567,7 @@ void SliderFloat::Draw(UIContext &dc) {
dc.FillRect(Drawable(0xFF808080), Bounds(knobX, bounds_.centerY() - 2, (bounds_.x + bounds_.w - paddingRight_ - knobX), 4));
dc.Draw()->DrawImage(dc.theme->sliderKnob, knobX, bounds_.centerY(), 1.0f, knobStyle.fgColor, ALIGN_CENTER);
char temp[64];
sprintf(temp, "%0.2f", *value_);
snprintf(temp, sizeof(temp), "%0.2f", *value_);
dc.SetFontStyle(dc.theme->uiFont);
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), dc.theme->popupStyle.fgColor, ALIGN_CENTER);
}