Skip to content

tal/str: don't loop in tal_fmt (et al.)#121

Open
whitslack wants to merge 1 commit into
rustyrussell:masterfrom
whitslack:tal_fmt-speed
Open

tal/str: don't loop in tal_fmt (et al.)#121
whitslack wants to merge 1 commit into
rustyrussell:masterfrom
whitslack:tal_fmt-speed

Conversation

@whitslack

@whitslack whitslack commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

There is no need to loop. Just ask vsnprintf how many bytes it needs, and size your buffer accordingly.

FYI, the POSIX documentation for vsnprintf() states:

If the value of n is zero on a call to snprintf(), nothing shall be written, the number of bytes that would have been written had n been sufficiently large excluding the terminating null shall be returned, and s may be a null pointer.

I'm sorry that GitHub doesn't display the diff sensibly. (Git does.) It's easier to grok if you just hit View File. The code is very straightforward.

There is no need to loop. Just ask vsnprintf how many bytes it needs,
and size your buffer accordingly.

FYI, the POSIX documentation for vsnprintf() states:

> If the value of n is zero on a call to snprintf(), nothing shall be
> written, the number of bytes that would have been written had n been
> sufficiently large excluding the terminating null shall be returned,
> and s may be a null pointer.
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

Successfully merging this pull request may close these issues.

1 participant