From 6b117694489f523cfd7dce926b5b3ab5472095ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:26:10 +0200 Subject: Avoid conversion warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit linux/Platform.c:47:90: error: implicit conversion from ‘enum LinuxProcessFields’ to ‘enum ProcessFields’ [-Werror=enum-conversion] 47 | ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; | --- linux/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Platform.c b/linux/Platform.c index 1725eea9..10311a2d 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -44,7 +44,7 @@ in the source distribution for its full text. #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif -ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; +ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; //static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 }; -- cgit v1.2.3 From 21fb56e1e297c5ea85d685eb3809f1052d6f9a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:31:50 +0200 Subject: Avoid string overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enough memory is allocated. Header.c: In function ‘Header_readMeterName’: Header.c:157:4: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 157 | strncpy(name, Meter_name(meter), nameLen); | ^ Header.c:154:18: note: length computed here 154 | int nameLen = strlen(Meter_name(meter)); | ^ --- Header.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Header.c b/Header.c index a4075d22..c8cfaabc 100644 --- a/Header.c +++ b/Header.c @@ -154,7 +154,7 @@ char* Header_readMeterName(Header* this, int i, int column) { int nameLen = strlen(Meter_name(meter)); int len = nameLen + 100; char* name = xMalloc(len); - strncpy(name, Meter_name(meter), nameLen); + memcpy(name, Meter_name(meter), nameLen); name[nameLen] = '\0'; if (meter->param) xSnprintf(name + nameLen, len - nameLen, "(%d)", meter->param); -- cgit v1.2.3 From 7457bfe9f319d939f9840a79703991d4b7beaaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:34:28 +0200 Subject: Avoid string overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use xStrdup instead of xMallow and strncpy StringUtils.c: In function ‘String_split’: StringUtils.c:86:7: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 86 | strncpy(token, s, size + 1); | ^ StringUtils.c:84:18: note: length computed here 84 | int size = strlen(s); | ^ --- StringUtils.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/StringUtils.c b/StringUtils.c index 0ac54b12..d7058a28 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -81,10 +81,7 @@ char** String_split(const char* s, char sep, int* n) { s += size + 1; } if (s[0] != '\0') { - int size = strlen(s); - char* token = xMalloc(size + 1); - strncpy(token, s, size + 1); - out[ctr] = token; + out[ctr] = xStrdup(s); ctr++; } out = xRealloc(out, sizeof(char*) * (ctr + 1)); -- cgit v1.2.3 From 11f558f93421a42aa29e0de7e50e670facfb5bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:58:14 +0200 Subject: Avoid discarding const qualifiers --- InfoScreen.c | 4 ++-- InfoScreen.h | 4 ++-- Process.c | 2 +- Process.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/InfoScreen.c b/InfoScreen.c index 0b919932..93120006 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -56,7 +56,7 @@ static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"}; static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; -InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader) { +InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader) { this->process = process; if (!bar) { bar = FunctionBar_new(InfoScreenFunctions, InfoScreenKeys, InfoScreenEvents); @@ -75,7 +75,7 @@ InfoScreen* InfoScreen_done(InfoScreen* this) { return this; } -void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) { +void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) { va_list ap; va_start(ap, fmt); attrset(CRT_colors[METER_TEXT]); diff --git a/InfoScreen.h b/InfoScreen.h index b9387cda..e5d6bb67 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -38,11 +38,11 @@ struct InfoScreen_ { Vector* lines; }; -extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader); +extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader); extern InfoScreen* InfoScreen_done(InfoScreen* this); -extern void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...); +extern void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...); extern void InfoScreen_addLine(InfoScreen* this, const char* line); diff --git a/Process.c b/Process.c index 7bcaf19a..6a0d56b9 100644 --- a/Process.c +++ b/Process.c @@ -85,7 +85,7 @@ typedef enum ProcessFields { typedef struct ProcessPidColumn_ { int id; - char* label; + const char* label; } ProcessPidColumn; typedef struct Process_ { diff --git a/Process.h b/Process.h index 56a4dba1..3085f164 100644 --- a/Process.h +++ b/Process.h @@ -61,7 +61,7 @@ typedef enum ProcessFields { typedef struct ProcessPidColumn_ { int id; - char* label; + const char* label; } ProcessPidColumn; typedef struct Process_ { -- cgit v1.2.3 From 1130ad8b739be8f10bcf49a3928264cdf5566258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 23 Aug 2020 12:48:08 +0200 Subject: MakeHeader.py.in: remove executable bit --- scripts/MakeHeader.py.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 scripts/MakeHeader.py.in diff --git a/scripts/MakeHeader.py.in b/scripts/MakeHeader.py.in old mode 100755 new mode 100644 -- cgit v1.2.3 From b4ceb83d760e7f58eed7d6785c81bece01c29662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 23 Aug 2020 12:54:39 +0200 Subject: MakeHeader.py.in: remove unused import --- scripts/MakeHeader.py.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/MakeHeader.py.in b/scripts/MakeHeader.py.in index 9da6685a..8a688778 100644 --- a/scripts/MakeHeader.py.in +++ b/scripts/MakeHeader.py.in @@ -1,5 +1,5 @@ #!/usr/bin/env @PYTHON@ -import os, sys, string, io +import os, sys, io try: from StringIO import StringIO except ImportError: -- cgit v1.2.3 From 4e2b9f09654ff31602eaa294e0ac77b2f82ea3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 25 Aug 2020 12:01:54 +0200 Subject: Avoid shadowing warnings --- Action.c | 14 +++++++------- linux/Battery.c | 26 +++++++++++++------------- linux/LinuxProcessList.c | 6 +++--- linux/Platform.c | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Action.c b/Action.c index 64573938..a7747f52 100644 --- a/Action.c +++ b/Action.c @@ -316,17 +316,17 @@ static Htop_Reaction actionSetAffinity(State* st) { Process* p = (Process*) Panel_getSelected(panel); if (!p) return HTOP_OK; - Affinity* affinity = Affinity_get(p, st->pl); - if (!affinity) return HTOP_OK; - Panel* affinityPanel = AffinityPanel_new(st->pl, affinity); - Affinity_delete(affinity); + Affinity* affinity1 = Affinity_get(p, st->pl); + if (!affinity1) return HTOP_OK; + Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1); + Affinity_delete(affinity1); void* set = Action_pickFromVector(st, affinityPanel, 15, true); if (set) { - Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL); + Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity2 }, NULL); if (!ok) beep(); - Affinity_delete(affinity); + Affinity_delete(affinity2); } Panel_delete((Object*)affinityPanel); #endif diff --git a/linux/Battery.c b/linux/Battery.c index 7a1c8163..4014a500 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -64,7 +64,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short } char* line = NULL; - for (unsigned short int i = 0; i < lineNum; i++) { + for (unsigned short int j = 0; j < lineNum; j++) { free(line); line = String_readLine(file); if (!line) break; @@ -194,26 +194,26 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { const char filePath[50]; xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) + int fd1 = open(filePath, O_RDONLY); + if (fd1 == -1) continue; char type[8]; - ssize_t typelen = xread(fd, type, 7); - close(fd); + ssize_t typelen = xread(fd1, type, 7); + close(fd1); if (typelen < 1) continue; if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) { + int fd2 = open(filePath, O_RDONLY); + if (fd2 == -1) { closedir(dir); return; } char buffer[1024]; - ssize_t buflen = xread(fd, buffer, 1023); - close(fd); + ssize_t buflen = xread(fd2, buffer, 1023); + close(fd2); if (buflen < 1) { closedir(dir); return; @@ -259,18 +259,18 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { } xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) { + int fd3 = open(filePath, O_RDONLY); + if (fd3 == -1) { closedir(dir); return; } char buffer[2] = ""; for(;;) { - ssize_t res = read(fd, buffer, 1); + ssize_t res = read(fd3, buffer, 1); if (res == -1 && errno == EINTR) continue; break; } - close(fd); + close(fd3); if (buffer[0] == '0') { *isOnAC = AC_ABSENT; } else if (buffer[0] == '1') { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 0d25e365..6d3d0348 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1227,9 +1227,9 @@ static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { (sscanf(buffer, "processor: %d", &cpuid) == 1) ) { if (cpuid < 0 || cpuid > (cpus - 1)) { - char buffer[64]; - xSnprintf(buffer, sizeof(buffer), PROCCPUINFOFILE " contains out-of-range CPU number %d", cpuid); - CRT_fatalError(buffer); + char tmpbuffer[64]; + xSnprintf(tmpbuffer, sizeof(tmpbuffer), PROCCPUINFOFILE " contains out-of-range CPU number %d", cpuid); + CRT_fatalError(tmpbuffer); } } else if ( (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || diff --git a/linux/Platform.c b/linux/Platform.c index 10311a2d..0f59fed6 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -94,12 +94,12 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel); if (!p) return HTOP_OK; - IOPriority ioprio = p->ioPriority; - Panel* ioprioPanel = IOPriorityPanel_new(ioprio); + IOPriority ioprio1 = p->ioPriority; + Panel* ioprioPanel = IOPriorityPanel_new(ioprio1); void* set = Action_pickFromVector(st, ioprioPanel, 21, true); if (set) { - IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL); + IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL); if (!ok) beep(); } -- cgit v1.2.3 From fc4f74aa47b0c15de3fb7d08e8aed7a2a5e086fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 25 Aug 2020 11:56:26 +0200 Subject: ci: add clang build --- .github/workflows/ci.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb7fb0a8..5482d1eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,29 @@ jobs: - name: Build run: make - name: Distcheck - run: make distcheck + run: make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror + + build-ubuntu-clang-latest: + runs-on: ubuntu-latest + env: + CC: clang-10 + steps: + - uses: actions/checkout@v2 + - name: install clang repo + run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key 2>/dev/null | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main' -y + sudo apt-get update -q + - name: Install Dependencies + run: sudo apt-get install clang-10 libncursesw5-dev + - name: Bootstrap + run: ./autogen.sh + - name: Configure + run: ./configure --enable-werror + - name: Build + run: make + - name: Distcheck + run: make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror whitespace_check: runs-on: ubuntu-latest -- cgit v1.2.3