|| !buf[0])
break;
- if (! isdigit ((unsigned char) buf[0]))
+ if (mutt_atoi (buf, &i) < 0)
{
mutt_error _("Argument must be a message number.");
break;
}
- i = atoi (buf);
if (i > 0 && i <= Context->msgcount)
{
for (j = i-1; j < Context->msgcount; j++)
while ((msg = strtok (msg, " ,")) != NULL)
{
- n = atoi (msg);
- if (n > 0 && n <= Context->msgcount)
+ if (mutt_atoi (msg, &n) == 0 && n > 0 && n <= Context->msgcount)
{
n--;
else if (DTYPE(MuttVars[idx].type) == DT_NUM)
{
short *ptr = (short *) MuttVars[idx].data;
- int val;
- char *t;
+ short val;
+ int rc;
if (query || *s->dptr != '=')
{
s->dptr++;
mutt_extract_token (tmp, s, 0);
- val = strtol (tmp->data, &t, 0);
+ rc = mutt_atos (tmp->data, (short *) &val);
- if (!*tmp->data || *t || (short) val != val)
+ if (rc < 0 || !*tmp->data)
{
- snprintf (err->data, err->dsize, _("%s: invalid value"), tmp->data);
+ snprintf (err->data, err->dsize, _("%s: invalid value (%s)"), tmp->data,
+ rc == -1 ? _("format error") : _("number overflow"));
r = -1;
break;
}
else
- *ptr = (short) val;
+ *ptr = val;
/* these ones need a sanity check */
if (mutt_strcmp (MuttVars[idx].option, "history") == 0)
case 'd':
#ifdef DEBUG
- debuglevel = atoi (optarg);
+ if (mutt_atoi (optarg, &debuglevel) < 0 || debuglevel <= 0)
+ {
+ fprintf (stderr, _("Error: value '%s' is invalid for -d.\n"), optarg);
+ return 1;
+ }
printf (_("Debugging at level %d.\n"), debuglevel);
#else
printf _("DEBUG was not defined during compilation. Ignored.\n");
buf[0] = 0;
if (mutt_get_field (_("Jump to: "), buf, sizeof (buf), 0) == 0 && buf[0])
{
- n = atoi (buf) - 1;
- if (n >= 0 && n < menu->max)
+ if (mutt_atoi (buf, &n) == 0 && n > 0 && n < menu->max + 1)
{
+ n--; /* msg numbers are 0-based */
menu->current = n;
menu->redraw = REDRAW_MOTION;
}
#endif
-static void mh_read_token (char *t, int *first, int *last)
+static int mh_read_token (char *t, int *first, int *last)
{
char *p;
if ((p = strchr (t, '-')))
{
*p++ = '\0';
- *first = atoi (t);
- *last = atoi (p);
+ if (mutt_atoi (t, first) < 0 || mutt_atoi (t, last) < 0)
+ return -1;
}
else
- *first = *last = atoi (t);
+ {
+ if (mutt_atoi (t, first) < 0)
+ return -1;
+ *last = *first;
+ }
+ return 0;
}
-static void mh_read_sequences (struct mh_sequences *mhs, const char *path)
+static int mh_read_sequences (struct mh_sequences *mhs, const char *path)
{
FILE *fp;
int line = 1;
size_t sz = 0;
short f;
- int first, last;
+ int first, last, rc;
char pathname[_POSIX_PATH_MAX];
snprintf (pathname, sizeof (pathname), "%s/.mh_sequences", path);
if (!(fp = fopen (pathname, "r")))
- return;
+ return 0; /* yes, ask callers to silently ignore the error */
while ((buff = mutt_read_line (buff, &sz, fp, &line, 0)))
{
while ((t = strtok (NULL, " \t:")))
{
- mh_read_token (t, &first, &last);
+ if (mh_read_token (t, &first, &last) < 0)
+ {
+ mhs_free_sequences (mhs);
+ rc = -1;
+ goto out;
+ }
for (; first <= last; first++)
mhs_set (mhs, first, f);
}
}
+ rc = 0;
+
+out:
FREE (&buff);
safe_fclose (&fp);
+ return 0;
}
static inline mode_t mh_umask (CONTEXT* ctx)
struct mh_sequences mhs;
memset (&mhs, 0, sizeof (mhs));
- mh_read_sequences (&mhs, path);
+ if (mh_read_sequences (&mhs, path) < 0)
+ return 0;
for (i = 0; !r && i <= mhs.max; i++)
if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN)
r = 1;
- mhs_free_sequences (&mhs);
return r;
}
if (ctx->magic == M_MH)
{
- mh_read_sequences (&mhs, ctx->path);
+ if (mh_read_sequences (&mhs, ctx->path) >= 0)
+ return -1;
mh_update_maildir (md, &mhs);
mhs_free_sequences (&mhs);
}
if (!data->mh_umask)
data->mh_umask = mh_umask (ctx);
-
+
return 0;
}
maildir_parse_dir (ctx, &last, NULL, NULL, NULL);
maildir_delayed_parsing (ctx, &md, NULL);
- mh_read_sequences (&mhs, ctx->path);
+ if (mh_read_sequences (&mhs, ctx->path) < 0)
+ return -1;
mh_update_maildir (md, &mhs);
mhs_free_sequences (&mhs);
#ifdef SUN_ATTACHMENT
if (mutt_get_parameter ("content-lines", new->parameter)) {
- for (lines = atoi(mutt_get_parameter ("content-lines", new->parameter));
- lines; lines-- )
+ mutt_atoi (mutt_get_parameter ("content-lines", new->parameter), &lines);
+ for ( ; lines; lines-- )
if (ftello (fp) >= end_off || fgets (buffer, LONG_STRING, fp) == NULL)
break;
}
switch (count)
{
case 0: /* day of the month */
- if (!isdigit ((unsigned char) *t))
+ if (mutt_atoi (t, &tm.tm_mday) < 0 || tm.tm_mday < 0)
return (-1);
- tm.tm_mday = atoi (t);
if (tm.tm_mday > 31)
return (-1);
break;
break;
case 2: /* year */
- tm.tm_year = atoi (t);
+ if (mutt_atoi (t, &tm.tm_year) < 0 || tm.tm_year < 0)
+ return (-1);
if (tm.tm_year < 50)
tm.tm_year += 100;
else if (tm.tm_year >= 1900)
{
if (hdr)
{
- if ((hdr->content->length = atoi (p)) < 0)
+ if ((hdr->content->length = atol (p)) < 0)
hdr->content->length = -1;
}
matched = 1;
{
if (hdr)
{
- hdr->lines = atoi (p);
-
/*
* HACK - mutt has, for a very short time, produced negative
* Lines header values. Ignore them.
*/
- if (hdr->lines < 0)
+ if (mutt_atoi (p, &hdr->lines) < 0 || hdr->lines < 0)
hdr->lines = 0;
}
}
if (SLtt_Screen_Rows <= 0)
{
- if ((cp = getenv ("LINES")) != NULL)
- {
- SLtt_Screen_Rows = atoi (cp);
- }
- else
+ if ((cp = getenv ("LINES")) != NULL && mutt_atoi (cp, &SLtt_Screen_Rows) < 0)
SLtt_Screen_Rows = 24;
}
if (SLtt_Screen_Cols <= 0)
{
- if ((cp = getenv ("COLUMNS")) != NULL)
- SLtt_Screen_Cols = atoi (cp);
- else
+ if ((cp = getenv ("COLUMNS")) != NULL && mutt_atoi (cp, &SLtt_Screen_Cols) < 0)
SLtt_Screen_Cols = 80;
}
#ifdef USE_SLANG_CURSES
ptr->exact = 1;
pc++;
}
- ptr->val = atoi (pc);
+ if (mutt_atoi (pc, &ptr->val) < 0)
+ {
+ FREE (&pattern);
+ strfcpy (err->data, _("Error: score: invalid number"), err->dsize);
+ return (-1);
+ }
set_option (OPTNEEDRESCORE);
return 0;
}
if ((p = strchr (t, ':')))
{
*p++ = '\0';
- ciss->port = atoi (p);
+ if (mutt_atos (p, (short*) &ciss->port) < 0)
+ return NULL;
}
else
ciss->port = 0;
tmp = strchr (src, ':') + 1;
- ciss->path = ciss_parse_userhost (ciss, tmp);
+ if ((ciss->path = ciss_parse_userhost (ciss, tmp)) == NULL)
+ return -1;
url_pct_decode (ciss->path);
return 0;