Check NULL pointers or not...

Matthias St. Pierre Matthias.St.Pierre at ncp-e.com
Fri Nov 29 10:32:06 UTC 2019



On 29.11.19 11:29, Matthias St. Pierre wrote:
>
>
> On 29.11.19 10:22, Matt Caswell wrote:
>>
>>      if (!ossl_assert(ptr != NULL)) {
>>          ERR_raise(ERR_LIB_WHATEVER, ERR_R_PASSED_NULL_PARAMETER);
>>          return 0;
>>      }
>>
>
> I still dislike the odd way in which the assertion needs to be formulated,
> with the double negation. With the `ossl_is_null()` macro, which I proposed
> in #7218, the same condition would read
>
>     if (ossl_is_null(ptr)) {
>         ERR_raise(ERR_LIB_WHATEVER, ERR_R_PASSED_NULL_PARAMETER);
>         return 0;
>     }
>
>
> Isn't that much better readable and easier to understand?
>
>
> For more examples like that, see the change set
>
> https://github.com/openssl/openssl/pull/7218/files
>
>
> Matthias
>
>


Moreover, in the debug build you get the error message  "Invalid NULL pointer:" instead of a generic "Assertion Failed:"

https://github.com/openssl/openssl/pull/7218/files#diff-6e9d962dc8c30948fdf827ad471ec11dR41-R44





More information about the openssl-project mailing list