aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-12-15 17:27:22 +0000
committerdam <dam@gudinoff>2022-12-15 17:27:22 +0000
commit380d0f24426a7abd0630872c43cd68c2c7058b54 (patch)
treeb6e6520e8cca0939f22ae220d34d891e30e1de89
parentb968cf38d0c69827dfd1a1a25b4c940b1189df95 (diff)
downloadtask-time-tracker-380d0f24426a7abd0630872c43cd68c2c7058b54.tar.zst
task-time-tracker-380d0f24426a7abd0630872c43cd68c2c7058b54.zip
Improved error return on read_input_to_int.
-rw-r--r--main.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/main.c b/main.c
index 3d6ca66..918d3f0 100644
--- a/main.c
+++ b/main.c
@@ -1157,11 +1157,13 @@ bool read_input_to_int(int row, int style, const char *message, intmax_t *result
read_input_to_string_buffer(row, input_pos_x, style, input_width);
char *parser;
+ errno = 0;
*result = strtoimax(string_buffer, &parser, 10);
- // TODO Add comment about this comparison... is checking what? - ALSO ADD THIS BELOW
- // If endptr is not NULL, strtol() stores the address of the first invalid character in *endptr. If there were no digits at all, strtol() stores the original value of nptr in *endptr (and returns 0). In particular, if *nptr is not '\0' but **endptr is '\0' on return, the entire string is valid.
- return parser != string_buffer;
+ bool success = (errno == 0 || errno == ERANGE) // No error OR value was clamped to limits (acceptable).
+ && parser != string_buffer; // If no digits are found, parser will return the address of the input string.
+
+ return success;
}
// Retuns true if user presses enter, false otherwise.