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 <[email protected]> --- 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 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
