Skip to content

Commit

Permalink
Fix LLONG_MIN and INT_MIN
Browse files Browse the repository at this point in the history
  • Loading branch information
msg7086 committed Feb 9, 2025
1 parent 721fe20 commit 5846d59
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion common/lwindex_sscanf_unrolled.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define PARSE_OR_RETURN(buf, needle, out, type) \
if (strncmp(buf, needle, strlen(needle)) != 0) \
return 0; \
return parsed_count; \
buf += strlen(needle); \
out = my_strto_##type(buf, &buf); \
parsed_count++;
Expand All @@ -41,6 +41,12 @@ static inline int64_t my_strto_int64_t(const char *nptr, char **endptr) {
int c;
int neg = 0;

const char* min_str = "-9223372036854775808";
if (strncmp(s, min_str, strlen(min_str)) == 0) {
*endptr = (char*)s + strlen(min_str);
return LLONG_MIN;
}

/* Process sign. */
if (*s == '-') {
neg = 1;
Expand Down Expand Up @@ -76,6 +82,12 @@ static inline int my_strto_int(const char *nptr, char **endptr) {
int c;
int neg = 0;

const char* min_str = "-2147483648";
if (strncmp(s, min_str, strlen(min_str)) == 0) {
*endptr = (char*)s + strlen(min_str);
return INT_MIN;
}

/* Process sign. */
if (*s == '-') {
neg = 1;
Expand Down

0 comments on commit 5846d59

Please sign in to comment.