Skip to content

Commit

Permalink
Use 'unsigned int' for Header column numbers
Browse files Browse the repository at this point in the history
Change return type of HeaderLayout_getColumns() from 'size_t' to
'unsigned int', and use 'unsigned int' type for all Header column
iterators.

Using 'size_t' is unnecessary (you cannot have 2^32 columns anyway)
and would cause "-Wshorten-64-to-32" warnings (enabled by default in
Clang 19).
  • Loading branch information
Explorer09 committed Aug 13, 2024
1 parent 161c4ac commit 29cc62e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions CategoriesPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ static void CategoriesPanel_delete(Object* object) {
}

static void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
size_t columns = HeaderLayout_getColumns(this->scr->header->headerLayout);
unsigned int columns = HeaderLayout_getColumns(this->scr->header->headerLayout);
MetersPanel** meterPanels = xMallocArray(columns, sizeof(MetersPanel*));
Settings* settings = this->host->settings;

for (size_t i = 0; i < columns; i++) {
for (unsigned int i = 0; i < columns; i++) {
char titleBuffer[32];
xSnprintf(titleBuffer, sizeof(titleBuffer), "Column %zu", i + 1);
xSnprintf(titleBuffer, sizeof(titleBuffer), "Column %u", i + 1);
meterPanels[i] = MetersPanel_new(settings, titleBuffer, this->header->columns[i], this->scr);

if (i != 0) {
Expand Down
12 changes: 6 additions & 6 deletions Header.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void Header_delete(Header* this) {
}

void Header_setLayout(Header* this, HeaderLayout hLayout) {
size_t oldColumns = HeaderLayout_getColumns(this->headerLayout);
size_t newColumns = HeaderLayout_getColumns(hLayout);
unsigned int oldColumns = HeaderLayout_getColumns(this->headerLayout);
unsigned int newColumns = HeaderLayout_getColumns(hLayout);

this->headerLayout = hLayout;

Expand All @@ -61,11 +61,11 @@ void Header_setLayout(Header* this, HeaderLayout hLayout) {

if (newColumns > oldColumns) {
this->columns = xReallocArray(this->columns, newColumns, sizeof(Vector*));
for (size_t i = oldColumns; i < newColumns; i++)
for (unsigned int i = oldColumns; i < newColumns; i++)
this->columns[i] = Vector_new(Class(Meter), true, DEFAULT_SIZE);
} else {
// move meters from to-be-deleted columns into last one
for (size_t i = newColumns; i < oldColumns; i++) {
for (unsigned int i = newColumns; i < oldColumns; i++) {
for (int j = this->columns[i]->items - 1; j >= 0; j--) {
Vector_add(this->columns[newColumns - 1], Vector_take(this->columns[i], j));
}
Expand Down Expand Up @@ -198,7 +198,7 @@ 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 numCols = (int)HeaderLayout_getColumns(this->headerLayout);
const int width = COLS - 2 * pad - (numCols - 1);
int x = pad;
float roundingLoss = 0.0F;
Expand Down Expand Up @@ -254,7 +254,7 @@ void Header_updateData(Header* this) {
* 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) {
for (size_t i = curColumn + 1; i < HeaderLayout_getColumns(this->headerLayout); i++) {
for (unsigned int i = curColumn + 1; i < HeaderLayout_getColumns(this->headerLayout); i++) {
const Vector* meters = this->columns[i];

int height = pad;
Expand Down
2 changes: 1 addition & 1 deletion Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct Header_ {
int height;
} Header;

#define Header_forEachColumn(this_, i_) for (size_t (i_)=0, H_fEC_numColumns_ = HeaderLayout_getColumns((this_)->headerLayout); (i_) < H_fEC_numColumns_; ++(i_))
#define Header_forEachColumn(this_, i_) for (unsigned int (i_)=0, H_fEC_numColumns_ = HeaderLayout_getColumns((this_)->headerLayout); (i_) < H_fEC_numColumns_; ++(i_))

Header* Header_new(Machine* host, HeaderLayout hLayout);

Expand Down
2 changes: 1 addition & 1 deletion HeaderLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static const struct {
[HF_FOUR_25_25_25_25] = { 4, { 25, 25, 25, 25 }, "four_25_25_25_25", "4 columns - 25/25/25/25", },
};

static inline size_t HeaderLayout_getColumns(HeaderLayout hLayout) {
static inline unsigned int HeaderLayout_getColumns(HeaderLayout hLayout) {
/* assert the layout is initialized */
assert(0 <= hLayout);
assert(hLayout < LAST_HEADER_LAYOUT);
Expand Down
6 changes: 3 additions & 3 deletions Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ static void Settings_readMeterModes(Settings* this, const char* line, unsigned i
}

static bool Settings_validateMeters(Settings* this) {
const size_t colCount = HeaderLayout_getColumns(this->hLayout);
const unsigned int colCount = HeaderLayout_getColumns(this->hLayout);

bool anyMeter = false;

for (size_t column = 0; column < colCount; column++) {
for (unsigned int column = 0; column < colCount; column++) {
char** names = this->hColumns[column].names;
const MeterModeId* modes = this->hColumns[column].modes;
const size_t len = this->hColumns[column].len;
Expand Down Expand Up @@ -154,7 +154,7 @@ static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount)
}

// Release any previously allocated memory
for (size_t i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
String_freeArray(this->hColumns[i].names);
free(this->hColumns[i].modes);
}
Expand Down

0 comments on commit 29cc62e

Please sign in to comment.