rui314 / 9cc

A Small C Compiler
MIT License
1.83k stars 155 forks source link

Completion of error handling #2

Closed elfring closed 6 years ago

elfring commented 6 years ago

Would you like to add more error handling for return values from functions like the following?

rui314 commented 6 years ago

Thank you for the suggestion, but I intentionally omit error checking for the memory exhaustion situation, because we cannot really handle such situation. If the memory is so tight that malloc can fail, the entire system becomes unstable (e.g. the kernel chooses a process to kill to free up some amount of memory). So, your program becomes unstable even if you correctly handle such situation. 9cc doesn't handle malloc failure, so it crashes with SEGV when malloc fails. That's fine. In practice, that won't cause any trouble.

I'm trying not to make 9cc bullet-safe. Rather, I trust people don't shoot us. That design choice greatly simplifies its code, as you probably can see.

elfring commented 6 years ago

How do you think about to improve static source code analysis also for this software?


rui314 commented 6 years ago

You probably should unlearn these kind of "best practices". I'm trying to keep my code as simple as I can so that you don't really need any higher-level metaprogramming.

elfring commented 6 years ago

How do you think about to avoid that this software can depend on undefined behaviour?