[ipxe-devel] %lld format patch

James Harper james at ejbdigital.com.au
Wed Nov 4 08:24:20 UTC 2015


The following trivial patch adds support for %lld printf format. Currently, %lld will only take a 32 bit parameter from the stack which doesn't give the right answer and throws out the rest of the parameter list.

diff --git a/src/core/vsprintf.c b/src/core/vsprintf.c
index cb3bec5..60a90fd 100644
--- a/src/core/vsprintf.c
+++ b/src/core/vsprintf.c
@@ -130,7 +130,7 @@ static char * format_hex ( char *end, unsigned long long num, int width,
  * There must be enough space in the buffer to contain the largest
  * number that this function can format.
  */
-static char * format_decimal ( char *end, signed long num, int width,
+static char * format_decimal ( char *end, signed long long num, int width,
                               int flags ) {
        char *ptr = end;
        int negative = 0;
@@ -281,9 +281,11 @@ size_t vcprintf ( struct printf_context *ctx, const char *fmt, va_list args ) {
                        }
                        ptr = format_hex ( ptr, hex, width, flags );
                } else if ( ( *fmt == 'd' ) || ( *fmt == 'i' ) ){
-                       signed long decimal;
+                       signed long long decimal;

-                       if ( *length >= sizeof ( signed long ) ) {
+                       if ( *length >= sizeof ( signed long long ) ) {
+                               decimal = va_arg ( args, signed long long );
+                       } else if ( *length >= sizeof ( signed long ) ) {
                                decimal = va_arg ( args, signed long );
                        } else {
                                decimal = va_arg ( args, signed int );



More information about the ipxe-devel mailing list