diff options
| -rw-r--r-- | main.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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. |
