* [PATCH] misc: Add grub_sprintf() C99/POSIX non-conformance comment
@ 2023-07-14 20:38 Glenn Washburn
0 siblings, 0 replies; only message in thread
From: Glenn Washburn @ 2023-07-14 20:38 UTC (permalink / raw)
To: grub-devel, Daniel Kiper; +Cc: Glenn Washburn
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-14 20:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-14 20:38 [PATCH] misc: Add grub_sprintf() C99/POSIX non-conformance comment Glenn Washburn
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.