From 4a4b8b6117c758d70da915742cd9bffdf2d55e86 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Mon, 1 Jun 2009 11:24:43 +0200 Subject: [PATCH] Add mutt_atos(), mutt_atoi() and mutt_atol() (strtol() wrappers) --- ChangeLog | 13 +++++++++++++ lib.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib.h | 10 ++++++++++ 3 files changed, 78 insertions(+) diff --git a/ChangeLog b/ChangeLog index 97c0c41d0..c3a9796f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-06-01 10:36 +0200 Rocco Rutte (36b7e267ce33) + + * send.c: Treat address groups as no recipients + + When sending with Sendmail or SMTP we exclude address groups anyway, + so treat these addresses as not present when checking for valid + recipients before sending in the compose menu. + +2009-06-01 10:29 +0200 Rocco Rutte (64250df0e9a4) + + * ChangeLog, smtp.c: Weed out address groups for SMTP the same way we + do for sendmail + 2009-05-31 19:19 -0700 Brendan Cully (0024860ab03e) * doc/Makefile.am: Allow chunked and unchunked manuals to build in diff --git a/lib.c b/lib.c index 6fd243727..c1f124ec9 100644 --- a/lib.c +++ b/lib.c @@ -1006,3 +1006,58 @@ mutt_strsysexit(int e) return sysexits_h[i].str; } + +int mutt_atos (const char *str, short *dst) +{ + int rc; + long res; + short tmp; + short *t = dst ? dst : &tmp; + + *t = 0; + + if ((rc = mutt_atol (str, &res)) < 0) + return rc; + if ((short) res != res) + return -2; + + *t = (short) res; + return 0; +} + +int mutt_atoi (const char *str, int *dst) +{ + int rc; + long res; + int tmp; + int *t = dst ? dst : &tmp; + + *t = 0; + + if ((rc = mutt_atol (str, &res)) < 0) + return rc; + if ((int) res != res) + return -2; + + *t = (int) res; + return 0; +} + +int mutt_atol (const char *str, long *dst) +{ + long r; + long *res = dst ? dst : &r; + char *e = NULL; + + /* no input: 0 */ + if (!str || !*str) + { + *res = 0; + return 0; + } + + *res = strtol (str, &e, 10); + if (e && *e != '\0') + return -1; + return 0; +} diff --git a/lib.h b/lib.h index 6fabfd739..5ce9b805c 100644 --- a/lib.h +++ b/lib.h @@ -158,6 +158,16 @@ char *safe_strcat (char *, size_t, const char *); char *safe_strncat (char *, size_t, const char *, size_t); char *safe_strdup (const char *); +/* strtol() wrappers with range checking; they return + * 0 success + * -1 format error + * -2 overflow (for int and short) + * the int pointer may be NULL to test only without conversion + */ +int mutt_atos (const char *, short *); +int mutt_atoi (const char *, int *); +int mutt_atol (const char *, long *); + const char *mutt_stristr (const char *, const char *); const char *mutt_basename (const char *); -- 2.40.0