diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-11 20:39:49 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-11 20:39:49 +0200 |
commit | bc5c3034cab84e9a7d587c2590c2d3f06283972e (patch) | |
tree | f895ac024c2ff37907781890ee672c74e7a96ed4 /set-contact-birthday.c | |
parent | Rewrite set-contact-numbers to work like set-contact-addresses (diff) | |
download | contacts-bc5c3034cab84e9a7d587c2590c2d3f06283972e.tar.gz contacts-bc5c3034cab84e9a7d587c2590c2d3f06283972e.tar.bz2 contacts-bc5c3034cab84e9a7d587c2590c2d3f06283972e.tar.xz |
Improve set-contact- utils
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | set-contact-birthday.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/set-contact-birthday.c b/set-contact-birthday.c index 9db0987..74dadc7 100644 --- a/set-contact-birthday.c +++ b/set-contact-birthday.c @@ -2,20 +2,23 @@ #include "common.h" /* Date components are in different options to avoid date format confusion */ -USAGE("([-y year | -Y] [-m month | -M] [-d day | -D] [-b | -B] | -u) contact-id ..."); +USAGE("([-Y | -y year] [-M | -m month] [-D | -d day] [-B | -b] | -u) contact-id ..."); +#if defined(__GNUC__) +__attribute__((__pure__)) +#endif static int getintarg(const char *arg) { int ret = 0; for (; isdigit(*arg); arg++) { if (ret > (INT_MAX - (*arg & 15)) / 10) - usage(); + return -1; ret = ret * 10 + (*arg & 15); } if (*arg) - usage(); + return -1; return ret; } @@ -34,6 +37,8 @@ main(int argc, char *argv[]) if (year) usage(); year = getintarg(ARG()); + if (year < 0) + usage(); break; case 'Y': if (year) @@ -44,6 +49,8 @@ main(int argc, char *argv[]) if (month) usage(); month = getintarg(ARG()); + if (month < 0) + usage(); break; case 'M': if (month) @@ -54,6 +61,8 @@ main(int argc, char *argv[]) if (day) usage(); day = getintarg(ARG()); + if (day < 0) + usage(); break; case 'D': if (day) |