The contract for tal_strndup says:
|
/** |
|
* tal_strndup - duplicate a limited amount of a string. |
|
* @ctx: NULL, or tal allocated object to be parent. |
|
* @p: the string to copy (can be take()). |
|
* @n: the maximum length to copy. |
|
* |
|
* Always gives a nul-terminated string, with strlen() <= @n. |
|
* The returned string will have tal_count() == strlen() + 1. |
|
*/ |
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.
|
if (likely(p)) |
|
len = strnlen(p, n); |
|
else |
|
len = n; |
It seems like this^ really should say len = 0; in the else branch.
The contract for
tal_strndupsays:ccan/ccan/tal/str/str.h
Lines 22 to 30 in cd56b18
However, when
tal_strndup(ctx, NULL, n)is called withnbeing 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.ccan/ccan/tal/str/str.c
Lines 27 to 30 in cd56b18
It seems like this^ really should say
len = 0;in theelsebranch.