Skip to content

Commit

Permalink
Silence -Wshorten-64-to-32 warnings
Browse files Browse the repository at this point in the history
Enabled in LLVM 19
  • Loading branch information
cgzones authored and BenBE committed Sep 23, 2024
1 parent b1b804f commit fbd42e4
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 106 deletions.
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;
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);
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;
if (*endptr != '\0' || res == ULONG_MAX || errno != 0 || castRes != res) {
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 */
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
43 changes: 26 additions & 17 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ static bool findCommInCmdline(const char* comm, const char* cmdline, int cmdline

if ((tokenLen == commLen || (tokenLen > commLen && commLen == (TASK_COMM_LEN - 1))) &&
strncmp(tokenBase, comm, commLen) == 0) {
*pCommStart = tokenBase - cmdline;
*pCommEnd = token - cmdline;
*pCommStart = (int)(tokenBase - cmdline);
*pCommEnd = (int)(token - cmdline);
return true;
}

Expand Down Expand Up @@ -209,7 +209,7 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
/* The field separator "│" has been chosen such that it will not match any
* valid string used for searching or filtering */
const char* SEPARATOR = CRT_treeStr[TREE_STR_VERT];
const int SEPARATOR_LEN = strlen(SEPARATOR);
const size_t SEPARATOR_LEN = strlen(SEPARATOR);

/* Accommodate the column text, two field separators and terminating NUL */
size_t maxLen = 2 * SEPARATOR_LEN + 1;
Expand Down Expand Up @@ -350,7 +350,7 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
return;
}

int exeLen = strlen(this->procExe);
int exeLen = (int)MINIMUM(strlen(this->procExe), 65536);
int exeBasenameOffset = this->procExeBasenameOffset;
int exeBasenameLen = exeLen - exeBasenameOffset;

Expand Down Expand Up @@ -509,7 +509,7 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin
if (!highlightDeleted)
continue;

RichString_setAttrn(str, hl->attr, strStart + hl->offset, hl->length);
RichString_setAttrn(str, hl->attr, (int)(strStart + hl->offset), (int)hl->length);
}
}

Expand Down Expand Up @@ -575,7 +575,7 @@ void Process_writeField(const Process* this, RichString* str, RowField field) {
ret = xSnprintf(buf, n, " ");
}
if (ret < 0 || (size_t)ret >= n) {
written = n;
written = (int)n;
} else {
written = ret;
}
Expand Down Expand Up @@ -870,7 +870,13 @@ static bool Process_setPriority(Process* this, int priority) {
bool Process_rowChangePriorityBy(Row* super, Arg delta) {
Process* this = (Process*) super;
assert(Object_isA((const Object*) this, (const ObjectClass*) &Process_class));
return Process_setPriority(this, this->nice + delta.i);

long value = this->nice + delta.i;
int prio = (int)value;
if (prio != value)
return false;

return Process_setPriority(this, prio);
}

static bool Process_sendSignal(Process* this, Arg sgn) {
Expand Down Expand Up @@ -1002,12 +1008,12 @@ void Process_updateComm(Process* this, const char* comm) {
this->mergedCommand.lastUpdate = 0;
}

static int skipPotentialPath(const char* cmdline, int end) {
static size_t skipPotentialPath(const char* cmdline, size_t end) {
if (cmdline[0] != '/')
return 0;

int slash = 0;
for (int i = 1; i < end; i++) {
size_t slash = 0;
for (size_t i = 1; i < end; i++) {
if (cmdline[i] == '/' && cmdline[i + 1] != '\0') {
slash = i + 1;
continue;
Expand All @@ -1023,27 +1029,29 @@ static int skipPotentialPath(const char* cmdline, int end) {
return slash;
}

void Process_updateCmdline(Process* this, const char* cmdline, int basenameStart, int basenameEnd) {
assert(basenameStart >= 0);
assert((cmdline && basenameStart < (int)strlen(cmdline)) || (!cmdline && basenameStart == 0));
void Process_updateCmdline(Process* this, const char* cmdline, size_t basenameStart, size_t basenameEnd) {
assert((cmdline && basenameStart < strlen(cmdline)) || (!cmdline && basenameStart == 0));
assert((basenameEnd > basenameStart) || (basenameEnd == 0 && basenameStart == 0));
assert((cmdline && basenameEnd <= (int)strlen(cmdline)) || (!cmdline && basenameEnd == 0));
assert((cmdline && basenameEnd <= strlen(cmdline)) || (!cmdline && basenameEnd == 0));

if (!this->cmdline && !cmdline)
return;

if (this->cmdline && cmdline && String_eq(this->cmdline, cmdline))
return;

basenameStart = MINIMUM(basenameStart, 1000000);
basenameEnd = MINIMUM(basenameEnd, 1000000);

free(this->cmdline);
this->cmdline = cmdline ? xStrdup(cmdline) : NULL;
if (Process_isKernelThread(this)) {
/* kernel threads have no basename */
this->cmdlineBasenameStart = 0;
this->cmdlineBasenameEnd = 0;
} else {
this->cmdlineBasenameStart = (basenameStart || !cmdline) ? basenameStart : skipPotentialPath(cmdline, basenameEnd);
this->cmdlineBasenameEnd = basenameEnd;
this->cmdlineBasenameStart = (basenameStart || !cmdline) ? (int)basenameStart : (int)skipPotentialPath(cmdline, basenameEnd);
this->cmdlineBasenameEnd = (int)basenameEnd;
}

this->mergedCommand.lastUpdate = 0;
Expand All @@ -1060,7 +1068,8 @@ void Process_updateExe(Process* this, const char* exe) {
if (exe) {
this->procExe = xStrdup(exe);
const char* lastSlash = strrchr(exe, '/');
this->procExeBasenameOffset = (lastSlash && *(lastSlash + 1) != '\0' && lastSlash != exe) ? (lastSlash - exe + 1) : 0;
long offset = (lastSlash && *(lastSlash + 1) != '\0' && lastSlash != exe) ? (lastSlash - exe + 1) : 0;
this->procExeBasenameOffset = MAXIMUM((int)offset, 0);
} else {
this->procExe = NULL;
this->procExeBasenameOffset = 0;
Expand Down
2 changes: 1 addition & 1 deletion Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField
const char* Process_getCommand(const Process* this);

void Process_updateComm(Process* this, const char* comm);
void Process_updateCmdline(Process* this, const char* cmdline, int basenameStart, int basenameEnd);
void Process_updateCmdline(Process* this, const char* cmdline, size_t basenameStart, size_t basenameEnd);
void Process_updateExe(Process* this, const char* exe);

/* This function constructs the string that is displayed by
Expand Down
15 changes: 8 additions & 7 deletions RichString.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static void RichString_extendLen(RichString* this, int len) {
}

static void RichString_setLen(RichString* this, int len) {
len = MAXIMUM(len, 0);
if (len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) {
RichString_setChar(this, len, 0);
this->chlen = len;
Expand All @@ -59,7 +60,7 @@ static void RichString_setLen(RichString* this, int len) {
}

void RichString_rewind(RichString* this, int count) {
RichString_setLen(this, this->chlen - count);
RichString_setLen(this, CLAMP(this->chlen - count, 0, this->chlen));
}

#ifdef HAVE_LIBNCURSESW
Expand Down Expand Up @@ -99,7 +100,7 @@ static size_t mbstowcs_nonfatal(wchar_t* restrict dest, const char* restrict src

static inline int RichString_writeFromWide(RichString* this, int attrs, const char* data_c, int from, int len) {
wchar_t data[len];
len = mbstowcs_nonfatal(data, data_c, len);
len = (int)mbstowcs_nonfatal(data, data_c, len);
if (len <= 0)
return 0;

Expand All @@ -114,7 +115,7 @@ static inline int RichString_writeFromWide(RichString* this, int attrs, const ch

int RichString_appendnWideColumns(RichString* this, int attrs, const char* data_c, int len, int* columns) {
wchar_t data[len];
len = mbstowcs_nonfatal(data, data_c, len);
len = (int)mbstowcs_nonfatal(data, data_c, len);
if (len <= 0)
return 0;

Expand Down Expand Up @@ -243,25 +244,25 @@ void RichString_setAttr(RichString* this, int attrs) {
}

int RichString_appendWide(RichString* this, int attrs, const char* data) {
return RichString_writeFromWide(this, attrs, data, this->chlen, strlen(data));
return RichString_writeFromWide(this, attrs, data, this->chlen, (int)strlen(data));
}

int RichString_appendnWide(RichString* this, int attrs, const char* data, int len) {
return RichString_writeFromWide(this, attrs, data, this->chlen, len);
}

int RichString_writeWide(RichString* this, int attrs, const char* data) {
return RichString_writeFromWide(this, attrs, data, 0, strlen(data));
return RichString_writeFromWide(this, attrs, data, 0, (int)strlen(data));
}

int RichString_appendAscii(RichString* this, int attrs, const char* data) {
return RichString_writeFromAscii(this, attrs, data, this->chlen, strlen(data));
return RichString_writeFromAscii(this, attrs, data, this->chlen, (int)strlen(data));
}

int RichString_appendnAscii(RichString* this, int attrs, const char* data, int len) {
return RichString_writeFromAscii(this, attrs, data, this->chlen, len);
}

int RichString_writeAscii(RichString* this, int attrs, const char* data) {
return RichString_writeFromAscii(this, attrs, data, 0, strlen(data));
return RichString_writeFromAscii(this, attrs, data, 0, (int)strlen(data));
}
Loading

0 comments on commit fbd42e4

Please sign in to comment.