Skip to content

Commit

Permalink
http: Avoid undefined behavior in va_arg conversion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daddesio committed Jul 6, 2022
1 parent cf218fb commit 5eb65b1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -3466,10 +3466,12 @@ static void *op_url_stream_vcreate_impl(OpusFileCallbacks *_cb,
pinfo=NULL;
*_pinfo=NULL;
for(;;){
ptrdiff_t request;
request=va_arg(_ap,char *)-(char *)NULL;
char *prequest;
intptr_t request;
prequest=va_arg(_ap,char *);
/*If we hit NULL, we're done processing options.*/
if(!request)break;
if(!prequest)break;
request=(intptr_t)prequest;
switch(request){
case OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST:{
skip_certificate_check=!!va_arg(_ap,opus_int32);
Expand Down

0 comments on commit 5eb65b1

Please sign in to comment.