Enable -Wcast-qual compiler warning

This commit is contained in:
Christian Göttsche 2020-10-04 14:30:35 +02:00 committed by cgzones
parent ad3acfc847
commit db472075a4
9 changed files with 56 additions and 33 deletions

View File

@ -40,18 +40,18 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke
} }
if (keys && events) { if (keys && events) {
this->staticData = false; this->staticData = false;
this->keys = xCalloc(15, sizeof(char*)); this->keys.keys = xCalloc(15, sizeof(char*));
this->events = xCalloc(15, sizeof(int)); this->events = xCalloc(15, sizeof(int));
int i = 0; int i = 0;
while (i < 15 && functions[i]) { while (i < 15 && functions[i]) {
this->keys[i] = xStrdup(keys[i]); this->keys.keys[i] = xStrdup(keys[i]);
this->events[i] = events[i]; this->events[i] = events[i];
i++; i++;
} }
this->size = i; this->size = i;
} else { } else {
this->staticData = true; this->staticData = true;
this->keys = (char**) FunctionBar_FKeys; this->keys.constKeys = FunctionBar_FKeys;
this->events = FunctionBar_FEvents; this->events = FunctionBar_FEvents;
this->size = 10; this->size = 10;
} }
@ -65,9 +65,9 @@ void FunctionBar_delete(FunctionBar* this) {
free(this->functions); free(this->functions);
if (!this->staticData) { if (!this->staticData) {
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
free(this->keys[i]); free(this->keys.keys[i]);
} }
free(this->keys); free(this->keys.keys);
free(this->events); free(this->events);
} }
free(this); free(this);
@ -93,8 +93,8 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
int x = 0; int x = 0;
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
attrset(CRT_colors[FUNCTION_KEY]); attrset(CRT_colors[FUNCTION_KEY]);
mvaddstr(LINES-1, x, this->keys[i]); mvaddstr(LINES-1, x, this->keys.constKeys[i]);
x += strlen(this->keys[i]); x += strlen(this->keys.constKeys[i]);
attrset(CRT_colors[FUNCTION_BAR]); attrset(CRT_colors[FUNCTION_BAR]);
mvaddstr(LINES-1, x, this->functions[i]); mvaddstr(LINES-1, x, this->functions[i]);
x += strlen(this->functions[i]); x += strlen(this->functions[i]);
@ -113,7 +113,7 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) { int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {
int x = 0; int x = 0;
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
x += strlen(this->keys[i]); x += strlen(this->keys.constKeys[i]);
x += strlen(this->functions[i]); x += strlen(this->functions[i]);
if (pos < x) { if (pos < x) {
return this->events[i]; return this->events[i];

View File

@ -12,7 +12,10 @@ in the source distribution for its full text.
typedef struct FunctionBar_ { typedef struct FunctionBar_ {
int size; int size;
char** functions; char** functions;
char** keys; union {
char** keys;
const char* const* constKeys;
} keys;
int* events; int* events;
bool staticData; bool staticData;
} FunctionBar; } FunctionBar;

View File

@ -33,4 +33,20 @@
#endif /* __GNUC__ */ #endif /* __GNUC__ */
// ignore casts discarding const specifier, e.g.
// const char [] -> char * / void *
// const char *[2]' -> char *const *
#ifdef __clang__
#define IGNORE_WCASTQUAL_BEGIN _Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wcast-qual\"")
#define IGNORE_WCASTQUAL_END _Pragma("clang diagnostic pop")
#elif defined(__GNUC__)
#define IGNORE_WCASTQUAL_BEGIN _Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
#define IGNORE_WCASTQUAL_END _Pragma("GCC diagnostic pop")
#else
#define IGNORE_WCASTQUAL_BEGIN
#define IGNORE_WCASTQUAL_END
#endif
#endif #endif

View File

@ -296,6 +296,7 @@ fi
AM_CFLAGS="\ AM_CFLAGS="\
-Wall\ -Wall\
-Wcast-align\ -Wcast-align\
-Wcast-qual\
-Wextra\ -Wextra\
-Wfloat-equal\ -Wfloat-equal\
-Wmissing-format-attribute\ -Wmissing-format-attribute\

View File

@ -108,14 +108,14 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField
} }
long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { long DragonFlyBSDProcess_compare(const void* v1, const void* v2) {
DragonFlyBSDProcess *p1, *p2; const DragonFlyBSDProcess *p1, *p2;
Settings *settings = ((Process*)v1)->settings; const Settings *settings = ((const Process*)v1)->settings;
if (settings->direction == 1) { if (settings->direction == 1) {
p1 = (DragonFlyBSDProcess*)v1; p1 = (const DragonFlyBSDProcess*)v1;
p2 = (DragonFlyBSDProcess*)v2; p2 = (const DragonFlyBSDProcess*)v2;
} else { } else {
p2 = (DragonFlyBSDProcess*)v1; p2 = (const DragonFlyBSDProcess*)v1;
p1 = (DragonFlyBSDProcess*)v2; p1 = (const DragonFlyBSDProcess*)v2;
} }
switch ((int) settings->sortKey) { switch ((int) settings->sortKey) {
// add Platform-specific fields here // add Platform-specific fields here

View File

@ -107,14 +107,14 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel
} }
long FreeBSDProcess_compare(const void* v1, const void* v2) { long FreeBSDProcess_compare(const void* v1, const void* v2) {
FreeBSDProcess *p1, *p2; const FreeBSDProcess *p1, *p2;
Settings *settings = ((Process*)v1)->settings; const Settings *settings = ((const Process*)v1)->settings;
if (settings->direction == 1) { if (settings->direction == 1) {
p1 = (FreeBSDProcess*)v1; p1 = (const FreeBSDProcess*)v1;
p2 = (FreeBSDProcess*)v2; p2 = (const FreeBSDProcess*)v2;
} else { } else {
p2 = (FreeBSDProcess*)v1; p2 = (const FreeBSDProcess*)v1;
p1 = (FreeBSDProcess*)v2; p1 = (const FreeBSDProcess*)v2;
} }
switch ((int) settings->sortKey) { switch ((int) settings->sortKey) {
// add FreeBSD-specific fields here // add FreeBSD-specific fields here

View File

@ -5,6 +5,7 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Macros.h"
#include "ProcessList.h" #include "ProcessList.h"
#include "FreeBSDProcessList.h" #include "FreeBSDProcessList.h"
#include "FreeBSDProcess.h" #include "FreeBSDProcess.h"
@ -338,6 +339,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) {
if (kproc->ki_jid != 0 ){ if (kproc->ki_jid != 0 ){
memset(jnamebuf, 0, sizeof(jnamebuf)); memset(jnamebuf, 0, sizeof(jnamebuf));
IGNORE_WCASTQUAL_BEGIN
*(const void **)&jiov[0].iov_base = "jid"; *(const void **)&jiov[0].iov_base = "jid";
jiov[0].iov_len = sizeof("jid"); jiov[0].iov_len = sizeof("jid");
jiov[1].iov_base = &kproc->ki_jid; jiov[1].iov_base = &kproc->ki_jid;
@ -350,6 +352,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) {
jiov[4].iov_len = sizeof("errmsg"); jiov[4].iov_len = sizeof("errmsg");
jiov[5].iov_base = jail_errmsg; jiov[5].iov_base = jail_errmsg;
jiov[5].iov_len = JAIL_ERRMSGLEN; jiov[5].iov_len = JAIL_ERRMSGLEN;
IGNORE_WCASTQUAL_END
jail_errmsg[0] = 0; jail_errmsg[0] = 0;
jid = jail_get(jiov, 6, 0); jid = jail_get(jiov, 6, 0);
if (jid < 0) { if (jid < 0) {

View File

@ -193,14 +193,14 @@ void OpenBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel
} }
long OpenBSDProcess_compare(const void* v1, const void* v2) { long OpenBSDProcess_compare(const void* v1, const void* v2) {
OpenBSDProcess *p1, *p2; const OpenBSDProcess *p1, *p2;
Settings *settings = ((Process*)v1)->settings; const Settings *settings = ((const Process*)v1)->settings;
if (settings->direction == 1) { if (settings->direction == 1) {
p1 = (OpenBSDProcess*)v1; p1 = (const OpenBSDProcess*)v1;
p2 = (OpenBSDProcess*)v2; p2 = (const OpenBSDProcess*)v2;
} else { } else {
p2 = (OpenBSDProcess*)v1; p2 = (const OpenBSDProcess*)v1;
p1 = (OpenBSDProcess*)v2; p1 = (const OpenBSDProcess*)v2;
} }
switch (settings->sortKey) { switch (settings->sortKey) {
// add OpenBSD-specific fields here // add OpenBSD-specific fields here

View File

@ -117,14 +117,14 @@ void SolarisProcess_writeField(Process* this, RichString* str, ProcessField fiel
} }
long SolarisProcess_compare(const void* v1, const void* v2) { long SolarisProcess_compare(const void* v1, const void* v2) {
SolarisProcess *p1, *p2; const SolarisProcess *p1, *p2;
Settings* settings = ((Process*)v1)->settings; const Settings* settings = ((const Process*)v1)->settings;
if (settings->direction == 1) { if (settings->direction == 1) {
p1 = (SolarisProcess*)v1; p1 = (const SolarisProcess*)v1;
p2 = (SolarisProcess*)v2; p2 = (const SolarisProcess*)v2;
} else { } else {
p2 = (SolarisProcess*)v1; p2 = (const SolarisProcess*)v1;
p1 = (SolarisProcess*)v2; p1 = (const SolarisProcess*)v2;
} }
switch ((int) settings->sortKey) { switch ((int) settings->sortKey) {
case ZONEID: case ZONEID: