printf_arginfo_size_function error handling
Alejandro Colomar (man-pages)
alx.manpages@gmail.com
Wed Mar 24 16:39:05 GMT 2021
Hi,
I've been re-reading the docs for printf_register_specifier(), and
there's something in an example code that doesn't make much sense:
<https://www.gnu.org/software/libc/manual/html_node/Printf-Extension-Example.html>
[[
int
print_widget_arginfo (const struct printf_info *info, size_t n,
int *argtypes)
{
/* We always take exactly one argument and this is a pointer to the
structure.. */
if (n > 0)
argtypes[0] = PA_POINTER;
return 1;
}
]]
In the code above there is a check that n>0, but:
What can a user do if n<=0 ? There's no error reporting method, is there?
And, is it possible for such a case to happen? What to do there?
I think either using an assert() or not checking at all might make more
sense (depending on how possible is n<=0 to happen). The current check
continues as if everything was fine, just without setting argtypes[0],
so if there's an error, it will be carried to some future stage, where
nasal daemons might unexpectedly happen.
Thanks,
Alex
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
More information about the Libc-alpha
mailing list