From 52266c9f662a5ca7550daeebc94678c5dd1dbcb3 Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Mon, 15 May 2017 07:05:07 +0100 Subject: [PATCH] Make %x formatting verb in early.Printf behave like fmt.Printf The %x verb in fmt.Printf does not add the "0x" prefix automatically so early.Printf has been changed to match this behavior. --- kernel/kfmt/early/early_fmt.go | 7 ------- kernel/kfmt/early/early_fmt_test.go | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/kernel/kfmt/early/early_fmt.go b/kernel/kfmt/early/early_fmt.go index d3b9bfe..b24cbfe 100644 --- a/kernel/kfmt/early/early_fmt.go +++ b/kernel/kfmt/early/early_fmt.go @@ -246,13 +246,6 @@ func fmtInt(v interface{}, base, padLen int) { buf[right] = padCh } - // Apply hex prefix - if base == 16 { - buf[right] = 'x' - buf[right+1] = '0' - right += 2 - } - // Apply negative sign to the rightmost blank character (if using enough padding); // otherwise append the sign as a new char if sval < 0 { diff --git a/kernel/kfmt/early/early_fmt_test.go b/kernel/kfmt/early/early_fmt_test.go index 86ced53..4a004df 100644 --- a/kernel/kfmt/early/early_fmt_test.go +++ b/kernel/kfmt/early/early_fmt_test.go @@ -71,7 +71,7 @@ func TestPrintf(t *testing.T) { "uint arg: 777", }, { - func() { printfn("uint arg: %x", uint32(0xbadf00d)) }, + func() { printfn("uint arg: 0x%x", uint32(0xbadf00d)) }, "uint arg: 0xbadf00d", }, { @@ -83,16 +83,16 @@ func TestPrintf(t *testing.T) { "uint arg with padding: '0777'", }, { - func() { printfn("uint arg with padding: '%10x'", uint64(0xbadf00d)) }, + func() { printfn("uint arg with padding: '0x%10x'", uint64(0xbadf00d)) }, "uint arg with padding: '0x000badf00d'", }, { - func() { printfn("uint arg longer than padding: '%5x'", int64(0xbadf00d)) }, + func() { printfn("uint arg longer than padding: '0x%5x'", int64(0xbadf00d)) }, "uint arg longer than padding: '0xbadf00d'", }, // pointers { - func() { printfn("uintptr %x", uintptr(0xb8000)) }, + func() { printfn("uintptr 0x%x", uintptr(0xb8000)) }, "uintptr 0xb8000", }, // ints @@ -107,7 +107,7 @@ func TestPrintf(t *testing.T) { }, { func() { printfn("int arg: %x", int32(-0xbadf00d)) }, - "int arg: -0xbadf00d", + "int arg: -badf00d", }, { func() { printfn("int arg with padding: '%10d'", int64(-12345678)) }, @@ -123,7 +123,7 @@ func TestPrintf(t *testing.T) { }, { func() { printfn("int arg longer than padding: '%5x'", int(-0xbadf00d)) }, - "int arg longer than padding: '-0xbadf00d'", + "int arg longer than padding: '-badf00d'", }, // multiple arguments {