Skip to contentSkip to conversation

misc: Make grub_vsnprintf C99/POSIX conformant

PATCH In review Glenn Washburn 2 participants 2 messages Aug 18, 2023 – Aug 30, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: Make grub_vsnprintf C99/POSIX conformant

To comply with C99 and POSIX standards, snprintf should return the number of bytes that would be written to the string (excluding the terminating NULL byte) if the buffer size was big enough. Before this change, the return value was the minimum of the standard return and the length of the buffer. Rarely is the return value of grub_snprintf or grub_vsnprintf used with current code, and the few places where it is used do not need to be changed.

---
 grub-core/kern/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/misc.c +1 -1
index 95bf7860f3da..afb41bd63a6a 100644
@@ -1201,7 +1201,7 @@ grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list ap)
 
   free_printf_args (&args);
 
-  return ret < n ? ret : n;
+  return ret;
 }
 
 int
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Glenn Washburn

To comply with C99 and POSIX standards, snprintf should return the number of bytes that would be written to the string (excluding the terminating NULL byte) if the buffer size was big enough. Before this change, the return value was the minimum of the standard return and the length of the buffer. Rarely is the return value of grub_snprintf or grub_vsnprintf used with current code, and the few places where it is used do not need to be changed.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel