Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 19 related updates #1513

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ jobs:
build-ubuntu-latest-minimal-clang:
runs-on: ubuntu-latest
env:
CC: clang-18
CC: clang-19
steps:
- uses: actions/checkout@v4
- 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/jammy/ llvm-toolchain-jammy-18 main' -y
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main' -y
sudo apt-get update -q
- name: Install Dependencies
run: sudo apt-get install --no-install-recommends clang-18 libncursesw5-dev
run: sudo apt-get install --no-install-recommends clang-19 libncursesw5-dev
- name: Bootstrap
run: ./autogen.sh
- name: Configure
Expand Down Expand Up @@ -72,16 +72,16 @@ jobs:
build-ubuntu-latest-full-featured-clang:
runs-on: ubuntu-latest
env:
CC: clang-18
CC: clang-19
steps:
- uses: actions/checkout@v4
- 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/jammy/ llvm-toolchain-jammy-18 main' -y
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main' -y
sudo apt-get update -q
- name: Install Dependencies
run: sudo apt-get install --no-install-recommends clang-18 libncursesw5-dev libhwloc-dev libnl-3-dev libnl-genl-3-dev libsensors4-dev libcap-dev
run: sudo apt-get install --no-install-recommends clang-19 libncursesw5-dev libhwloc-dev libnl-3-dev libnl-genl-3-dev libsensors4-dev libcap-dev
- name: Bootstrap
run: ./autogen.sh
- name: Configure
Expand Down Expand Up @@ -127,27 +127,27 @@ jobs:
build-ubuntu-latest-clang-analyzer:
runs-on: ubuntu-latest
env:
CC: clang-18
CC: clang-19
steps:
- uses: actions/checkout@v4
- 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/jammy/ llvm-toolchain-jammy-18 main' -y
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main' -y
sudo apt-get update -q
- name: Install Dependencies
run: sudo apt-get install --no-install-recommends clang-18 clang-tools-18 libncursesw5-dev libnl-3-dev libnl-genl-3-dev libsensors4-dev libcap-dev
run: sudo apt-get install --no-install-recommends clang-19 clang-tools-19 libncursesw5-dev libnl-3-dev libnl-genl-3-dev libsensors4-dev libcap-dev
- name: Bootstrap
run: ./autogen.sh
- name: Configure
run: scan-build-18 -analyze-headers --status-bugs ./configure --enable-debug --enable-werror --enable-openvz --enable-vserver --enable-ancient-vserver --enable-unicode --enable-delayacct --enable-sensors --enable-capabilities || ( cat config.log; exit 1; )
run: scan-build-19 -analyze-headers --status-bugs ./configure --enable-debug --enable-werror --enable-openvz --enable-vserver --enable-ancient-vserver --enable-unicode --enable-delayacct --enable-sensors --enable-capabilities || ( cat config.log; exit 1; )
- name: Build
run: scan-build-18 -analyze-headers --status-bugs make -j"$(nproc)"
run: scan-build-19 -analyze-headers --status-bugs make -j"$(nproc)"

build-ubuntu-latest-clang-sanitizer:
runs-on: ubuntu-latest
env:
CC: clang-18
CC: clang-19
CFLAGS: '-O1 -g -ftrivial-auto-var-init=pattern -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-address-use-after-return=always -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=nullability -fsanitize=implicit-conversion -fsanitize=integer -fsanitize=float-divide-by-zero -fsanitize=local-bounds'
LDFLAGS: '-ftrivial-auto-var-init=pattern -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-address-use-after-return=always -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=nullability -fsanitize=implicit-conversion -fsanitize=integer -fsanitize=float-divide-by-zero -fsanitize=local-bounds'
ASAN_OPTIONS: strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
Expand All @@ -159,10 +159,10 @@ jobs:
- 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/jammy/ llvm-toolchain-jammy-18 main' -y
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main' -y
sudo apt-get update -q
- name: Install LLVM Toolchain
run: sudo apt-get install --no-install-recommends clang-18 libclang-rt-18-dev llvm-18
run: sudo apt-get install --no-install-recommends clang-19 libclang-rt-19-dev llvm-19
- name: Install Dependencies
run: sudo apt-get install --no-install-recommends libncursesw5-dev libhwloc-dev libnl-3-dev libnl-genl-3-dev libsensors4-dev libcap-dev
- name: Bootstrap
Expand Down
12 changes: 8 additions & 4 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,19 @@ static Htop_Reaction actionPrevScreen(State* st) {
}

Htop_Reaction Action_setScreenTab(State* st, int x) {
assert(x >= 0);
if (x < 0)
return 0;
unsigned int pos = x;
Settings* settings = st->host->settings;
int s = 2;
unsigned int s = 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this algorithm, it's better for s to be in size_t, and use (size_t)x (upcast) for comparisons below. I think I would submit my propsed change in a separate PR.

for (unsigned int i = 0; i < settings->nScreens; i++) {
if (x < s) {
if (pos < s) {
return 0;
}
const char* tab = settings->screens[i]->heading;
int len = strlen(tab);
if (x <= s + len + 1) {
size_t len = strlen(tab);
if (pos <= s + len + 1) {
settings->ssIndex = i;
setActiveScreen(settings, st, i);
return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
Expand Down
4 changes: 2 additions & 2 deletions AffinityPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static MaskItem* AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u
}

/* "[x] " + "|- " * depth + ("- ")?(if root node) + name */
unsigned width = 4 + 3 * depth + (2 * !depth) + strlen(buf);
unsigned width = 4 + 3 * depth + (2 * !depth) + (unsigned)strlen(buf);
if (width > this->width) {
this->width = width;
}
Expand Down Expand Up @@ -389,7 +389,7 @@ Panel* AffinityPanel_new(Machine* host, const Affinity* affinity, int* width) {

char number[16];
xSnprintf(number, 9, "CPU %d", Settings_cpuId(host->settings, i));
unsigned cpu_width = 4 + strlen(number);
unsigned cpu_width = 4 + (unsigned) strlen(number);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned cpu_width = 4 + (unsigned) strlen(number);
unsigned cpu_width = 4 + (unsigned)strlen(number);

if (cpu_width > this->width) {
this->width = cpu_width;
}
Expand Down
16 changes: 10 additions & 6 deletions CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ in the source distribution for its full text.

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <locale.h>
#include <stdbool.h>
Expand Down Expand Up @@ -204,12 +205,15 @@ static CommandLineStatus parseArguments(int argc, char** argv, CommandLineSettin
if (!username) {
flags->userId = geteuid();
} else if (!Action_setUserOnly(username, &(flags->userId))) {
for (const char* itr = username; *itr; ++itr)
if (!isdigit((unsigned char)*itr)) {
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
return STATUS_ERROR_EXIT;
}
flags->userId = atol(username);
char *endptr;
errno = 0;
unsigned long res = strtoul(username, &endptr, 10);
unsigned castRes = (unsigned) res;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned castRes = (unsigned) res;
unsigned castRes = (unsigned)res;

if (*endptr != '\0' || res == ULONG_MAX || errno != 0 || castRes != res) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (*endptr != '\0' || res == ULONG_MAX || errno != 0 || castRes != res) {
if (*endptr != '\0' || res == ULONG_MAX || errno != 0 || res > UINT_MAX) {

or

Suggested change
if (*endptr != '\0' || res == ULONG_MAX || errno != 0 || castRes != res) {
if (*endptr != '\0' || res > UINT_MAX || errno != 0) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenBE I would say res >= UINT_MAX because, AFAIK, (uid_t)-1 is invalid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's something the current version didn't check for …

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I can suggest a better code for this, I need one behavior clarified:
Is username being an empty string acceptable here?
Because strtoul would not produce an error for the empty string. It would happily return 0 as the result.

fprintf(stderr, "Error: invalid user \"%s\".\n", username);
return STATUS_ERROR_EXIT;
}
flags->userId = castRes;
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions DynamicMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static void DynamicMeter_getUiName(const Meter* this, char* name, size_t length)
const char* uiName = meter->caption;
if (uiName) {
size_t uiNameLen = strlen(uiName);
assert(uiNameLen < 32);
if (uiNameLen > 2 && uiName[uiNameLen - 2] == ':')
uiNameLen -= 2;

Expand Down
12 changes: 6 additions & 6 deletions Header.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Header_setLayout(Header* this, HeaderLayout hLayout) {
Header_calculateHeight(this);
}

static void Header_addMeterByName(Header* this, const char* name, MeterModeId mode, unsigned int column) {
static void Header_addMeterByName(Header* this, const char* name, MeterModeId mode, size_t column) {
assert(column < HeaderLayout_getColumns(this->headerLayout));

Vector* meters = this->columns[column];
Expand Down Expand Up @@ -170,7 +170,7 @@ void Header_writeBackToSettings(const Header* this) {
}
}

Meter* Header_addMeterByClass(Header* this, const MeterClass* type, unsigned int param, unsigned int column) {
Meter* Header_addMeterByClass(Header* this, const MeterClass* type, unsigned int param, size_t column) {
assert(column < HeaderLayout_getColumns(this->headerLayout));

Vector* meters = this->columns[column];
Expand Down Expand Up @@ -198,8 +198,8 @@ void Header_draw(const Header* this) {
for (int y = 0; y < height; y++) {
mvhline(y, 0, ' ', COLS);
}
const int numCols = HeaderLayout_getColumns(this->headerLayout);
const int width = COLS - 2 * pad - (numCols - 1);
const size_t numCols = HeaderLayout_getColumns(this->headerLayout);
const size_t width = COLS - 2 * pad - (numCols - 1);
int x = pad;
float roundingLoss = 0.0F;

Expand All @@ -221,7 +221,7 @@ void Header_draw(const Header* this) {
/* Let meters in text mode expand to the right on empty neighbors;
except for multi column meters. */
if (meter->mode == TEXT_METERMODE && !Meter_isMultiColumn(meter)) {
for (int j = 1; j < meter->columnWidthCount; j++) {
for (size_t j = 1; j < meter->columnWidthCount; j++) {
actualWidth++; /* separator column */
actualWidth += (float)width * HeaderLayout_layouts[this->headerLayout].widths[col + j] / 100.0F;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ void Header_updateData(Header* this) {
* by counting how many columns to the right are empty or contain a BlankMeter.
* Returns the number of columns to span, i.e. if the direct neighbor is occupied 1.
*/
static int calcColumnWidthCount(const Header* this, const Meter* curMeter, const int pad, const unsigned int curColumn, const int curHeight) {
static size_t calcColumnWidthCount(const Header* this, const Meter* curMeter, const int pad, const size_t curColumn, const int curHeight) {
for (size_t i = curColumn + 1; i < HeaderLayout_getColumns(this->headerLayout); i++) {
const Vector* meters = this->columns[i];

Expand Down
2 changes: 1 addition & 1 deletion Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Header_populateFromSettings(Header* this);

void Header_writeBackToSettings(const Header* this);

Meter* Header_addMeterByClass(Header* this, const MeterClass* type, unsigned int param, unsigned int column);
Meter* Header_addMeterByClass(Header* this, const MeterClass* type, unsigned int param, size_t column);

void Header_reinit(Header* this);

Expand Down
2 changes: 1 addition & 1 deletion IncSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef enum {

typedef struct IncMode_ {
char buffer[INCMODE_MAX + 1];
int index;
size_t index;
FunctionBar* bar;
bool isFilter;
} IncMode;
Expand Down
8 changes: 5 additions & 3 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
mvaddnstr(y, x, caption, w);
attrset(CRT_colors[RESET_COLOR]);

int captionLen = strlen(caption);
int captionLen = (int)strlen(caption);
x += captionLen;
w -= captionLen;
if (w <= 0)
Expand Down Expand Up @@ -251,7 +251,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
// Starting positions of graph data and terminal column
if ((size_t)w > nValues / 2) {
x += w - nValues / 2;
w = nValues / 2;
w = (int)(nValues / 2);
}
size_t i = nValues - (size_t)w * 2;

Expand Down Expand Up @@ -319,7 +319,9 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
attrset(CRT_colors[LED_COLOR]);
const char* caption = Meter_getCaption(this);
mvaddstr(yText, x, caption);
int xx = x + strlen(caption);
size_t capLen = strlen(caption);
assert(capLen < 32);
int xx = x + (int) MINIMUM(capLen, 32);
int len = RichString_sizeVal(out);
for (int i = 0; i < len; i++) {
int c = RichString_getCharVal(out, i);
Expand Down
2 changes: 1 addition & 1 deletion Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct Meter_ {
unsigned int param;
GraphData drawData;
int h;
int columnWidthCount; /**< only used internally by the Header */
size_t columnWidthCount; /**< only used internally by the Header */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't understand the reason why expanding the bit width of this columnWidthCount to 64. Would it save code size by saving some cast instructions?

uint8_t curItems;
const int* curAttributes;
char txtBuffer[METER_TXTBUFFER_LEN];
Expand Down
2 changes: 1 addition & 1 deletion Panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
char* buffer = this->eventHandlerState;

if (0 < ch && ch < 255 && isgraph((unsigned char)ch)) {
int len = strlen(buffer);
size_t len = strlen(buffer);
if (!len) {
if ('/' == ch) {
ch = '\001';
Expand Down
Loading
Loading