X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftal%2Ftest%2Frun-overflow.c;h=c5daf97d2794b99966dd59e959cdab7d649be87f;hp=989fcd2aba2eee5e9339e06abdd3be4eb7549644;hb=680aa496521811e7c60afb940bcae5024f4c6adb;hpb=5582b011948769779b0d839d35873c2bc557f9cb diff --git a/ccan/tal/test/run-overflow.c b/ccan/tal/test/run-overflow.c index 989fcd2a..c5daf97d 100644 --- a/ccan/tal/test/run-overflow.c +++ b/ccan/tal/test/run-overflow.c @@ -13,8 +13,9 @@ int main(void) { void *p; int *pi, *origpi; + char *cp; - plan_tests(26); + plan_tests(30); tal_set_backend(NULL, NULL, NULL, my_error); @@ -81,5 +82,17 @@ int main(void) ok1(error_count == 1); ok1(!tal_first(NULL)); + /* Overflow on expand addition. */ + cp = tal_arr(p, char, 100); + ok1(!tal_expand(&cp, NULL, (size_t)-99UL)); + ok1(error_count == 2); + tal_free(cp); + + /* Overflow when multiplied by size */ + origpi = tal_arr(NULL, int, 100); + ok1(!tal_expand(&origpi, NULL, (size_t)-1UL / sizeof(int))); + ok1(error_count == 3); + tal_free(origpi); + return exit_status(); }