]> diplodocus.org Git - nmh/commitdiff
Fixed all anomalies detected by clang static analyzer (with
authorDavid Levine <levinedl@acm.org>
Sat, 13 Sep 2014 03:12:33 +0000 (22:12 -0500)
committerDavid Levine <levinedl@acm.org>
Sat, 13 Sep 2014 03:12:33 +0000 (22:12 -0500)
default checkers on Linux).  One was notable:  there was a break
missing from a switch case in fmt_scan.c, which caused the result
of the sday function escape to be garbage.

23 files changed:
Makefile.am
mts/smtp/smtp.c
sbr/addrsbr.c
sbr/encode_rfc2047.c
sbr/fmt_scan.c
sbr/mime_type.c
sbr/ruserpass.c
test/format/test-functions [new file with mode: 0755]
uip/annosbr.c
uip/dropsbr.c
uip/fmttest.c
uip/folder.c
uip/forw.c
uip/inc.c
uip/mhbuildsbr.c
uip/mhfixmsg.c
uip/mhlsbr.c
uip/mhparse.c
uip/mhshowsbr.c
uip/picksbr.c
uip/popsbr.c
uip/post.c
uip/scansbr.c

index 6b6d66d29173ac5490bfb9841d51c1a24a48a85d..30e02a275d8e911dc322cbba8bb4c628af77652d 100644 (file)
@@ -52,8 +52,8 @@ TESTS = test/ali/test-ali test/anno/test-anno \
        test/folder/test-create test/folder/test-packf \
        test/folder/test-recurse test/folder/test-sortm \
        test/folder/test-total \
        test/folder/test-create test/folder/test-packf \
        test/folder/test-recurse test/folder/test-sortm \
        test/folder/test-total \
-       test/format/test-curses \
-       test/format/test-dp test/format/test-fmtdump \
+       test/format/test-curses test/format/test-dp \
+       test/format/test-fmtdump test/format/test-functions \
        test/format/test-localmbox test/format/test-myname \
        test/format/test-myhost test/format/test-mymbox \
        test/format/test-nullstr \
        test/format/test-localmbox test/format/test-myname \
        test/format/test-myhost test/format/test-mymbox \
        test/format/test-nullstr \
index 65de0a7fe5364ae323f5e8f59e6739ec34ad9855..58ca023caa2c873529c115f5bb53c74b720bac7b 100644 (file)
@@ -1223,7 +1223,7 @@ sm_wstream (char *buffer, int len)
        return (ferror (sm_wfp) ? sm_werror () : OK);
     }
 
        return (ferror (sm_wfp) ? sm_werror () : OK);
     }
 
