From 5eb65b1305fad2d9cc635a34808e222dd6663595 Mon Sep 17 00:00:00 2001 From: Andrew D'Addesio Date: Tue, 5 Jul 2022 19:52:52 -0500 Subject: [PATCH] http: Avoid undefined behavior in va_arg conversion 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. --- src/http.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/http.c b/src/http.c index bd08562..437581f 100644 --- a/src/http.c +++ b/src/http.c @@ -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);