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

http: Avoid undefined behavior in va_arg conversion #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

daddesio
Copy link

@daddesio daddesio commented Jul 6, 2022

Compiling under Clang 13 with -Wextra resulted in the following warning:

src/http.c:3470:31: warning: performing pointer subtraction with a null pointer has undefined behavior [-Wnull-pointer-subtraction]
    request=va_arg(_ap,char *)-(char *)NULL;

It seems subtracting a null pointer is undefined behavior, which we can avoid by casting to intptr_t instead.

Request macros (e.g. OP_GET_SERVER_INFO) already do a simple cast ((char*)_request) rather than addition with null pointer (_request+(char*)NULL) so nothing needs to be changed on that end.

Subtracting a null pointer is undefined behavior according to
Clang 13 (-Wnull-pointer-subtraction). Avoid this by casting to
intptr_t instead.

Request macros (e.g. OP_GET_SERVER_INFO) already do a simple cast
`((char*)_request)` rather than addition with null pointer
`(_request+(char*)NULL)` so nothing needs to be changed on that end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant