vendredi 31 août 2018

Does assert() act as the identity function in release mode?

This library uses assert() as if it's the identity function in release mode (when NDEBUG is defined). The problem is that some important code is wrapped with assert(), and my tests fired when executed in release mode, because these important parts were not called. An example of this can be found here, where the random bytes generator will not generate anything and will cause an infinite loop.

Personal anecdote: I dislike assert() and I personally don't use it because of these ambiguity issues. I heard of many projects that had serious bugs because of it, most recently EOS, when their unit tests didn't detect some out of range arrays because NDEBUG was defined in release mode and it didn't fire. The documentation doesn't seem to be clear on this point. Does assert() act as the identity at all?

This library (libbtc) seems to be used widely, and I don't understand why the developer did this. Is this a horrible mistake and I should fork and remove all these asserts? Or is this some C thing that's not C++ compatible? Could someone please explain the correct course of action here?

I use clang 6.

Aucun commentaire:

Enregistrer un commentaire