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 \
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;
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 (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)))
* 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++ = '\n';
+ *q++ = '\n';
*q = '\0';
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) {
default:
value = -1; break;
}
+ break;
case FT_LV_ZONEF:
if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP)
value = 1;
lp = str;
wid = value;
- len = strlen (str);
+ len = str ? strlen (str) : 0;
sp = fmt->f_text;
indent = strlen (sp);
wid -= indent;
}
}
- cmd = concat(proc, " ", quotec, file_name, quotec, NULL);
if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
FILE *fp;
advise ("tmp", "fgets");
}
tmp[strlen(tmp) - 1] = '\0';
- if (*tmp != '\0') {
+ if (*tmp != '\0' || myname == NULL) {
myname = tmp;
}
--- /dev/null
+#!/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
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;
}
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;
- 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;
termination. */
buffer[i] = '\0';
- for (j = 0;
- (j = stringdex (mmdlm1, buffer)) >= 0;
- buffer[j]++)
+ for ( ; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
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;
* 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) {
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);
*/
if (!(mp = folder_read (fold, 1))) {
admonish (NULL, "unable to read folder %s", fold);
+ *crawl_children = FALSE;
return 0;
}
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);
+ }
seq_save (mp); /* synchronize the sequences */
context_save (); /* save the context file */
}
dup2 (pd[1], 1);
close (pd[1]);
- i = 1;
app_msgarg(&vec, "-forwall");
app_msgarg(&vec, "-form");
app_msgarg(&vec, filter);
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;
- 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;
strcasecmp (name, ENCODING_FIELD) == 0) {
if (autobuild) {
fclose(in);
+ free (ct);
return NULL;
} else {
adios (NULL, "draft shouldn't contain %s: field", name);
if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL)
adios (NULL, "out of memory");
*pp = part;
- pp = &part->mp_next;
part->mp_part = p;
}
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 ((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);
- if ((*ct = parse_mime (fixed))) {
+ if ((fixed_ct = parse_mime (fixed))) {
+ *ct = fixed_ct;
(*ct)->c_unlink = 1;
++*message_mods;
report (NULL, NULL, filename,
"fix multipart boundary");
}
+ } else {
+ advise (NULL, "unable to parse fixed part");
+ status = NOTOK;
}
free (filename);
} else {
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:
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]);
- if ((width = atoi (cp)) < 1)
+ else if ((width = atoi (cp)) < 1)
adios (NULL, "bad argument %s %s", argp[-2], cp);
continue;
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]);
- if ((volume = atoi (cp)) < 1)
+ else if ((volume = atoi (cp)) < 1)
adios (NULL, "bad argument %s %s", argp[-2], cp);
continue;
*cp = 0;
if (*bp == ':') {
- c1 = add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
+ (void) add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
continue;
}
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) {
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;
}
}
+ *fd = fileno (ce->ce_fp);
return OK;
ready_already:
{
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 */
{
int fd;
int xstdin = 0, xlist = 0;
- char *file, buffer[BUFSIZ];
+ char *file = NULL, buffer[BUFSIZ];
if (!ct->c_ceopenfnx) {
if (!alternate)
return NOTOK;
}
- file = NULL;
if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
return NOTOK;
if (ct->c_showproc && !strcmp (ct->c_showproc, "true"))
/* 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;
}
if (p->c_storage == NULL) {
- file = NULL;
if ((*p->c_ceopenfnx) (p, &file) == NOTOK)
return NOTOK;
if ((o->n_R_child = parse ()))
return o;
padvise (NULL, "missing disjunctive");
+ free (o);
return NULL;
header: ;
if (*cp != '-') {
padvise (NULL, "%s unexpected", cp);
+ free (n);
return NULL;
}
case AMBIGSW:
ambigsw (cp, parswit);
talked++;
+ free (n);
return NULL;
case UNKWNSW:
fprintf (stderr, "-%s unknown\n", cp);
talked++;
+ free (n);
return NULL;
case PRAND:
if ((o->n_R_child = nexp1 ()))
return o;
padvise (NULL, "missing conjunctive");
+ free (o);
return NULL;
header: ;
if ((n->n_L_child = nexp3 ()))
return n;
padvise (NULL, "missing negation");
+ free (n);
return NULL;
header: ;
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);
+ free (n);
return NULL;
}
n->n_patbuf = getcpy (dp);
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;
*p = 0;
if (*--p == '\n')
*p = 0;
- if (*--p == '\r')
+ if (p > s && *--p == '\r')
*p = 0;
return OK;
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);
}
break;
case BODY:
- compnum = -1;
/*
* A slight hack ... if we have less than rlwidth characters
* in the buffer, call m_getfld again.