Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ch18 - Arbitrary Precision: strict code #13

Open
ylme opened this issue Nov 3, 2019 · 1 comment
Open

Ch18 - Arbitrary Precision: strict code #13

ylme opened this issue Nov 3, 2019 · 1 comment

Comments

@ylme
Copy link

ylme commented Nov 3, 2019

https://github.com/drh/cii/blob/master/src/ap.c#L361

Before AP_new(0) , call AP_free(&z) making code stricting, Does it ?

if (endp == p) { endp = (char *)str; z = AP_new(0); }

@juniskane
Copy link

I don't know what you mean by "strict code" or "stricting", but this looks like a memory leak of old value of 'z', that was allocated by mk() earlier. It is not in book's errata.

But I don't think the branch if (endp == p) here is ever taken. This is because called XP_fromstr() can return with that condition only if passed string contains zero valid digits in base. But AP_fromstr() validates the digits before calling XP_fromstr() and before z = mk(((k*n + 7)&~7)/8) call. However if this validation fails with first digit (the endp == p case), then n is 0 which makes entire expression 0 and mk() asserts on assert(size > 0) line:

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

This exception makes the error handling block dead code, and is bug in itself. Call char *end; AP_fromstr("A", 10, &end); to easily reproduce.

juniskane added a commit to juniskane/cii that referenced this issue Mar 9, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants