From 65b57039a225b77f550971d7825e0bb0dff4b184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 8 Feb 2024 15:37:49 +0100 Subject: [PATCH] font: drop tags that don't fit in buf --- demos/01-font.c | 2 +- engine/joint/v4k.h | 4 +--- engine/split/v4k_font.c | 4 +--- engine/v4k.c | 4 +--- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/demos/01-font.c b/demos/01-font.c index d70cba9..daaaf3f 100644 --- a/demos/01-font.c +++ b/demos/01-font.c @@ -140,7 +140,7 @@ int main() { { vec2 pos = vec2(1990,820); ddraw_push_2d(); - char *txt = FONT_RIGHT FONT_BOTTOM FONT_WHITE "This is the first line.\n" FONT_LIME "And now the second line.\n" FONT_WHITE "You can do a third great line, too!\n"; + char *txt = FONT_RIGHT FONT_BOTTOM FONT_WHITE "This is the first line.\n" FONT_LIME "And now the second line.\n" FONT_WHITE "You can do a third" FONT_ORANGE " great" FONT_WHITE " line, too!\n"; font_goto(pos.x, pos.y); vec2 size=font_rect(txt); font_metrics_t m=font_metrics(txt); diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index b54ef1a..77da590 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -363964,12 +363964,10 @@ vec2 font_print_rect(const char *text, vec4 rect) { if( (ch >= 1 && ch <= 6) || (ch >= 0x1a && ch <= 0x1f) || (ch >= 0x10 && ch <= 0x19)) { - tags[t++] = ch; + if (t < sizeof(tags)) tags[t++] = ch; } else break; ++text; - - if (t == 3) break; } array(char *) lines = strsplit(text, "\n"); if (b) { diff --git a/engine/split/v4k_font.c b/engine/split/v4k_font.c index dab347a..c7ade24 100644 --- a/engine/split/v4k_font.c +++ b/engine/split/v4k_font.c @@ -2406,12 +2406,10 @@ vec2 font_print_rect(const char *text, vec4 rect) { if( (ch >= 1 && ch <= 6) || (ch >= 0x1a && ch <= 0x1f) || (ch >= 0x10 && ch <= 0x19)) { - tags[t++] = ch; + if (t < sizeof(tags)) tags[t++] = ch; } else break; ++text; - - if (t == 3) break; } array(char *) lines = strsplit(text, "\n"); if (b) { diff --git a/engine/v4k.c b/engine/v4k.c index dd68e72..420dca3 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -11104,12 +11104,10 @@ vec2 font_print_rect(const char *text, vec4 rect) { if( (ch >= 1 && ch <= 6) || (ch >= 0x1a && ch <= 0x1f) || (ch >= 0x10 && ch <= 0x19)) { - tags[t++] = ch; + if (t < sizeof(tags)) tags[t++] = ch; } else break; ++text; - - if (t == 3) break; } array(char *) lines = strsplit(text, "\n"); if (b) {