rui314 / chibicc

A small C compiler
MIT License
9.69k stars 883 forks source link

Error in hashmap.c #135

Open sgraham opened 1 year ago

sgraham commented 1 year ago

I just discovered a bug in hashmap.c, which I found quite surprising as I'd been using it for quite a while and on some pretty large codebases!

I think the logic for TOMBSTONE is incorrect which can manifest with #undef when used by the preprocessor.

In particular:

I think the only easy solution is to never re-use TOMBSTONEs when doing a get_or_insert_entry().

I put the test data that discovered this at https://github.com/rui314/chibicc/pull/134 for reference (run ./chibicc -hashmap-test).

rui314 commented 1 year ago

Ah, I see the problem. That's indeed a bug, and it's hard to believe I haven't noticed before. Thank you for pointing it out!

fuhsnn commented 1 year ago

Actually, you have! #53

sgraham commented 1 year ago

Oops, I should have done some more searching first I guess!