cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

fixed missing exception handling in `MathLib::toBig{U}Number()`

Open firewave opened this issue 2 weeks ago • 4 comments

firewave avatar Dec 09 '25 21:12 firewave

Uncovered by adding @throws documentation to simplecpp: https://github.com/danmar/simplecpp/pull/600.

firewave avatar Dec 09 '25 21:12 firewave

That's how we treat exceptions.

can we discuss some builtin exceptions. If there is anything like std::out_of_range then I would prefer an internal error that points at the token. I don't see why we wouldn't want to get context if there is out_of_range exceptions.

In python a good reason you don't want to catch Exception is that it can mean anything including Ctrl+C and by catching Exception it's possible that Ctrl+C stops working.

I don't see that stuff will stop working in cppcheck because we catch std::exception.

danmar avatar Dec 14 '25 14:12 danmar

can we discuss some builtin exceptions. If there is anything like std::out_of_range then I would prefer an internal error that points at the token. I don't see why we wouldn't want to get context if there is out_of_range exceptions.

That's why I started documenting all of them in Cppcheck (PR coming soon). With the help of more tests and clang-tidy we can certainly improve some cases.

I don't see that stuff will stop working in cppcheck because we catch std::exception.

It is just cleaner.

firewave avatar Dec 14 '25 16:12 firewave

After using a fuzzer to trigger certain errors in another PR having a more narrow handling would allow you for undefined behavior but also unexpected errors. I also plan to do for for the important parts of the code. And after introducing noexcept in more places that would be easier as it would crash out.

That was actually the function in question and I did not produce another exception but the one we are throwing. I am also confident it might not happen since I had to fuzz a long time for some of our own exceptions to happen.

The MathLib functions are also great functions to fuzz.

I am not very excited.. but well chatgpt also told me that it's best practice to do it like this.

That would me actually make this reconsider as AI is usually wrong...

firewave avatar Dec 15 '25 19:12 firewave