Skip to content

Commit

Permalink
Merge branch 'bug/124'
Browse files Browse the repository at this point in the history
* bug/124:
  fix, extend slot to capture INT64_MIN, fixes bug #124
  • Loading branch information
hroptatyr committed Mar 5, 2021
2 parents a975812 + a0ebd00 commit a669bba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/dt-core-strpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ __strpdt_card(struct strpdt_s *d, const char *sp, struct dt_spec_s s, char **ep)
sp = tp;
}
if (s.spfl == DT_SPFL_N_EPOCHNS) {
d->st.ns = d->i % 1000000000;
d->i /= 1000000000;
d->st.ns = d->i % 1000000000LL;
d->i /= 1000000000LL;
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dt-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
struct strpdt_s {
struct strpd_s sd;
struct strpt_s st;
long int i;
int64_t i;

/* use 31 bits for the difference */
int32_t zdiff:31;
Expand Down
16 changes: 6 additions & 10 deletions lib/strops.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ strtoi32(const char *str, const char **ep)
{
const char *sp = str;
bool negp = false;
int32_t res = 0;
int32_t res = INT32_MIN;

if (*str == '-') {
negp = true;
Expand All @@ -122,12 +122,10 @@ strtoi32(const char *str, const char **ep)
while (res < INT32_MAX / 10 && (unsigned char)(*sp ^ '0') < 10U) {
res *= 10, res += (unsigned char)(*sp++ ^ '0');
}
if (UNLIKELY(sp == str)) {
res = INT32_MIN;
} else if (negp) {
if (negp) {
res = -res;
}
*ep = (char*)sp;
*ep = res > INT32_MIN ? (char*)sp : (char*)str;
return res;
}

Expand All @@ -137,7 +135,7 @@ strtoi64(const char *str, const char **ep)
{
const char *sp = str;
bool negp = false;
int64_t res = 0;
int64_t res = INT64_MIN;

if (*str == '-') {
negp = true;
Expand All @@ -146,12 +144,10 @@ strtoi64(const char *str, const char **ep)
while (res < INT64_MAX / 10 && (unsigned char)(*sp ^ '0') < 10U) {
res *= 10, res += (unsigned char)(*sp++ ^ '0');
}
if (UNLIKELY(sp == str)) {
res = INT64_MIN;
} else if (negp) {
if (negp) {
res = -res;
}
*ep = (char*)sp;
*ep = res > INT64_MIN ? (char*)sp : (char*)str;
return res;
}

Expand Down

0 comments on commit a669bba

Please sign in to comment.