Skip to content

Commit

Permalink
fix clang diagnostic cast-qual (GPSBabel#967)
Browse files Browse the repository at this point in the history
* fix cast-qual clang diagnostic

* use const_cast to cheat

* decay an array with casts.

the assembly code for gpsusbwin and gpsusbcommon does match the master branch.

* explicitly use const with auto*
  • Loading branch information
tsteven4 authored Dec 31, 2022
1 parent e9786f1 commit 1a38301
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 34 deletions.
12 changes: 6 additions & 6 deletions exif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16
if (size_increase > 0) {
qba.append(size_increase, 0);
}
qba.replace(index, count, (char*) data, count);
qba.replace(index, count, static_cast<const char*>(data), count);
tag->data[0] = qba;
} else {
// we haven't coded for insertion of multiple values (except for BYTE_TYPE above).
Expand All @@ -1041,17 +1041,17 @@ ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16
case EXIF_TYPE_SHORT:
case EXIF_TYPE_SSHORT:
tag->grow<uint16_t>(index + count);
tag->data[index] = *(uint16_t*)data;
tag->data[index] = *static_cast<const uint16_t*>(data);
break;
case EXIF_TYPE_LONG:
case EXIF_TYPE_SLONG:
case EXIF_TYPE_IFD:
tag->grow<uint32_t>(index + count);
tag->data[index] = *(uint32_t*)data;
tag->data[index] = *static_cast<const uint32_t*>(data);
break;
case EXIF_TYPE_RAT:
case EXIF_TYPE_SRAT: {
double val = *(double*)data;
double val = *static_cast<const double*>(data);

if ((val < 0.0) && (type == EXIF_TYPE_RAT)) {
fatal(MYNAME ": A negative value cannot be stored as type RATIONAL.");
Expand All @@ -1065,11 +1065,11 @@ ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16
break;
case EXIF_TYPE_FLOAT:
tag->grow<float>(index + count);
tag->data[index] = *(float*)data;
tag->data[index] = *static_cast<const float*>(data);
break;
case EXIF_TYPE_DOUBLE:
tag->grow<double>(index + count);
tag->data[index] = *(double*)data;
tag->data[index] = *static_cast<const double*>(data);
break;
default:
fatal(MYNAME ": Unknown data type %u!\n", type);
Expand Down
6 changes: 2 additions & 4 deletions gui/gpx.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ class GpxRoute: public GpxItem
prevPt = thisPt;
}
}
auto* dptr = (double*)(&cachedLength); // big cheat
*dptr = dist;
*const_cast<double*>(&cachedLength) = dist; // big cheat
return cachedLength;
}

Expand Down Expand Up @@ -355,8 +354,7 @@ class GpxTrack: public GpxItem
}
}
}
auto* dptr = (double*)(&cachedLength); // big cheat
*dptr = dist;
*const_cast<double*>(&cachedLength) = dist; // big cheat
return cachedLength;
}

