Skip to content

Commit

Permalink
src/ap.c: fix crash in AP_fromstr()
Browse files Browse the repository at this point in the history
Calls where first character in string is not a valid digit
in base, like:

  char *end;
  AP_fromstr("A", 10, &end);

throw an unhandled exception:

  Uncaught exception Assertion failed raised at src/ap.c:26
  aborting...

instead of properly handling the error.

Issue described in drh#13
  • Loading branch information
juniskane committed Mar 9, 2023
1 parent 9cb8b5f commit ea69a4f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ap.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ T AP_fromstr(const char *str, int base, char **end) {
|| 'a' <= *p && *p <= 'z' && *p < 'a' + base - 10
|| 'A' <= *p && *p <= 'Z' && *p < 'A' + base - 10); p++)
n++;
if (n == 0) {
z = AP_new(0);
if (end)
*end = (char *)str;
return z;
}
for (k = 1; (1<<k) < base; k++)
;
z = mk(((k*n + 7)&~7)/8);
Expand All @@ -355,12 +361,9 @@ T AP_fromstr(const char *str, int base, char **end) {
carry = XP_fromstr(z->size, z->digits, p,
base, &endp);
assert(carry == 0);
assert(endp != p);
normalize(z, z->size);
if (endp == p) {
endp = (char *)str;
z = AP_new(0);
} else
z->sign = iszero(z) || sign != '-' ? 1 : -1;
z->sign = iszero(z) || sign != '-' ? 1 : -1;
if (end)
*end = (char *)endp;
return z;
Expand Down

0 comments on commit ea69a4f

Please sign in to comment.