From: David Levine Date: Wed, 16 Jan 2013 01:38:16 +0000 (-0600) Subject: Check that a character array isn't empty before looking for its X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/c09f9e4a7f10d1272300da16cbdfbd3e98afb517?ds=inline;hp=--cc Check that a character array isn't empty before looking for its next-to-last element. --- c09f9e4a7f10d1272300da16cbdfbd3e98afb517 diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index de44c44a..879f7716 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -367,11 +367,11 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat) comp = fmt->f_comp; - if (! (comp->c_flags & CF_TRIMMED) && comp->c_text) { - i = strlen(comp->c_text); + if (! (comp->c_flags & CF_TRIMMED) && comp->c_text && + (i = strlen(comp->c_text)) > 0) { if (comp->c_text[i - 1] == '\n' && - strcmp(comp->c_name, "body") != 0 && - strcmp(comp->c_name, "text") != 0) + strcmp(comp->c_name, "body") != 0 && + strcmp(comp->c_name, "text") != 0) comp->c_text[i - 1] = '\0'; comp->c_flags |= CF_TRIMMED; }