Thread (33 messages) 33 messages, 11 authors, 2022-07-11

RE: [PATCH 00/12] Clang -Wformat warning fixes

From: David Laight <hidden>
Date: 2022-06-10 09:15:44
Also in: alsa-devel, linux-acpi, linux-edac, linux-mm, lkml, llvm, netfilter-devel

From: Jan Engelhardt
Sent: 10 June 2022 09:32


On Friday 2022-06-10 10:17, David Laight wrote:
quoted
quoted
Calling a "printf" style function is already insanely expensive. :-) I
understand that it's not okay blithely to increase runtime resources
simply because it's already slow, but in this case it's worthwhile.
Yep, IMHO definitely should be fixed.
It is even possible that using "%s" is faster because the printf
code doesn't have to scan the string for format effectors.
I see no special handling; the vsnprintf function just loops
over fmt as usual and I see no special casing of fmt by
e.g. strcmp(fmt, "%s") == 0 to take a shortcut.
Consider the difference between:
	printf("fubar");
and
	printf("%s", "fubar");
In the former all of "fubar" is checked for '%'.
In the latter only the length of "fubar" has to be counted.

FWIW the patch description should probably by:
	use "%s" when formatting a single string.
(or something to that effect).

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help