]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
vsprintf.c: correct printing of a NULL device path
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 26 Jan 2018 05:30:30 +0000 (06:30 +0100)
committerAlexander Graf <agraf@suse.de>
Sun, 28 Jan 2018 20:37:13 +0000 (21:37 +0100)
When printing '%pD' with a value of NULL we want to output
'<NULL>'. But this requires copying to buf. Leave this
to string16.

A unit test is supplied which relies on EFI support in the sandbox.

The development for EFI support in the sandbox is currently in branch
u-boot-dm/efi-working. The branch lacks commit 6ea8b580f06b ("efi_loader:
correct DeviceNodeToText for media types"). Ater rebasing the aforementioned
branch on U-Boot v2018.01 and adding 256060e4257a2 and this patch the test
is executed successfully.

Fixes: 256060e4257a2 (vsprintf.c: add EFI device path printing)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/vsprintf.c
test/print_ut.c

index 226f4eb3e5125878200fbeb1109d3ab24e41e260..5f7a5f17dc6917cf539c9b207698408a43eda493 100644 (file)
@@ -300,8 +300,9 @@ static char *device_path_string(char *buf, char *end, void *dp, int field_width,
 {
        u16 *str;
 
+       /* If dp == NULL output the string '<NULL>' */
        if (!dp)
-               return "<NULL>";
+               return string16(buf, end, dp, field_width, precision, flags);
 
        str = efi_dp_str((struct efi_device_path *)dp);
        if (!str)
index 1aa68be7a9ac6cef1e68e31e6f31b9472068091f..d8e9da8fa8f4141235ac01d7d1654f5b6314b1f7 100644 (file)
@@ -44,6 +44,10 @@ static void efi_ut_print(void)
 
        snprintf(str, sizeof(str), "_%pD_", buf);
        assert(!strcmp("_/SD(3)_", str));
+
+       /* NULL device path */
+       snprintf(str, sizeof(str), "_%pD_", NULL);
+       assert(!strcmp("_<NULL>_", str));
 #endif
 }