-    for (bp = buffer; len > 0; bp++, len--) {
+    for (bp = buffer; bp && len > 0; bp++, len--) {
        switch (*bp) {
            case '\n': 
                sm_nl = TRUE;
        switch (*bp) {
            case '\n': 
                sm_nl = TRUE;
@@ -1467,7 +1467,7 @@ smhear (void)
     int i, code, cont, bc = 0, rc, more;
     unsigned char *bp;
     char *rp;
     int i, code, cont, bc = 0, rc, more;
     unsigned char *bp;
     char *rp;
-    char **ehlo = NULL, buffer[BUFSIZ];
+    char **ehlo = EHLOkeys, buffer[BUFSIZ];
 
     if (doingEHLO) {
        static int at_least_once = 0;
 
     if (doingEHLO) {
        static int at_least_once = 0;
index b2079bd288e4f7aa28f0ab4de481bf9829d0fb2d..3028847a42478e399cf9115bbae0f3212e8d0f94 100644 (file)
@@ -436,7 +436,7 @@ local_test: ;
 
        if (mp->m_nohost)
            return 1;
 
        if (mp->m_nohost)
            return 1;
-       if (np->m_host == NULL)
+       if (np->m_host == NULL || mp->m_host == NULL)
            continue;
        if ((len = strlen (cp = np->m_host))
                < (i = strlen (pp = mp->m_host)))
            continue;
        if ((len = strlen (cp = np->m_host))
                < (i = strlen (pp = mp->m_host)))
index 581214b7cf65eb29e1e571d779cd02b221411bf4..2c8a3f0d9ffcf1ed2baa4528a10a7b8ca570a61d 100644 (file)
@@ -281,16 +281,22 @@ field_encode_quoted(const char *name, char **value, const char *charset,
             * allow for the encoded output.
             */
            if (column + (utf8len(p) * 3) > ENCODELINELIMIT - 2) {
             * allow for the encoded output.
             */
            if (column + (utf8len(p) * 3) > ENCODELINELIMIT - 2) {
-               newline = 1;
+               newline = 1;
            }
        }
     }
 
            }
        }
     }
 
+    if (q == NULL) {
+       /* This should never happen, but just in case.  Found by
+          clang static analyzer. */
+       admonish (NULL, "null output encoding for %s", *value);
+       return 1;
+    }
     *q++ = '?';
     *q++ = '=';
 
     if (prefixlen)
     *q++ = '?';
     *q++ = '=';
 
     if (prefixlen)
-       *q++ = '\n';
+       *q++ = '\n';
 
     *q = '\0';
 
 
     *q = '\0';
 
index cc5c192d3904b86520bb37f1e22c3fdcd30c8534..08405da1e00158842740f67dda8f63814551315d 100644 (file)
@@ -499,6 +499,9 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
                if (val < scale) {
                    snprintf(buffer, sizeof(buffer), "%u", val);
                } else {
                if (val < scale) {
                    snprintf(buffer, sizeof(buffer), "%u", val);
                } else {
+                   /* To prevent divide by 0, found by clang static
+                      analyzer. */
+                   if (scale == 0) { scale = 1; }
 
                    /* find correct scale for size (Kilo/Mega/Giga/Tera) */
                    for (unitcp = "KMGT"; val > (scale * scale); val /= scale) {
 
                    /* find correct scale for size (Kilo/Mega/Giga/Tera) */
                    for (unitcp = "KMGT"; val > (scale * scale); val /= scale) {
@@ -821,6 +824,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
                default:
                    value = -1; break;
            }
                default:
                    value = -1; break;
            }
+           break;
        case FT_LV_ZONEF:
            if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP)
                    value = 1;
        case FT_LV_ZONEF:
            if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP)
                    value = 1;
@@ -988,7 +992,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
 
            lp = str;
            wid = value;
 
            lp = str;
            wid = value;
-           len = strlen (str);
+           len = str ? strlen (str) : 0;
            sp = fmt->f_text;
            indent = strlen (sp);
            wid -= indent;
            sp = fmt->f_text;
            indent = strlen (sp);
            wid -= indent;
index 673642d5b956bc9fe68effef9de0a154b9774feb..06a6156d418294c0754742c2bc199835d19a8cf0 100644 (file)
@@ -128,7 +128,6 @@ get_file_info(const char *proc, const char *file_name) {
         }
     }
 
         }
     }
 
-    cmd = concat(proc, " ", quotec, file_name, quotec, NULL);
     if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
         FILE *fp;
 
     if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
         FILE *fp;
 
index a55f68031b60006562a6874e4c33bd1a21617b3b..7038cf5ce4ac87a2f15e0ce8150c5d24343c9c2d 100644 (file)
@@ -152,7 +152,7 @@ ruserpass(char *host, char **aname, char **apass)
            advise ("tmp", "fgets");
        }
        tmp[strlen(tmp) - 1] = '\0';
            advise ("tmp", "fgets");
        }
        tmp[strlen(tmp) - 1] = '\0';
-       if (*tmp != '\0') {
+       if (*tmp != '\0' || myname == NULL) {
            myname = tmp;
        }
 
            myname = tmp;
        }
 
