Odin icon indicating copy to clipboard operation
Odin copied to clipboard

compiler crash parsing vendor:stb/easy_font

Open eisbehr opened this issue 3 years ago • 3 comments

Context

compiler crash parsing vendor:stb/easy_font

  • Operating System & Odin Version: Odin: dev-2022-04:d10d5471

Failure Information (for bugs)

in stb_easy_font.odin

Steps to Reproduce

package main

import "core:fmt"
import "vendor:stb/easy_font"

main :: proc() {
	buffer: [9999]u8
	num_quads := easy_font.print(0,0, "Hello, Crash!", {}, buffer[:])
	fmt.println(num_quads)
}

Failure Logs

dies silently, null pointer deref is the final killer

eisbehr avatar Apr 03 '22 08:04 eisbehr

Pared it down further. This crashes the compiler in the same place. What happens is that in the original, len was a value that got replaced here by n := segs[i] & 7, but not everywhere.

The line where it's trying to fill the buffer tries to use the builtin len as a value. The parser doesn't catch this and it makes its way all the way to codegen.

package easy_font_crash

@(private)
hseg := [214]u8{}

draw_segs :: proc(x, y: f32, segs: []u8, vertical: bool, vbuf: []byte, offset: int) -> int {
    x, y, offset := x, y, offset
    for i in 0..<len(segs) {
        n := segs[i] & 7
        x += f32((segs[i]>>31) & 1)
        if n != 0 && offset+64 <= len(vbuf) {
            y0 := y + f32(segs[i]>>4)
            for j in 0..<4 {
                (^f32)(&vbuf[offset+0])^    = x  + ((vertical ? 1 : len) if j==1 || j==2 else 0)
                (^f32)(&vbuf[offset+4])^    = y0 + ((vertical ? len : 1) if     j >= 2   else 0)
                (^f32)(&vbuf[offset+8])^    = 0
                offset += 16
            }
        }
    }
    return offset
}

main :: proc() {
    buffer: [9999]u8
    _ = draw_segs(0, 0.000, hseg[1:][:4], false, buffer[:], 0)
}

Kelimion avatar Apr 03 '22 11:04 Kelimion

This appears to still be an issue, per @Kelimion's example above - still segfaults on my machine with latest odin.

z64 avatar Sep 03 '22 02:09 z64

This appears to still be an issue, per @Kelimion's example above - still segfaults on my machine with latest odin.

I can confirm that this particular snippet still crashes on the latest Odin (Linux). It doesn't on Windows somehow. However, if you wanted to use vendor:stb/easy_font, the code this was excised from was patched back in April and doesn't suffer this problem.

Kelimion avatar Sep 03 '22 12:09 Kelimion