Expand Down
4 changes: 2 additions & 2 deletions jeeps/gpsusbcommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ gusb_cmd_get(garmin_usb_packet* ibuf, size_t sz)
int
gusb_cmd_send(const garmin_usb_packet* opkt, size_t sz)
{
auto* obuf = (unsigned char*) &opkt->dbuf;
const auto* obuf = opkt->dbuf;
const char* m2;

unsigned int rv = gusb_llops->llop_send(opkt, sz);
Expand Down Expand Up @@ -215,7 +215,7 @@ gusb_id_unit(garmin_unit_info_t* gu)
garmin_usb_packet iresp;
int i;

gusb_cmd_send((garmin_usb_packet*)oid, sizeof(oid));
gusb_cmd_send(reinterpret_cast<const garmin_usb_packet*>(oid), sizeof(oid));

for (i = 0; i < 25; i++) {
iresp.gusb_pkt.type = 0;
Expand Down
8 changes: 4 additions & 4 deletions jeeps/gpsusbwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int
gusb_win_send(const garmin_usb_packet* opkt, size_t sz)
{
DWORD rsz;
unsigned char* obuf = (unsigned char*) &opkt->dbuf;
const auto* obuf = opkt->dbuf;

/* The spec warns us about making writes an exact multiple
* of the packet size, but isn't clear whether we can issue
Expand Down Expand Up @@ -236,7 +236,7 @@ gusb_init(const char* pname, gpsdevh** dh)
}
}

hdevinfo = SetupDiGetClassDevs((GUID*) &GARMIN_GUID, NULL, NULL,
hdevinfo = SetupDiGetClassDevs(&GARMIN_GUID, NULL, NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

if (hdevinfo == INVALID_HANDLE_VALUE) {
Expand All @@ -249,7 +249,7 @@ gusb_init(const char* pname, gpsdevh** dh)

if (req_unit_number >= 0) {
if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL,
(GUID*) &GARMIN_GUID,
&GARMIN_GUID,
req_unit_number, &devinterface)) {
// If there were zero matches, we may be trying to talk to a "GPX Mode" device.

Expand Down Expand Up @@ -277,7 +277,7 @@ gusb_init(const char* pname, gpsdevh** dh)
*/
for (match = 0;; match++) {
if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL,
(GUID*) &GARMIN_GUID, match, &devinterface)) {
&GARMIN_GUID, match, &devinterface)) {
if (GetLastError() == ERROR_NO_MORE_ITEMS) {

break;
Expand Down
16 changes: 5 additions & 11 deletions jeeps/jgpsutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ US GPS_Util_Get_Short(const UC* s)

void GPS_Util_Put_Short(UC* s, const US v)
{
UC* p;

p = (UC*)&v;
const auto* p = reinterpret_cast<const UC*>(&v);

if (!GPS_Little) {
*s++ = *(p+1);
Expand Down Expand Up @@ -163,10 +161,9 @@ double GPS_Util_Get_Double(const UC* s)

void GPS_Util_Put_Double(UC* s, const double v)
{
UC* p;
int32 i;

p = (UC*)&v;
const auto* p = reinterpret_cast<const UC*>(&v);

if (!GPS_Little)
for (i=sizeof(double)-1; i>-1; --i) {
Expand Down Expand Up @@ -225,10 +222,9 @@ int32 GPS_Util_Get_Int(const UC* s)

void GPS_Util_Put_Int(UC* s, const int32 v)
{
UC* p;
int32 i;

p = (UC*)&v;
const auto* p = reinterpret_cast<const UC*>(&v);

if (!GPS_Little)
for (i=sizeof(int32)-1; i>-1; --i) {
Expand Down Expand Up @@ -286,10 +282,9 @@ uint32 GPS_Util_Get_Uint(const UC* s)

void GPS_Util_Put_Uint(UC* s, const uint32 v)
{
UC* p;
int32 i;

p = (UC*)&v;
const auto* p = reinterpret_cast<const UC*>(&v);

if (!GPS_Little)
for (i=sizeof(uint32)-1; i>-1; --i) {
Expand Down Expand Up @@ -347,10 +342,9 @@ float GPS_Util_Get_Float(const UC* s)

void GPS_Util_Put_Float(UC* s, const float v)
{
UC* p;
int32 i;

p = (UC*)&v;
const auto* p = reinterpret_cast<const UC*>(&v);

if (!GPS_Little)
for (i=sizeof(float)-1; i>-1; --i) {
Expand Down
2 changes: 1 addition & 1 deletion navilink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ decode_waypoint(const unsigned char* buffer)
auto* waypt = new Waypoint;

decode_position(buffer + 12, waypt);
waypt->shortname = (char*) buffer + 4;
waypt->shortname = reinterpret_cast<const char*>(buffer) + 4;
waypt->icon_descr = icon_table[buffer[28]];
waypt->SetCreationTime(decode_datetime(buffer + 22));

Expand Down
2 changes: 1 addition & 1 deletion skytraq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ SkytraqBase::process_data_sector(struct read_state* pst, const uint8_t* buf, int
int plen, ilen;

for (plen = 0; plen < len && buf[plen] != 0xFF; plen += ilen) {
ilen = process_data_item(pst, (item_frame*)&buf[plen], len-plen);
ilen = process_data_item(pst, reinterpret_cast<const item_frame*>(&buf[plen]), len-plen);
if (ilen <= 0) {
fatal(MYNAME ": Error %i while processing data item #%i (starts at %i)\n",
ilen, pst->tpn, plen);
Expand Down
4 changes: 2 additions & 2 deletions util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ endian_read_double(const void* ptr, int read_le)
p = ptr;
} else {
for (int i = 0; i < 8; i++) {
r[i] = ((char*)ptr)[7-i];
r[i] = static_cast<const char*>(ptr)[7-i];
}
p = r;
}
Expand All @@ -794,7 +794,7 @@ endian_read_float(const void* ptr, int read_le)
p = ptr;
} else {
for (int i = 0; i < 4; i++) {
r[i] = ((char*)ptr)[3-i];
r[i] = static_cast<const char*>(ptr)[3-i];
}
p = r;
}
Expand Down
4 changes: 2 additions & 2 deletions util_crc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ unsigned long
get_crc32(const void* data, int datalen)
{
unsigned long crc = 0xFFFFFFFF;
const unsigned char* cp = (unsigned char*)data;
const unsigned char* cp = static_cast<const unsigned char*>(data);

while (cp < ((unsigned char*)data + datalen)) {
while (cp < (static_cast<const unsigned char*>(data) + datalen)) {
crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ *cp) &0xFF];
cp++;
}
Expand Down
2 changes: 1 addition & 1 deletion wbt-200.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static void buf_extend(struct buf_head* h, size_t amt)

static void buf_update_checksum(struct buf_head* h, const void* data, size_t len)
{
auto* cp = (unsigned char*) data;
auto* cp = static_cast<const unsigned char*>(data);

db(4, "Updating checksum with %p, %zu, before: %02x ",
data, len, h->checksum);
Expand Down

0 comments on commit 1a38301

Please sign in to comment.