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

Build warnings with clang 6 #2466

Closed
rikardfalkeborn opened this issue Apr 6, 2018 · 1 comment
Closed

Build warnings with clang 6 #2466

rikardfalkeborn opened this issue Apr 6, 2018 · 1 comment

Comments

@rikardfalkeborn
Copy link
Contributor

I did this

Built curl with clang 6.0.0.

$ ./buildconf
$ ./configure --enable-debug --enable-warnings --enable-werror CC=clang
$ make check
$ clang --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

I expected the following

Successful build. Instead, I got this:

unit1309.c:91:24: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]
    nodes[i].payload = CURLX_INTEGER_TO_POINTER_CAST(payload);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../lib/warnless.h:32:26: note: expanded from macro 'CURLX_INTEGER_TO_POINTER_CAST'                                                                                
  ((void *)((char *)NULL + (i)))
            ~~~~~~~~~~~~ ^
unit1309.c:125:34: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]              
      nodes[i * 3 + j].payload = CURLX_INTEGER_TO_POINTER_CAST(payload);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../lib/warnless.h:32:26: note: expanded from macro 'CURLX_INTEGER_TO_POINTER_CAST'                                                                                
  ((void *)((char *)NULL + (i)))

Looks like this warning has been improved/changed in clang 6. From http://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html#improvements-to-clang-s-diagnostics

-Wnull-pointer-arithmetic now warns about performing pointer arithmetic on a null pointer. Such pointer arithmetic has an undefined behavior if the offset is nonzero. It also now warns about arithmetic on a null pointer treated as a cast from integer to pointer (GNU extension).

curl/libcurl version

$ git rev-parse HEAD
dd03e8c281582af454fabfb4a666a5b232d518aa
$ ./src/curl -V 
curl 7.60.0-DEV (x86_64-pc-linux-gnu) libcurl/7.60.0-DEV OpenSSL/1.1.0h zlib/1.2.11 brotli/1.0.2 libidn2/2.0.4 libpsl/0.20.1 (+libidn2/2.0.4) nghttp2/1.31.0 librtmp/2.3
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS Debug TrackMemory IDN IPv6 Largefile NTLM NTLM_WB SSL libz brotli TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

operating system

Linux (Arch Linux)

bagder added a commit that referenced this issue Apr 7, 2018
unit1309.c:91:24: error: arithmetic on a null pointer treated as a cast
from integer to pointer is a GNU extension

Reported-by: Rikard Falkeborn

Fixes #2466
@rikardfalkeborn
Copy link
Contributor Author

#2468 fixes the reported warnings. However, if I enable gnutls (--with-gnutls) I get the same warning in the last place CURLX_INTEGER_TO_POINTER_CAST is used:

  CC       vtls/libcurl_la-gtls.lo
vtls/gtls.c:851:21: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]
    transport_ptr = CURLX_INTEGER_TO_POINTER_CAST(conn->sock[sockindex]);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/warnless.h:32:26: note: expanded from macro 'CURLX_INTEGER_TO_POINTER_CAST'                                                                                   
  ((void *)((char *)NULL + (i)))
            ~~~~~~~~~~~~ ^
1 error generated.

Note that there is not warning from CURLX_POINTER_TO_INTEGER_CAST.

bagder added a commit that referenced this issue Apr 7, 2018
unit1309 and vtls/gtls: error: arithmetic on a null pointer treated as a
cast from integer to pointer is a GNU extension

Reported-by: Rikard Falkeborn

Fixes #2466
@bagder bagder closed this as completed in dc1b6c5 Apr 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants