[mapserver-dev] Mapserver assertion handling causing potential crashes

Sebastiaan Couwenberg sebastic at xs4all.nl
Sat Feb 12 11:56:20 PST 2022


On 2/12/22 20:25, Even Rouault wrote:
> Hopefully https://github.com/MapServer/MapServer/pull/6477 should fix that
> 
> to use or not to use assert(), and where, is one of the many debates for 
> which devs will have different opinions : 
> https://stackoverflow.com/questions/1081409/why-should-i-use-asserts . 
> I'd say assert() are supposed to be used for conditions you don't 
> anticipate to happen in practice and thus for which you don't have a 
> plan if they occur (a good reason is because you can't test it and thus 
> the error handling might be broken because untested). Of course practice 
> sometimes/often later contradicts your theories, as the impossible has a 
> trend to occur more often than you'd like :-)

assert() is unreliable as it is optimized out when using -DNDEBUG as set 
by CMAKE_BUILD_TYPE=Release.

It is also a PITA for reproducible builds as it uses __FILE__ thereby 
embedding the absolute path of the sources file in the binary.

Kind Regards,

Bas

-- 
  GPG Key ID: 4096R/6750F10AE88D4AF1
Fingerprint: 8182 DE41 7056 408D 6146  50D1 6750 F10A E88D 4AF1


More information about the MapServer-dev mailing list