cii
cii copied to clipboard
Ch18 - Arbitrary Precision: strict code
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); }
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.