X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/c6f2d14d9c38345075629af3487c2de491584ca1..c8caafcb4a39516eaec330f9ea229ea52e5fe46b:/uip/dropsbr.c?ds=inline diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 6f7f3652..a02e29c4 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -1,6 +1,4 @@ - -/* - * dropsbr.c -- create/read/manipulate mail drops +/* dropsbr.c -- create/read/manipulate mail drops * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -210,7 +208,7 @@ mbx_read (FILE *fp, long pos, struct drop **drops) } if (dp == pp) - free ((char *) pp); + free(pp); else *drops = pp; return (dp - pp); @@ -272,7 +270,7 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, int i, j, size; off_t start, stop; long pos; - char *cp, buffer[BUFSIZ]; + char *cp, buffer[BUFSIZ + 1]; /* Space for NUL. */ FILE *fp; pos = (long) lseek (md, (off_t) 0, SEEK_CUR); @@ -295,10 +293,8 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, size++; } - while ((i = read (fd, buffer, sizeof(buffer))) > 0) { - /* valgrind noticed that stringdex depends on null - termination. */ - buffer[i] = '\0'; + while ((i = read (fd, buffer, sizeof buffer - 1)) > 0) { + buffer[i] = '\0'; /* Terminate for stringdex(). */ for ( ; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++) continue; @@ -350,8 +346,8 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, * Change the "Return-Path:" field (if in first line) * back to "From ". */ - if (!strncmp (buffer, "Return-Path:", 12)) { - char tmpbuffer[BUFSIZ]; + if (has_prefix(buffer, "Return-Path:")) { + char tmpbuffer[sizeof buffer]; char *tp, *ep, *fp; strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); @@ -361,23 +357,23 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, tp = dctime(dlocaltimenow()); snprintf (buffer, sizeof(buffer), "From %.*s %s", (int)(fp - ep), ep, tp); - } else if (!strncmp (buffer, "X-Envelope-From:", 16)) { + } else if (has_prefix(buffer, "X-Envelope-From:")) { /* * Change the "X-Envelope-From:" field * (if first line) back to "From ". */ - char tmpbuffer[BUFSIZ]; + char tmpbuffer[sizeof buffer]; char *ep; strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); ep = tmpbuffer + 17; snprintf (buffer, sizeof(buffer), "From %s", ep); - } else if (strncmp (buffer, "From ", 5)) { + } else if (!has_prefix(buffer, "From ")) { /* * If there is already a "From " line, * then leave it alone. Else we add one. */ - char tmpbuffer[BUFSIZ]; + char tmpbuffer[sizeof buffer]; char *tp, *ep; strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); @@ -391,7 +387,7 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, * If this is not first line, and begins with * "From ", then prepend line with ">". */ - if (j != 0 && strncmp (buffer, "From ", 5) == 0) { + if (j != 0 && has_prefix(buffer, "From ")) { if (write (md, ">", 1) < 0) { advise (mailbox, "write"); } @@ -507,7 +503,7 @@ map_read (char *file, long pos, struct drop **drops, int noisy) if ((i = read (md, (char *) (dp + 1), msgp * sizeof(*dp))) < (int) sizeof(*dp)) { i = 0; - free ((char *) dp); + free(dp); } else { #ifdef NTOHLSWAP struct drop *tdp; @@ -591,7 +587,7 @@ map_write (char *mailbox, int md, int id, long last, off_t start, return NOTOK; } } - free ((char *) rp); + free(rp); fclose (fp); break; } @@ -652,7 +648,7 @@ map_chk (char *file, int fd, struct drop *dp, long pos, int noisy) if (read (fd, (char *) &tmpd, sizeof(*dp)) != sizeof(*dp)) { #ifdef notdef - admonish (NULL, "%s: missing or partial index", file); + inform("%s: missing or partial index, continuing...", file); #endif /* notdef */ return NOTOK; } @@ -667,22 +663,21 @@ map_chk (char *file, int fd, struct drop *dp, long pos, int noisy) if (dp->d_size != DRVRSN) { if (noisy) - admonish (NULL, "%s: version mismatch (%d != %d)", file, + inform("%s: version mismatch (%d != %d), continuing...", file, dp->d_size, DRVRSN); return NOTOK; } if (dp->d_stop != pos) { if (noisy && pos != (long) 0) - admonish (NULL, - "%s: pointer mismatch or incomplete index (%ld!=%ld)", - file, dp->d_stop, (long) pos); + inform("%s: pointer mismatch or incomplete index (%ld!=%ld), " + "continuing...", file, dp->d_stop, (long) pos); return NOTOK; } if ((long) ((dp->d_id + 1) * sizeof(*dp)) != (long) lseek (fd, (off_t) 0, SEEK_END)) { if (noisy) - admonish (NULL, "%s: corrupt index(1)", file); + inform("%s: corrupt index(1), continuing...", file); return NOTOK; } @@ -693,7 +688,7 @@ map_chk (char *file, int fd, struct drop *dp, long pos, int noisy) || (ntohl(dl->d_stop) != dp->d_stop && ntohl(dl->d_stop) + count != dp->d_stop)) { if (noisy) - admonish (NULL, "%s: corrupt index(2)", file); + inform("%s: corrupt index(2), continuing...", file); return NOTOK; }