diff --git a/CategoriesPanel.c b/CategoriesPanel.c index 64a3f0624..93ac31ef9 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -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) { diff --git a/Header.c b/Header.c index 8a9eae34d..e7eef288e 100644 --- a/Header.c +++ b/Header.c @@ -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; @@ -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)); } @@ -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; @@ -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; diff --git a/Header.h b/Header.h index 2cc78ab72..4940887fc 100644 --- a/Header.h +++ b/Header.h @@ -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); diff --git a/HeaderLayout.h b/HeaderLayout.h index c8d51c845..8577cc847 100644 --- a/HeaderLayout.h +++ b/HeaderLayout.h @@ -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); diff --git a/Meter.c b/Meter.c index 4463a90a0..84ef65531 100644 --- a/Meter.c +++ b/Meter.c @@ -49,16 +49,19 @@ static inline void Meter_displayBuffer(const Meter* this, RichString* out) { /* ---------- TextMeterMode ---------- */ static void TextMeterMode_draw(Meter* this, int x, int y, int w) { + if (w <= 0) + return; + const char* caption = Meter_getCaption(this); attrset(CRT_colors[METER_TEXT]); mvaddnstr(y, x, caption, w); attrset(CRT_colors[RESET_COLOR]); - int captionLen = strlen(caption); - x += captionLen; - w -= captionLen; - if (w <= 0) + size_t captionLen = strlen(caption); + if ((size_t)w <= captionLen) return; + x += (int)captionLen; + w -= (int)captionLen; RichString_begin(out); Meter_displayBuffer(this, &out); @@ -301,6 +304,10 @@ static void LEDMeterMode_drawDigit(int x, int y, int n) { } static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { + assert(x >= 0); + if (w <= 0) + return; + #ifdef HAVE_LIBNCURSESW if (CRT_utf8) LEDMeterMode_digits = LEDMeterMode_digitsUtf8; @@ -318,25 +325,25 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { y + 2; attrset(CRT_colors[LED_COLOR]); const char* caption = Meter_getCaption(this); - mvaddstr(yText, x, caption); - int xx = x + strlen(caption); + mvaddnstr(yText, x, caption, w); + size_t xx = (size_t)x + strlen(caption); int len = RichString_sizeVal(out); - for (int i = 0; i < len; i++) { + for (size_t i = 0; i < (size_t)len; i++) { int c = RichString_getCharVal(out, i); if (c >= '0' && c <= '9') { - if (xx - x + 4 > w) + if (xx + 4 > (unsigned int)x + (unsigned int)w) break; - LEDMeterMode_drawDigit(xx, y, c - '0'); + LEDMeterMode_drawDigit((int)xx, y, c - '0'); xx += 4; } else { - if (xx - x + 1 > w) + if (xx + 1 > (unsigned int)x + (unsigned int)w) break; #ifdef HAVE_LIBNCURSESW const cchar_t wc = { .chars = { c, '\0' }, .attr = 0 }; /* use LED_COLOR from attrset() */ - mvadd_wch(yText, xx, &wc); + mvadd_wch(yText, (int)xx, &wc); #else - mvaddch(yText, xx, c); + mvaddch(yText, (int)xx, c); #endif xx += 1; } diff --git a/Row.c b/Row.c index d795787e6..cdbe558a4 100644 --- a/Row.c +++ b/Row.c @@ -428,23 +428,23 @@ void Row_printNanoseconds(RichString* str, unsigned long long totalNanoseconds, } unsigned long long totalSeconds = totalMicroseconds / 1000000; - unsigned long microseconds = totalMicroseconds % 1000000; + uint32_t microseconds = totalMicroseconds % 1000000; if (totalSeconds < 60) { int width = 5; - unsigned long fraction = microseconds / 10; + uint32_t fraction = microseconds / 10; if (totalSeconds >= 10) { width--; fraction /= 10; } - len = xSnprintf(buffer, sizeof(buffer), "%u.%0*lus ", (unsigned int)totalSeconds, width, fraction); + len = xSnprintf(buffer, sizeof(buffer), "%u.%0*lus ", (unsigned int)totalSeconds, width, (unsigned long)fraction); RichString_appendnAscii(str, baseColor, buffer, len); return; } if (totalSeconds < 600) { - unsigned int minutes = totalSeconds / 60; - unsigned int seconds = totalSeconds % 60; - unsigned int milliseconds = microseconds / 1000; + unsigned int minutes = (unsigned int)totalSeconds / 60; + unsigned int seconds = (unsigned int)totalSeconds % 60; + unsigned int milliseconds = (unsigned int)(microseconds / 1000); len = xSnprintf(buffer, sizeof(buffer), "%u:%02u.%03u ", minutes, seconds, milliseconds); RichString_appendnAscii(str, baseColor, buffer, len); return; diff --git a/Settings.c b/Settings.c index f8fbcb19c..a402c0145 100644 --- a/Settings.c +++ b/Settings.c @@ -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; @@ -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); }