diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22c3303ad9..83d0864356 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,6 +156,10 @@ jobs: export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/" - name: Build V run: make -j4 && ./v -cg -cflags -Werror -o v cmd/v + - name: Run sanitizers + run: | + ./v -o v2 cmd/v -cflags -fsanitize=undefined + UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v - name: Build V using V run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v - name: v self with -usecache @@ -221,6 +225,12 @@ jobs: run: make -j4 && ./v -cc gcc -cg -cflags -Werror -o v cmd/v - name: Valgrind run: valgrind --error-exitcode=1 ./v -o v.c cmd/v + - name: Run sanitizers + run: | + ./v -o v2 cmd/v -cflags -fsanitize=thread + ./v -o v3 cmd/v -cflags "-fsanitize=undefined -fno-sanitize=alignment" + UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v + UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v # - name: Test V # run: ./v -silent test-compiler # - name: Test v binaries @@ -310,8 +320,12 @@ jobs: run: valgrind --error-exitcode=1 ./v -o v.c cmd/v - name: Run sanitizers run: | - ./v -o v2 cmd/v -cflags -fsanitize=memory && ./v2 -o v.c cmd/v - ./v -o v2 cmd/v -cflags -fsanitize=thread && ./v2 -o v.c cmd/v + ./v -o v2 cmd/v -cflags -fsanitize=memory + ./v -o v3 cmd/v -cflags -fsanitize=thread + ./v -o v4 cmd/v -cflags -fsanitize=undefined + UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v + UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v + UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v4 -o v.c cmd/v - name: v self compilation run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v - name: v self with -usecache diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index f2f4842254..e15b4f642d 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -338,7 +338,9 @@ pub fn (a &array) clone() array { unsafe {arr.set_unsafe(i, &ar_clone)} } } else { - unsafe {C.memcpy(byteptr(arr.data), a.data, a.cap * a.element_size)} + if !isnil(a.data) { + unsafe {C.memcpy(byteptr(arr.data), a.data, a.cap * a.element_size)} + } } return arr } @@ -396,7 +398,7 @@ fn (mut a array) push(val voidptr) { // `val` is array.data // TODO make private, right now it's used by strings.Builder pub fn (mut a3 array) push_many(val voidptr, size int) { - if a3.data == val { + if a3.data == val && !isnil(a3.data) { // handle `arr << arr` copy := a3.clone() a3.ensure_cap(a3.len + size) @@ -406,7 +408,9 @@ pub fn (mut a3 array) push_many(val voidptr, size int) { } } else { a3.ensure_cap(a3.len + size) - unsafe {C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size)} + if !isnil(a3.data) && !isnil(val) { + unsafe {C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size)} + } } a3.len += size } diff --git a/vlib/strconv/atof.v b/vlib/strconv/atof.v index 325893f411..4a60d9af22 100644 --- a/vlib/strconv/atof.v +++ b/vlib/strconv/atof.v @@ -356,7 +356,7 @@ fn converter(mut pn PrepNumber) u64 { mut r2 := u32(0) // 96-bit precision integer mut r1 := u32(0) mut r0 := u32(0) - mask28 := u32(0xF<<28) + mask28 := u32(u64(0xF)<<28) mut result := u64(0) // working on 3 u32 to have 96 bit precision s0 = u32(pn.mantissa & u64(0x00000000FFFFFFFF))