Skip to content

[BUG] - segfault if the parser cannot find end marker of a comment #172

@rilysh

Description

@rilysh

Describe the bug
Hello,
In the following example, compiler parser segfaults if tokenRingBufferPeek() returns NULL.

U0 Main() {
   /*
}

A debug build (address sanitizer enabled), it points to cctrlTokenPeek(), which calls tokenRingBufferPeek() and it returns a NULL pointer. Functions that call ccttrlTokenPeek(), doesn't handle it's return value, and tries to dereference the NULL pointer.

I don't know why ring_buffer size is 0 (if /* doesn't end with */), I assume ring buffer is just keep popping and it doesn't see that we didn't end the comment line.

To Reproduce
Steps to reproduce the behavior:

  1. Compile the following example program.

Example Program

U0 Main() {
   /*
}

Expected behavior
No error at all.

Compiler version
hcc beta-v0.0.9
binary: /usr/local/hcc
commit-hash: fd2d410
arch: Linux x86_64
build: Debug

Desktop (please complete the following information):

  • OS: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions