WhiteBox-Systems / whitebox

A tool for showing software developers how their (C/C++) code behaves as they write it. (README and public issues)
https://whitebox.systems
17 stars 0 forks source link

Internal Error: DWARF - while using flexible array member #14

Closed fafok29 closed 2 years ago

fafok29 commented 2 years ago

What happened?

I have a struct with a flexible array member

typedef struct {
    uint64_t len;
    uint8_t buf[]; <<< 
} arr_uint8_t;

Whenever I try to analyze a function that has arr_uint8_t type, I get the following error:

Actual behavior:

Internal Error: DWARF Assertion failed in dwarf_val_constant - ../dwarf.h(1206): form_val.kind == DW_VAL_constant errno => 0: Success SIGTRAP hit in PID: 475436. Attach a debugger, hit 'x' to exit or 'c' to continue...

Expected behavior:

It should work with a flexible array member.

The same code but with zero length array doesn't produce any error

typedef struct {
    uint64_t len;
    uint8_t buf[0]; <<< 
} arr_uint8_t;

System/app details

WhiteBox version - 0.91.1 WhiteBox commit - a1735eaf840395556371fae40ad42c7c39b2d4a8 Assert level - 5 Debug info - false Kernel - Linux 5.15.0-46-generic OS - Ubuntu 22.04.1 LTS Architecture - x86-64 CPU name - Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz CPU count - 8 CPU MHz - RAM - 16G

How to reproduce the error

Steps to reproduce:

  1. rename algo1.txt to algo1.c
  2. Start Whitebox
  3. Open algo1.c in vim
  4. Place cursor over fill_in_array function
  5. call WhiteBoxConnect()
  6. Get the error log mentioned in the description

If you change arr_uint8_t to use a zero-length array instead of a flexible array member and it will not assert.

Does the error happen consistently with the above steps? Always

Minimal reproducible code example: algo1.txt

Crash/log attachments & additional info

Any additional information/comments:

I noticed that the value of errno from a log is random

errno => 0: Success
errno => 2: No such file or directory

and so on

azmr commented 2 years ago

I noticed that the value of errno from a log is random

Yeah it doesn't necessarily correspond to the source of the assertion failing, but it's occasionally useful as a debug prompt.

azmr commented 2 years ago

Fixed in 36b00c3