From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org, Daniel Kiper <dkiper@net-space.pl>
Cc: Glenn Washburn <development@efficientek.com>
Subject: [PATCH] misc: Add grub_sprintf() C99/POSIX non-conformance comment
Date: Fri, 14 Jul 2023 15:38:00 -0500 [thread overview]
Message-ID: <20230714203800.1779660-1-development@efficientek.com> (raw)
Make clear that grub_sprintf() does not conform to C99/POSIX. It returns
the number of bytes written, even when n is less than the length of the
fully formatted string.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/kern/misc.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 2890aad49fa7..634bf1441c63 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -983,6 +983,7 @@ write_number (char *str, grub_size_t *count, grub_size_t max_len, grub_size_t fo
write_char (str, count, max_len, zerofill);
}
+/* See grub_snprintf for details of non-compliance to C99 and POSIX */
static int
grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
struct printf_args *args)
@@ -1204,6 +1205,14 @@ grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list ap)
return ret < n ? ret : n;
}
+/*
+ * Note: grub_snprintf does not conform to C99 nor the POSIX specs.
+ * Specifically, it returns the number of bytes written, minus the NULL
+ * byte. Whereas, the specs say that the return value should be the
+ * number of bytes that *would* be written if n were sufficiently large
+ * to contain the formatted output. This only matters when n is smaller
+ * than the formatted string.
+ */
int
grub_snprintf (char *str, grub_size_t n, const char *fmt, ...)
{
--
2.34.1
reply other threads:[~2023-07-14 20:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230714203800.1779660-1-development@efficientek.com \
--to=development@efficientek.com \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.