From beced3ad774631c091241d5087761879c0aa88b1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 12 Jun 2009 22:12:13 -0700 Subject: [PATCH] output: Use "struct string" in tabi_title in place of fixed-size buffer. This ensures that extra-long titles provided by the user do not overflow the stack. --- src/output/table.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/output/table.c b/src/output/table.c index 453f7393..480534e1 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -1137,36 +1137,33 @@ tabi_title (void *r_, int x, int y) const struct tab_rendering *r = r_; const struct tab_table *t = r->table; struct outp_text text; - char buf[1024]; - char *cp; + struct string title; if (t->flags & SOMF_NO_TITLE) return; - cp = spprintf (buf, "%d.%d", table_num, subtable_num); + ds_init_empty (&title); + ds_put_format (&title,"%d.%d", table_num, subtable_num); if (x && y) - cp = spprintf (cp, "(%d:%d)", x, y); + ds_put_format (&title, "(%d:%d)", x, y); else if (x) - cp = spprintf (cp, "(%d)", x); + ds_put_format (&title, "(%d)", x); if (command_name != NULL) - cp = spprintf (cp, " %s", command_name); - cp = stpcpy (cp, ". "); + ds_put_format (&title, " %s", command_name); + ds_put_cstr (&title, ". "); if (t->title != NULL) - { - size_t length = strlen (t->title); - memcpy (cp, t->title, length); - cp += length; - } - *cp = 0; + ds_put_cstr (&title, t->title); text.font = OUTP_PROPORTIONAL; text.justification = OUTP_LEFT; - text.string = ss_buffer (buf, cp - buf); + text.string = ds_ss (&title); text.h = r->driver->width; text.v = r->driver->font_height; text.x = 0; text.y = r->driver->cp_y; r->driver->class->text_draw (r->driver, &text); + + ds_destroy (&title); } static int render_strip (const struct tab_rendering *, -- 2.30.2