Open whitslack opened 1 year ago
The contract for tal_strndup says:
tal_strndup
https://github.com/rustyrussell/ccan/blob/cd56b18ae87de6981b88abbe52544d8cc9f8aa0e/ccan/tal/str/str.h#L22-L30
However, when tal_strndup(ctx, NULL, n) is called with n being any non-zero integer, the returned string will have tal_count() equal to n + 1 (i.e., at least 2), but strlen() will be equal to zero. 2 != 0 + 1.
tal_strndup(ctx, NULL, n)
n
tal_count()
n + 1
strlen()
2 != 0 + 1
https://github.com/rustyrussell/ccan/blob/cd56b18ae87de6981b88abbe52544d8cc9f8aa0e/ccan/tal/str/str.c#L27-L30
It seems like this^ really should say len = 0; in the else branch.
len = 0;
else
The contract for
tal_strndup
says:https://github.com/rustyrussell/ccan/blob/cd56b18ae87de6981b88abbe52544d8cc9f8aa0e/ccan/tal/str/str.h#L22-L30
However, when
tal_strndup(ctx, NULL, n)
is called withn
being any non-zero integer, the returned string will havetal_count()
equal ton + 1
(i.e., at least 2), butstrlen()
will be equal to zero.2 != 0 + 1
.https://github.com/rustyrussell/ccan/blob/cd56b18ae87de6981b88abbe52544d8cc9f8aa0e/ccan/tal/str/str.c#L27-L30
It seems like this^ really should say
len = 0;
in theelse
branch.