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
F154976633: D10082.id26516.diff
Thu, Apr 30, 10:22 AM
F154929488: D10082.id.diff
Thu, Apr 30, 3:13 AM
Unknown Object (File)
Tue, Apr 28, 2:19 AM
Unknown Object (File)
Mon, Apr 27, 12:56 PM
Unknown Object (File)
Fri, Apr 24, 6:35 AM
Unknown Object (File)
Fri, Apr 24, 3:44 AM
Unknown Object (File)
Tue, Apr 21, 2:30 AM
Unknown Object (File)
Tue, Apr 21, 2:25 AM

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

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