logo

utils-std

Collection of commonly available Unix tools
commit: 294e468dd8fde2ac7bee6c7532142f56b8f7abae
parent eb054987dab5a048d2f16ea139b76a2240e78207
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu,  4 Jul 2024 14:22:36 +0200

cmd/*: Check endptr after strtoul

This is mostly due to glibc not setting EINVAL

Diffstat:

Mcmd/head.c4++--
Mcmd/timeout.c2+-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmd/head.c b/cmd/head.c @@ -173,7 +173,7 @@ main(int argc, char *argv[]) char *endptr = NULL; lines = strtoul(arg, &endptr, 0); - if(errno != 0) + if(!(errno == 0 && endptr != NULL && *endptr == '\0')) { fprintf(stderr, "head: Error while parsing number for `-%s`: %s\n", arg, strerror(errno)); return 1; @@ -218,7 +218,7 @@ main(int argc, char *argv[]) assert(errno == 0); char *endptr = NULL; lines = strtoul(optarg, &endptr, 0); - if(errno != 0) + if(!(errno == 0 && endptr != NULL && *endptr == '\0')) { fprintf( stderr, "head: Error while parsing number for `-n %s`: %s\n", optarg, strerror(errno)); diff --git a/cmd/timeout.c b/cmd/timeout.c @@ -75,7 +75,7 @@ main(int argc, char *argv[]) char *endptr = NULL; unsigned long optoul = strtoul(optarg, &endptr, 10); - if(errno != 0 && endptr != NULL) + if(!(errno == 0 && endptr != NULL && *endptr == '\0')) { fprintf(stderr, "timeout: Mix of digit and non-digit characters passed to -s option '%s'\n",