From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: GNU C Library <libc-alpha@sourceware.org>
Subject: printf_arginfo_size_function error handling
Date: Wed, 24 Mar 2021 17:39:05 +0100 [thread overview]
Message-ID: <cb1c1500-ce60-faf9-0864-0a996fbe20db@gmail.com> (raw)
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/
next reply other threads:[~2021-03-24 16:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-24 16:39 Alejandro Colomar (man-pages) [this message]
2021-03-24 19:30 ` Alejandro Colomar (man-pages)
2021-03-24 19:39 ` Alejandro Colomar (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cb1c1500-ce60-faf9-0864-0a996fbe20db@gmail.com \
--to=alx.manpages@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).