Page MenuHomeFreeBSD

kvm_write: fix -Wcast-qual warning in pointer arithmetic argument
ClosedPublic

Authored by ngie on Mar 21 2017, 7:24 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 1 2024, 3:42 AM
Unknown Object (File)
Sep 1 2023, 7:12 AM
Unknown Object (File)
Aug 16 2023, 5:55 AM
Unknown Object (File)
Mar 26 2017, 7:01 PM
Unknown Object (File)
Mar 23 2017, 8:02 PM

Details

Summary

kvm_write: fix -Wcast-qual warning in pointer arithmetic argument

Cast buf to const char * when doing arithmetic operation to match
cp's type.

MFC after: 1 week
Sponsored by: Dell EMC Isilon

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Why not just cast buf (const void *) to const char * to match cp? This is not a situation where DECONST is actually needed.

In D10082#208481, @cem wrote:

Why not just cast buf (const void *) to const char * to match cp? This is not a situation where DECONST is actually needed.

Agreed.

In D10082#208481, @cem wrote:

Why not just cast buf (const void *) to const char * to match cp? This is not a situation where DECONST is actually needed.

Agreed.

clang 4.0.0 and gcc 6.3.0 both don't like that.

clang:

/usr/src/lib/libkvm/kvm.c:479:26: error: arithmetic on pointers to void is a GNU extension [-Werror,-Wpointer-arith]
        return ((const void*)cp - buf);
                ~~~~~~~~~~~~~~~ ^ ~~~
1 error generated.
*** Error code 1

gcc:

/usr/src/lib/libkvm/kvm.c: In function 'kvm_write':
/usr/src/lib/libkvm/kvm.c:479:26: error: pointer of type 'void *' used in subtraction [-Werror=pointer-arith]
  return ((const void*)cp - buf);
                          ^
cc1: all warnings being treated as errors
*** Error code 1

Stop.
make: stopped in /usr/src/lib/libkvm
In D10082#208485, @ngie wrote:

clang 4.0.0 and gcc 6.3.0 both don't like that.

I said cast buf, not cp.

Per cem/vangyzen: don't use __DECONST (overkill); use const char * cast instead to
match buf's type.

In D10082#208486, @cem wrote:
In D10082#208485, @ngie wrote:

clang 4.0.0 and gcc 6.3.0 both don't like that.

I said cast buf, not cp.

Derp. I missed that..

This revision is now accepted and ready to land.Mar 21 2017, 8:44 PM