diff --git a/test/format/test-functions b/test/format/test-functions
new file mode 100755 (executable)
index 0000000..9cfaeee
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# Test of various (well, start with one) function escapes.
+
+set -e
+
+if test -z "${MH_OBJ_DIR}"; then
+    srcdir=`dirname "$0"`/../..
+    MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
+fi
+
+. "$MH_OBJ_DIR/test/common.sh"
+
+setup_test
+expected="$MH_TEST_DIR/$$.expected"
+actual="$MH_TEST_DIR/$$.actual"
+
+# check sday when day of week is specified
+echo 1 >"$expected"
+fmttest -raw -format '%(sday{text})' 'Fri Sep 12 20:02 2014' >"$actual"
+check "$expected" "$actual"
+
+# check sday when day of week is not specified
+echo 0 >"$expected"
+fmttest -raw -format '%(sday{text})' 'Sep 12 20:02 2014' >"$actual"
+check "$expected" "$actual"
+
+
+exit $failed
index a73c8277e815861454883fb2a6cb3ecfb9071326..63d2ee4487a106010b25bde0b25b0f43fa4730bd 100644 (file)
@@ -117,7 +117,6 @@ annolist(char *file, char *comp, char *text, int number)
        for (n = 0, cp = field; (c = getc(fp)) != EOF; *cp++ = c) {
            if (c == '\n' && (c = getc(fp)) != ' ' && c != '\t') {
                (void)ungetc(c, fp);
        for (n = 0, cp = field; (c = getc(fp)) != EOF; *cp++ = c) {
            if (c == '\n' && (c = getc(fp)) != ' ' && c != '\t') {
                (void)ungetc(c, fp);
-               c = '\n';
                break;
            }
 
                break;
            }
 
index dee95fe702a157ebcd084eecbedb0aae4cb67d64..66edece3200c30451f5bc6881690c056ff36c724 100644 (file)
@@ -241,9 +241,9 @@ mbx_write(char *mailbox, int md, FILE *fp, int id, long last,
     fseek (fp, pos, SEEK_SET);
     while (fgets (buffer, sizeof(buffer), fp) && (pos < stop)) {
        i = strlen (buffer);
     fseek (fp, pos, SEEK_SET);
     while (fgets (buffer, sizeof(buffer), fp) && (pos < stop)) {
        i = strlen (buffer);
-       for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
+       for ( ; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
            continue;
            continue;
-       for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
+       for ( ; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
            continue;
        if (write (md, buffer, i) != i)
            return NOTOK;
            continue;
        if (write (md, buffer, i) != i)
            return NOTOK;
@@ -304,13 +304,9 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
                    termination. */
                 buffer[i] = '\0';
 
                    termination. */
                 buffer[i] = '\0';
 
-               for (j = 0;
-                       (j = stringdex (mmdlm1, buffer)) >= 0;
-                       buffer[j]++)
+               for ( ; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
                    continue;
                    continue;
-               for (j = 0;
-                       (j = stringdex (mmdlm2, buffer)) >= 0;
-                       buffer[j]++)
+               for ( ; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
                    continue;
                if (write (md, buffer, i) != i)
                    return NOTOK;
                    continue;
                if (write (md, buffer, i) != i)
                    return NOTOK;
index 850e2d084878a4b079b93c78496c3cb04564e620..90df1e9e67c17fe055e1a3ed4ca36d3a079a09f7 100644 (file)
@@ -625,7 +625,7 @@ process_single_file(FILE *in, struct msgs_array *comps, int *dat, int msgsize,
      * Read in the message and process the components
      */
 
      * Read in the message and process the components
      */
 
-    for (state = FLD;;) {
+    for (;;) {
        bufsz = sizeof(rbuf);
        state = m_getfld(&gstate, name, rbuf, &bufsz, in);
        switch (state) {
        bufsz = sizeof(rbuf);
        state = m_getfld(&gstate, name, rbuf, &bufsz, in);
        switch (state) {
@@ -650,8 +650,7 @@ process_single_file(FILE *in, struct msgs_array *comps, int *dat, int msgsize,
            if (fmt_findcomp("body")) {
                if ((i = strlen(rbuf)) < outwidth) {
                    bufsz = min (outwidth, (int) sizeof rbuf - i);
            if (fmt_findcomp("body")) {
                if ((i = strlen(rbuf)) < outwidth) {
                    bufsz = min (outwidth, (int) sizeof rbuf - i);
-                   state = m_getfld(&gstate, name, rbuf + i,
-                                    &bufsz, in);
+                   m_getfld(&gstate, name, rbuf + i, &bufsz, in);
                }
 
                fmt_addcomptext("body", rbuf);
                }
 
                fmt_addcomptext("body", rbuf);
index 98ecde68d70f27ac102083dfb6012e8e04a799a7..fc183774fefb63b2d58c0e7e1103549595478f8e 100644 (file)
@@ -398,6 +398,7 @@ get_folder_info_body (char *fold, char *msg, boolean *crawl_children)
         */
        if (!(mp = folder_read (fold, 1))) {
            admonish (NULL, "unable to read folder %s", fold);
         */
        if (!(mp = folder_read (fold, 1))) {
            admonish (NULL, "unable to read folder %s", fold);
+           *crawl_children = FALSE;
            return 0;
        }
 
            return 0;
        }
 
@@ -406,8 +407,10 @@ get_folder_info_body (char *fold, char *msg, boolean *crawl_children)
            retval = 0;
 
        if (fpack) {
            retval = 0;
 
        if (fpack) {
-           if (folder_pack (&mp, fverb) == -1)
+           if (folder_pack (&mp, fverb) == -1) {
+               *crawl_children = FALSE; /* to please clang static analyzer */
                done (1);
                done (1);
+           }
            seq_save (mp);              /* synchronize the sequences */
            context_save ();    /* save the context file     */
        }
            seq_save (mp);              /* synchronize the sequences */
            context_save ();    /* save the context file     */
        }
index d3fd4238b0826f5daab39d39499b9da681d111d6..12a323bb874cfe2746ffa161846e64871f3a1dd5 100644 (file)
@@ -509,7 +509,6 @@ mhl_draft (int out, char *digest, int volume, int issue,
            dup2 (pd[1], 1);
            close (pd[1]);
 
            dup2 (pd[1], 1);
            close (pd[1]);
 
-           i = 1;
            app_msgarg(&vec, "-forwall");
            app_msgarg(&vec, "-form");
            app_msgarg(&vec, filter);
            app_msgarg(&vec, "-forwall");
            app_msgarg(&vec, "-form");
            app_msgarg(&vec, filter);
index 2ee1996066043789c1df9061e7227b842c0d1e6c..1ea618db44204ed355d6fe804411980abe613552 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -969,9 +969,9 @@ pop_pack (char *s)
     char buffer[BUFSIZ];
 
     snprintf (buffer, sizeof(buffer), "%s\n", s);
     char buffer[BUFSIZ];
 
     snprintf (buffer, sizeof(buffer), "%s\n", s);
-    for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
+    for ( ; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
        continue;
        continue;
-    for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
+    for ( ; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
        continue;
     fputs (buffer, pf);
     size += strlen (buffer) + 1;
        continue;
     fputs (buffer, pf);
     size += strlen (buffer) + 1;
index 7776333781cb879144e2ae068af318c340789e96..68c555d36a2cf7b64804845153092fad56708cad 100644 (file)
@@ -173,6 +173,7 @@ build_mime (char *infile, int autobuild, int dist, int directives,
                strcasecmp (name, ENCODING_FIELD) == 0) {
                if (autobuild) {
                    fclose(in);
                strcasecmp (name, ENCODING_FIELD) == 0) {
                if (autobuild) {
                    fclose(in);
+                   free (ct);
                    return NULL;
                } else {
                    adios (NULL, "draft shouldn't contain %s: field", name);
                    return NULL;
                } else {
                    adios (NULL, "draft shouldn't contain %s: field", name);
@@ -398,7 +399,6 @@ finish_field:
        if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL)
            adios (NULL, "out of memory");
        *pp = part;
        if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL)
            adios (NULL, "out of memory");
        *pp = part;
-       pp = &part->mp_next;
        part->mp_part = p;
     }
 
        part->mp_part = p;
     }
 
@@ -780,7 +780,6 @@ use_forw:
                adios (NULL, "out of memory");
            init_decoded_content(ct, infilename);
            *ctp = ct;
                adios (NULL, "out of memory");
            init_decoded_content(ct, infilename);
            *ctp = ct;
-           ci = &ct->c_ctinfo;
            if (get_ctinfo (buffer, ct, 0) == NOTOK)
                done (1);
            ct->c_type = CT_MESSAGE;
            if (get_ctinfo (buffer, ct, 0) == NOTOK)
                done (1);
            ct->c_type = CT_MESSAGE;
index 5385b9ecff7bbfaa4d1a4d209d41c693ad07c985..3180e9ce3ce3c2b9cde53f34cfb145a5215a29e4 100644 (file)
@@ -484,9 +484,11 @@ fix_boundary (CT *ct, int *message_mods) {
                 if ((fixed = m_mktemp2 (NULL, invo_name, NULL, &(*ct)->c_fp))) {
                     if (replace_boundary (*ct, fixed, part_boundary) == OK) {
                         char *filename = add ((*ct)->c_file, NULL);
                 if ((fixed = m_mktemp2 (NULL, invo_name, NULL, &(*ct)->c_fp))) {
                     if (replace_boundary (*ct, fixed, part_boundary) == OK) {
                         char *filename = add ((*ct)->c_file, NULL);
+                        CT fixed_ct;
 
                         free_content (*ct);
 
                         free_content (*ct);
-                        if ((*ct = parse_mime (fixed))) {
+                        if ((fixed_ct = parse_mime (fixed))) {
+                            *ct = fixed_ct;
                             (*ct)->c_unlink = 1;
 
                             ++*message_mods;
                             (*ct)->c_unlink = 1;
 
                             ++*message_mods;
@@ -494,6 +496,9 @@ fix_boundary (CT *ct, int *message_mods) {
                                 report (NULL, NULL, filename,
                                         "fix multipart boundary");
                             }
                                 report (NULL, NULL, filename,
                                         "fix multipart boundary");
                             }
+                        } else {
+                            advise (NULL, "unable to parse fixed part");
+                            status = NOTOK;
                         }
                         free (filename);
                     } else {
                         }
                         free (filename);
                     } else {
index 0c9719c2d2cd5b5d2a961e6c519b2f3d2805527e..12add6ccca2a793b7fbe5cbb77317a8639684e2d 100644 (file)
@@ -400,7 +400,8 @@ mhl (int argc, char **argv)
                case SLEEPSW:
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                case SLEEPSW:
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
-                   sleepsw = atoi (cp);/* ZERO ok! */
+                   else
+                       sleepsw = atoi (cp);/* ZERO ok! */
                    continue;
 
                case PROGSW:
                    continue;
 
                case PROGSW:
@@ -422,13 +423,13 @@ mhl (int argc, char **argv)
                case LENSW: 
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                case LENSW: 
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
-                   if ((length = atoi (cp)) < 1)
+                   else if ((length = atoi (cp)) < 1)
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
                case WIDTHSW: 
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
                case WIDTHSW: 
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
-                   if ((width = atoi (cp)) < 1)
+                   else if ((width = atoi (cp)) < 1)
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
 
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
 
@@ -439,13 +440,13 @@ mhl (int argc, char **argv)
                case ISSUESW:
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                case ISSUESW:
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
-                   if ((issue = atoi (cp)) < 1)
+                   else if ((issue = atoi (cp)) < 1)
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
                case VOLUMSW:
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
                case VOLUMSW:
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
-                   if ((volume = atoi (cp)) < 1)
+                   else if ((volume = atoi (cp)) < 1)
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
 
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
 
@@ -591,7 +592,7 @@ mhl_format (char *file, int length, int width)
            *cp = 0;
 
        if (*bp == ':') {
            *cp = 0;
 
        if (*bp == ':') {
-           c1 = add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
+           (void) add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
            continue;
        }
 
            continue;
        }
 
@@ -1182,15 +1183,16 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2)
     while ((cp = getname (ap))) {
        if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL)
            adios (NULL, "unable to allocate pqpair memory");
     while ((cp = getname (ap))) {
        if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL)
            adios (NULL, "unable to allocate pqpair memory");
-
-       if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
-           p->pq_text = getcpy (cp);
-           p->pq_error = getcpy (error);
-       } else {
-           p->pq_text = getcpy (mp->m_text);
-           mnfree (mp);
+       else {
+           if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
+               p->pq_text = getcpy (cp);
+               p->pq_error = getcpy (error);
+           } else {
+               p->pq_text = getcpy (mp->m_text);
+               mnfree (mp);
+           }
+           q = (q->pq_next = p);
        }
        }
-       q = (q->pq_next = p);
     }
 
     for (p = pq.pq_next; p; p = q) {
     }
 
     for (p = pq.pq_next; p; p = q) {
@@ -1237,19 +1239,20 @@ add_queue (struct mcomp **head, struct mcomp **tail, char *name, char *text, int
 
     if ((c1 = (struct mcomp *) calloc ((size_t) 1, sizeof(*c1))) == NULL)
        adios (NULL, "unable to allocate comp memory");
 
     if ((c1 = (struct mcomp *) calloc ((size_t) 1, sizeof(*c1))) == NULL)
        adios (NULL, "unable to allocate comp memory");
-
-    c1->c_flags = flags & ~INIT;
-    if ((c1->c_name = name ? getcpy (name) : NULL))
-       c1->c_flags |= mcomp_flags (c1->c_name);
-    c1->c_text = text ? getcpy (text) : NULL;
-    if (flags & INIT) {
-       if (global.c_ovtxt)
-           c1->c_ovtxt = getcpy (global.c_ovtxt);
-       c1->c_offset = global.c_offset;
-       c1->c_ovoff = global. c_ovoff;
-       c1->c_width = c1->c_length = 0;
-       c1->c_cwidth = global.c_cwidth;
-       c1->c_flags |= global.c_flags & GFLAGS;
+    else {
+       c1->c_flags = flags & ~INIT;
+       if ((c1->c_name = name ? getcpy (name) : NULL))
+           c1->c_flags |= mcomp_flags (c1->c_name);
+       c1->c_text = text ? getcpy (text) : NULL;
+       if (flags & INIT) {
+           if (global.c_ovtxt)
+               c1->c_ovtxt = getcpy (global.c_ovtxt);
+           c1->c_offset = global.c_offset;
+           c1->c_ovoff = global. c_ovoff;
+           c1->c_width = c1->c_length = 0;
+           c1->c_cwidth = global.c_cwidth;
+           c1->c_flags |= global.c_flags & GFLAGS;
+       }
     }
     if (*head == NULL)
        *head = c1;
     }
     if (*head == NULL)
        *head = c1;
index 14701398ebc4f787fd4e63b8ae89811aa8c6cca5..e7782f14eec442491901adece5a159f7b58ad1f0 100644 (file)
@@ -2341,6 +2341,7 @@ openExternal (CT ct, CT cb, CE ce, char **file, int *fd)
        }
     }
 
        }
     }
 
+    *fd = fileno (ce->ce_fp);
     return OK;
 
 ready_already:
     return OK;
 
 ready_already:
index 61f041205926edb4f12cf9eb9883d9cf76280ab2..720ba9bc0fbfaf801722c5aac51925969959ddbe 100644 (file)
@@ -135,7 +135,7 @@ show_single_message (CT ct, char *form, int concatsw, int textonly,
 {
     sigset_t set, oset;
 
 {
     sigset_t set, oset;
 
-    int status;
+    int status = OK;
 
     /* Allow user executable bit so that temporary directories created by
      * the viewer (e.g., lynx) are going to be accessible */
 
     /* Allow user executable bit so that temporary directories created by
      * the viewer (e.g., lynx) are going to be accessible */
@@ -329,7 +329,7 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format *
 {
     int fd;
     int xstdin = 0, xlist = 0;
 {
     int fd;
     int xstdin = 0, xlist = 0;
-    char *file, buffer[BUFSIZ];
+    char *file = NULL, buffer[BUFSIZ];
 
     if (!ct->c_ceopenfnx) {
        if (!alternate)
 
     if (!ct->c_ceopenfnx) {
        if (!alternate)
@@ -338,7 +338,6 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format *
        return NOTOK;
     }
 
        return NOTOK;
     }
 
-    file = NULL;
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
        return NOTOK;
     if (ct->c_showproc && !strcmp (ct->c_showproc, "true"))
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
        return NOTOK;
     if (ct->c_showproc && !strcmp (ct->c_showproc, "true"))
@@ -643,7 +642,7 @@ show_multi_aux (CT ct, int alternate, char *cp, struct format *fmt)
     /* xstdin is only used in the call to parse_display_string():
        its value is ignored in the function. */
     int xstdin = 0, xlist = 0;
     /* xstdin is only used in the call to parse_display_string():
        its value is ignored in the function. */
     int xstdin = 0, xlist = 0;
-    char *file, buffer[BUFSIZ];
+    char *file = NULL, buffer[BUFSIZ];
     struct multipart *m = (struct multipart *) ct->c_ctparams;
     struct part *part;
     CT p;
     struct multipart *m = (struct multipart *) ct->c_ctparams;
     struct part *part;
     CT p;
@@ -658,7 +657,6 @@ show_multi_aux (CT ct, int alternate, char *cp, struct format *fmt)
        }
 
        if (p->c_storage == NULL) {
        }
 
        if (p->c_storage == NULL) {
-           file = NULL;
            if ((*p->c_ceopenfnx) (p, &file) == NOTOK)
                return NOTOK;
 
            if ((*p->c_ceopenfnx) (p, &file) == NOTOK)
                return NOTOK;
 
index 74834f4eaa8ae5700f34e093dc59f1fc1c431fe5..d444cd6853d604cc17db5d95c7c1418f896e7726 100644 (file)
@@ -243,6 +243,7 @@ parse (void)
            if ((o->n_R_child = parse ()))
                return o;
            padvise (NULL, "missing disjunctive");
            if ((o->n_R_child = parse ()))
                return o;
            padvise (NULL, "missing disjunctive");
+           free (o);
            return NULL;
 
 header: ;
            return NULL;
 
 header: ;
@@ -263,6 +264,7 @@ nexp1 (void)
 
     if (*cp != '-') {
        padvise (NULL, "%s unexpected", cp);
 
     if (*cp != '-') {
        padvise (NULL, "%s unexpected", cp);
+       free (n);
        return NULL;
     }
 
        return NULL;
     }
 
@@ -272,10 +274,12 @@ nexp1 (void)
        case AMBIGSW: 
            ambigsw (cp, parswit);
            talked++;
        case AMBIGSW: 
            ambigsw (cp, parswit);
            talked++;
+           free (n);
            return NULL;
        case UNKWNSW: 
            fprintf (stderr, "-%s unknown\n", cp);
            talked++;
            return NULL;
        case UNKWNSW: 
            fprintf (stderr, "-%s unknown\n", cp);
            talked++;
+           free (n);
            return NULL;
 
        case PRAND: 
            return NULL;
 
        case PRAND: 
@@ -284,6 +288,7 @@ nexp1 (void)
            if ((o->n_R_child = nexp1 ()))
                return o;
            padvise (NULL, "missing conjunctive");
            if ((o->n_R_child = nexp1 ()))
                return o;
            padvise (NULL, "missing conjunctive");
+           free (o);
            return NULL;
 
 header: ;
            return NULL;
 
 header: ;
@@ -325,6 +330,7 @@ nexp2 (void)
            if ((n->n_L_child = nexp3 ()))
                return n;
            padvise (NULL, "missing negation");
            if ((n->n_L_child = nexp3 ()))
                return n;
            padvise (NULL, "missing negation");
+           free (n);
            return NULL;
 
 header: ;
            return NULL;
 
 header: ;
@@ -406,12 +412,14 @@ nexp3 (void)
            n->n_header = 0;
            if (!(cp = nxtarg ())) {/* allow -xyz arguments */
                padvise (NULL, "missing argument to %s", argp[-2]);
            n->n_header = 0;
            if (!(cp = nxtarg ())) {/* allow -xyz arguments */
                padvise (NULL, "missing argument to %s", argp[-2]);
+               free (n);
                return NULL;
            }
            dp = cp;
     pattern: ;
            if (!gcompile (n, dp)) {
                padvise (NULL, "pattern error in %s %s", argp[-2], cp);
                return NULL;
            }
            dp = cp;
     pattern: ;
            if (!gcompile (n, dp)) {
                padvise (NULL, "pattern error in %s %s", argp[-2], cp);
+               free (n);
                return NULL;
            }
            n->n_patbuf = getcpy (dp);
                return NULL;
            }
            n->n_patbuf = getcpy (dp);
@@ -438,6 +446,7 @@ nexp3 (void)
            n->n_datef = datesw;
            if (!tcompile (cp, &n->n_tws, n->n_after = i == PRAFTR)) {
                padvise (NULL, "unable to parse %s %s", argp[-2], cp);
            n->n_datef = datesw;
            if (!tcompile (cp, &n->n_tws, n->n_after = i == PRAFTR)) {
                padvise (NULL, "unable to parse %s %s", argp[-2], cp);
+               free (n);
                return NULL;
            }
            return n;
                return NULL;
            }
            return n;
index 8334dee6f92e5cadbaf3c58aa6bca04540cf0f00..2d194a67204efffd8ac15c8aa088f9ccaf244743 100644 (file)
@@ -899,7 +899,7 @@ sasl_getline (char *s, int n, FILE *iop)
     *p = 0;
     if (*--p == '\n')
        *p = 0;
     *p = 0;
     if (*--p == '\n')
        *p = 0;
-    if (*--p == '\r')
+    if (p > s  &&  *--p == '\r')
        *p = 0;
 
     return OK;
        *p = 0;
 
     return OK;
index 16121359ee711178ea1bb08d50b55dafd199f129..685129b9653de6fbbea99aea693d5606644df3e4 100644 (file)
@@ -714,7 +714,7 @@ putfmt (char *name, char *str, FILE *out)
     if (hdr->flags & HFCC) {
        if ((cp = strrchr(str, '\n')))
            *cp = 0;
     if (hdr->flags & HFCC) {
        if ((cp = strrchr(str, '\n')))
            *cp = 0;
-       for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) {
+       for (pp = str; (cp = strchr(pp, ',')); pp = cp) {
            *cp++ = 0;
            insert_fcc (hdr, pp);
        }
            *cp++ = 0;
            insert_fcc (hdr, pp);
        }
index ce49bee21f9dd21cce5afb21bd46bf98d04cff2c..749743c1c4c3f55b2461ccc3e74f2f8c834fef8f 100644 (file)
@@ -220,7 +220,6 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
                break;
 
            case BODY: 
                break;
 
            case BODY: 
-               compnum = -1;
                /*
                 * A slight hack ... if we have less than rlwidth characters
                 * in the buffer, call m_getfld again.
                /*
                 * A slight hack ... if we have less than rlwidth characters
                 * in the buffer, call m_getfld again.