[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] misc: Add grub_sprintf() C99/POSIX non-conformance comment
From: |
Glenn Washburn |
Subject: |
[PATCH] misc: Add grub_sprintf() C99/POSIX non-conformance comment |
Date: |
Fri, 14 Jul 2023 15:38:00 -0500 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] misc: Add grub_sprintf() C99/POSIX non-conformance comment,
Glenn Washburn <=