diff options
author | Squibid <me@zacharyscheiman.com> | 2025-02-18 14:48:32 -0600 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2025-02-18 14:48:32 -0600 |
commit | 09362e2c7c376a7759f7e08790b8968a0e6bf30a (patch) | |
tree | e76875678e9a69f951d4741706c5e425d9473191 /XD.c | |
parent | 6025b2d8322caea124582fb9292780382466d660 (diff) | |
download | XD-09362e2c7c376a7759f7e08790b8968a0e6bf30a.tar.gz XD-09362e2c7c376a7759f7e08790b8968a0e6bf30a.tar.bz2 XD-09362e2c7c376a7759f7e08790b8968a0e6bf30a.zip |
replace atoi with my own impl to make sure that no errors occour
Diffstat (limited to '')
-rw-r--r-- | XD.c | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -230,6 +230,34 @@ has_staged(git_repository *repo) } #endif +inline unsigned +numcat(unsigned x, unsigned y) +{ + unsigned pow = 10; + while(y >= pow) { + pow *= 10; + } + + return (x * pow) + y; +} + +int +str_to_int(char *str) +{ + int res = -1; + char *c; + + for (c = str; (*c != '\0') && isdigit(*c); c++) { + if (res == -1) { + res = *c - '0'; + } else { + res = numcat(res, *c - '0'); + } + } + + return res; +} + int main(int argc, char *argv[]) { @@ -282,8 +310,12 @@ main(int argc, char *argv[]) } /* get exit code from user args */ - if (argv[1]) { - code = atoi(argv[1]); + if (argc > 1 && argv[argc - 1]) { + code = str_to_int(argv[argc - 1]); + if (code < 0) { + L("Return code, %d, not valid", code); + exit(1); + } } /* change mouth based on exit code */ |