Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NULL pointer checks & compiler warnings #3105

Open
marcstern opened this issue Mar 6, 2024 · 1 comment
Open

NULL pointer checks & compiler warnings #3105

marcstern opened this issue Mar 6, 2024 · 1 comment
Assignees
Labels
2.x Related to ModSecurity version 2.x help wanted

Comments

@marcstern
Copy link
Contributor

I'm rewriting my PR for NULL pointer checks.
In most places, it's as basic as adding "if (ptr != NULL)" but I tried to optimize it a bit.
There are some cases where a pointer cannot be NULL; it just doesn't make sense. Such an example is the "msc" variable used at a lot of place. It's initialized to non-NULL and checked, so it cannot be NULL (except in msc_tee.c, but that's another discussion). So, there's no need to check it in every single function. However, we'll get (depending on the compiler) warnings about null pointer dereference. Also, when doing a code review, it's not clear if it can never be null or if the developers forgot to check it.
I found an almost neat solution: add "assert(msc != NULL)" in every function. It clarifies the code and suppresses the compiler warning ... at least in debug mode because assert() is defined to nothing in NDEBUG mode so the check is not executed - good from a performance point of view) and the compiler doesn't see that we check for nulliness.
Does anybody see a variation that would avoid the compiler warning without adding a real check at run-time?

@marcstern marcstern added the 2.x Related to ModSecurity version 2.x label Mar 6, 2024
@marcstern marcstern self-assigned this Mar 6, 2024
@gberkes
Copy link

gberkes commented Mar 6, 2024

FYI

#3104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Related to ModSecurity version 2.x help wanted
Projects
None yet
Development

No branches or pull requests

2 participants