public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* printf_arginfo_size_function error handling
@ 2021-03-24 16:39 Alejandro Colomar (man-pages)
  2021-03-24 19:30 ` Alejandro Colomar (man-pages)
  0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-03-24 16:39 UTC (permalink / raw)
  To: GNU C Library

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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-24 19:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 16:39 printf_arginfo_size_function error handling Alejandro Colomar (man-pages)
2021-03-24 19:30 ` Alejandro Colomar (man-pages)
2021-03-24 19:39   ` Alejandro Colomar (man-pages)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).