fix passing raw string to vsprintf.

fixes #173
This commit is contained in:
ITotalJustice
2025-06-12 21:50:06 +01:00
parent 275707fe27
commit 6b099de63c
3 changed files with 9 additions and 4 deletions

View File

@@ -30,7 +30,8 @@ void drawTextArgs(NVGcontext*, float x, float y, float size, int align, const NV
void drawTextBox(NVGcontext*, float x, float y, float size, float bound, const NVGcolor& c, const char* str, int align = NVG_ALIGN_LEFT | NVG_ALIGN_TOP, const char* end = nullptr);
void textBounds(NVGcontext*, float x, float y, float *bounds, const char* str, ...) __attribute__ ((format (printf, 5, 6)));
void textBounds(NVGcontext*, float x, float y, float *bounds, const char* str);
void textBoundsArgs(NVGcontext*, float x, float y, float *bounds, const char* str, ...) __attribute__ ((format (printf, 5, 6)));
auto getButton(Button button) -> const char*;
void drawScrollbar(NVGcontext*, const Theme*, u32 index_off, u32 count, u32 max_per_page);

View File

@@ -73,7 +73,7 @@ void MenuBase::Draw(NVGcontext* vg, Theme* theme) {
if (fixed) { \
start_x -= fixed; \
} else { \
gfx::textBounds(vg, 0, 0, bounds, __VA_ARGS__); \
gfx::textBoundsArgs(vg, 0, 0, bounds, __VA_ARGS__); \
start_x -= spacing + (bounds[2] - bounds[0]); \
}

View File

@@ -230,13 +230,17 @@ void drawTextBox(NVGcontext* vg, float x, float y, float size, float bound, cons
nvgTextBox(vg, x, y, bound, str, end);
}
void textBounds(NVGcontext* vg, float x, float y, float *bounds, const char* str, ...) {
void textBounds(NVGcontext* vg, float x, float y, float *bounds, const char* str) {
nvgTextBounds(vg, x, y, str, nullptr, bounds);
}
void textBoundsArgs(NVGcontext* vg, float x, float y, float *bounds, const char* str, ...) {
char buf[0x100];
va_list v;
va_start(v, str);
std::vsnprintf(buf, sizeof(buf), str, v);
va_end(v);
nvgTextBounds(vg, x, y, buf, nullptr, bounds);
textBounds(vg, x, y, bounds, buf);
}
// NEW-----------