]> diplodocus.org Git - nmh/commitdiff
Check that a character array isn't empty before looking for its
authorDavid Levine <levinedl@acm.org>
Wed, 16 Jan 2013 01:38:16 +0000 (19:38 -0600)
committerDavid Levine <levinedl@acm.org>
Wed, 16 Jan 2013 01:38:16 +0000 (19:38 -0600)
next-to-last element.

sbr/fmt_scan.c

index de44c44ac6dd9a933b115f4a21fcf4797fdcb185..879f7716af6ee286b2a3919e5c1ed61f7ef01637 100644 (file)
@@ -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;
            }