Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strconv: string interpolation with '${f:54.40f}' leads to a MemorySanitizer: use-of-uninitialized-value error #23359

Open
spytheman opened this issue Jan 4, 2025 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. strconv module Unit: Memory Management Bugs/feature requests, that are related to the memory management of the compiler.

Comments

@spytheman
Copy link
Member

spytheman commented Jan 4, 2025

V doctor:

V full version: V 0.4.9 734bb00.3ed799e
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /home/delian/code/v
vexe: /home/delian/code/v/v
vexe mtime: 2025-01-03 23:59:54

vroot: OK, value: /home/delian/code/v
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.47.1
Git vroot status: weekly.2024.53-19-g3ed799ef
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

What did you do?
./v -g -o vdbg cmd/v && ./vdbg -keepc -cg -keepc -gc none -cc clang-18 -cflags -fsanitize=memory x_test.v && x_test

fn diff(actual f64, expected f64) string {
    C.printf(c' printf   actual: %054.54g\n', actual)
    C.printf(c' printf expected: %054.54g\n', expected)
    return '\n  actual:${actual:54.40f}\nexpected:${expected:54.40f}\n    diff:${actual - expected:54.40f}'
}

fn test_diff() {
    actual__ := -0.68849533748148505907238359213806688785552978515625
    expected := -0.68849533748148505907238359213806688785552978515625
    s := diff(actual__, expected)
    dump(s)
    assert true
}

What did you see?

==753252==WARNING: MemorySanitizer: use-of-uninitialized-value
/usr/bin/llvm-symbolizer-18: /usr/local/lib/libcurl.so.4: no version information available (required by /usr/bin/llvm-symbolizer-18)
    #0 0x555555645c90 in strconv__f64_to_str_lnd1 /tmp/v_1000/x_test.tmp.c:3920:9
    #1 0x555555646c3b in strconv__format_fl /tmp/v_1000/x_test.tmp.c:3949:15
    #2 0x555555693f55 in StrIntpData_process_str_intp_data /tmp/v_1000/x_test.tmp.c:7743:19
    #3 0x55555564c901 in str_intp /tmp/v_1000/x_test.tmp.c:7994:4
    #4 0x5555556ab1e9 in main__diff /tmp/v_1000/x_test.tmp.c:9053:9
    #5 0x5555556ab370 in main__test_diff /tmp/v_1000/x_test.tmp.c:9058:13
    #6 0x5555556ac837 in main /tmp/v_1000/x_test.tmp.c:9139:3
    #7 0x7ffff7be1082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16
    #8 0x55555558b39d in _start (/home/delian/code/v/x_test+0x3739d) (BuildId: 939d919dc452a11c3d737f0f911fa027413209ff)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /tmp/v_1000/x_test.tmp.c:3920:9 in strconv__f64_to_str_lnd1
Exiting

What did you expect to see?

A test program that runs without errors.

With -g, the stack trace becomes:

/usr/bin/llvm-symbolizer-18: /usr/local/lib/libcurl.so.4: no version information available (required by /usr/bin/llvm-symbolizer-18)
    #0 0x555555645c90 in strconv__f64_to_str_lnd1 /home/delian/code/v/vlib/strconv/format_mem.c.v:287:9
    #1 0x555555646c3b in strconv__format_fl /home/delian/code/v/vlib/strconv/format_mem.c.v:318:15
    #2 0x555555693f55 in StrIntpData_process_str_intp_data /home/delian/code/v/vlib/builtin/string_interpolation.v:444:19
    #3 0x55555564c901 in str_intp /home/delian/code/v/vlib/builtin/string_interpolation.v:706:4
    #4 0x5555556ab1e9 in main__diff /home/delian/code/v/x_test.v:4:9
    #5 0x5555556ab370 in main__test_diff /home/delian/code/v/x_test.v:10:13
    #6 0x5555556ac837 in main /tmp/v_1000/x_test.tmp.c:17219:3
    #7 0x7ffff7be1082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16
    #8 0x55555558b39d in _start (/home/delian/code/v/x_test+0x3739d) (BuildId: b871f77ea6767383b0c54f7963b09b8cc8cd51bc)

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Huly®: V_0.6-21790

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Memory Management Bugs/feature requests, that are related to the memory management of the compiler. strconv module labels Jan 4, 2025
@spytheman
Copy link
Member Author

Note changing line 212 of vlib/strconv/format_mem.c.v like this:

-               mut res := []u8{len: exp + 40, init: 0}
+               mut res := []u8{len: exp + 50, init: 0}

makes the test program pass.

@spytheman spytheman changed the title MemorySanitizer: use-of-uninitialized-value warning, when running string interpolation with '${f:54.40f}' strconv: string interpolation with '${f:54.40f}' leads to a MemorySanitizer: use-of-uninitialized-value error Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. strconv module Unit: Memory Management Bugs/feature requests, that are related to the memory management of the compiler.
Projects
None yet
Development

No branches or pull requests

1 participant