diff --git a/client/cmddata.c b/client/cmddata.c index d971d0fba..9b637894d 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1985,7 +1985,7 @@ static void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int //old CmdFSKdemod adapted by marshmellow //converts FSK to clear NRZ style wave. (or demodulates) -static int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) { +static int FSKToNRZ(int *data, size_t *dataLen, int clk, int LowToneFC, int HighToneFC) { uint8_t ans = 0; if (clk == 0 || LowToneFC == 0 || HighToneFC == 0) { int firstClockEdge = 0; @@ -2002,17 +2002,16 @@ static int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighTon return 0; } - int i, j; int LowTone[clk]; int HighTone[clk]; GetHiLoTone(LowTone, HighTone, clk, LowToneFC, HighToneFC); // loop through ([all samples] - clk) - for (i = 0; i < *dataLen - clk; ++i) { + for (size_t i = 0; i < *dataLen - clk; ++i) { int lowSum = 0, highSum = 0; // sum all samples together starting from this sample for [clk] samples for each tone (multiply tone value with sample data) - for (j = 0; j < clk; ++j) { + for (size_t j = 0; j < clk; ++j) { lowSum += LowTone[j] * data[i + j]; highSum += HighTone[j] * data[i + j]; } @@ -2026,14 +2025,14 @@ static int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighTon // now we have the abs( [average sample value per clk] * 100 ) for each tone // loop through again [all samples] - clk - 16 // note why 16??? is 16 the largest FC? changed to LowToneFC as that should be the > fc - for (i = 0; i < *dataLen - clk - LowToneFC; ++i) { + for (size_t i = 0; i < *dataLen - clk - LowToneFC; ++i) { int lowTot = 0, highTot = 0; // sum a field clock width of abs( [average sample values per clk] * 100) for each tone - for (j = 0; j < LowToneFC; ++j) { //10 for fsk2 + for (size_t j = 0; j < LowToneFC; ++j) { //10 for fsk2 lowTot += (data[i + j] & 0xffff); } - for (j = 0; j < HighToneFC; j++) { //8 for fsk2 + for (size_t j = 0; j < HighToneFC; j++) { //8 for fsk2 highTot += (data[i + j] >> 16); } diff --git a/client/crypto/asn1dump.c b/client/crypto/asn1dump.c index 2fd99ac40..e197749a0 100644 --- a/client/crypto/asn1dump.c +++ b/client/crypto/asn1dump.c @@ -165,7 +165,7 @@ static void asn1_tag_dump_string(const struct tlv *tlv, const struct asn1_tag *t static void asn1_tag_dump_octet_string(const struct tlv *tlv, const struct asn1_tag *tag, FILE *f, int level, bool *needdump) { *needdump = false; - for (int i = 0; i < tlv->len; i++) + for (size_t i = 0; i < tlv->len; i++) if (!isspace(tlv->value[i]) && !isprint(tlv->value[i])) { *needdump = true; break; @@ -181,7 +181,7 @@ static void asn1_tag_dump_octet_string(const struct tlv *tlv, const struct asn1_ static unsigned long asn1_value_integer(const struct tlv *tlv, unsigned start, unsigned end) { unsigned long ret = 0; - int i; + unsigned i; if (end > tlv->len * 2) return ret; @@ -222,7 +222,7 @@ static void asn1_tag_dump_integer(const struct tlv *tlv, const struct asn1_tag * PRINT_INDENT(level); if (tlv->len == 4) { int32_t val = 0; - for (int i = 0; i < tlv->len; i++) + for (size_t i = 0; i < tlv->len; i++) val = (val << 8) + tlv->value[i]; fprintf(f, "\tvalue4b: %d\n", val); return; diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index a688d9a9a..a10e6291e 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -150,7 +150,7 @@ fido2Desc_t fido2CmdGetInfoRespDesc[] = { }; const char *fido2GetCmdErrorDescription(uint8_t errorCode) { - for (int i = 0; i < sizeof(fido2Errors) / sizeof(fido2Error_t); i++) + for (size_t i = 0; i < sizeof(fido2Errors) / sizeof(fido2Error_t); i++) if (fido2Errors[i].ErrorCode == errorCode) return fido2Errors[i].Description; @@ -158,7 +158,7 @@ const char *fido2GetCmdErrorDescription(uint8_t errorCode) { } const char *fido2GetCmdMemberDescription(uint8_t cmdCode, bool isResponse, int memberNum) { - for (int i = 0; i < sizeof(fido2CmdGetInfoRespDesc) / sizeof(fido2Desc_t); i++) + for (size_t i = 0; i < sizeof(fido2CmdGetInfoRespDesc) / sizeof(fido2Desc_t); i++) if (fido2CmdGetInfoRespDesc[i].Command == cmdCode && fido2CmdGetInfoRespDesc[i].PckType == (isResponse ? ptResponse : ptQuery) && fido2CmdGetInfoRespDesc[i].MemberNumber == memberNum) diff --git a/client/graph.c b/client/graph.c index 677ab0846..d2a816125 100644 --- a/client/graph.c +++ b/client/graph.c @@ -10,7 +10,7 @@ #include "graph.h" int GraphBuffer[MAX_GRAPH_TRACE_LEN]; -int GraphTraceLen; +size_t GraphTraceLen; int s_Buff[MAX_GRAPH_TRACE_LEN]; /* write a manchester bit to the graph @@ -30,8 +30,8 @@ void AppendGraph(bool redraw, int clock, int bit) { } // clear out our graph window -int ClearGraph(bool redraw) { - int gtl = GraphTraceLen; +size_t ClearGraph(bool redraw) { + size_t gtl = GraphTraceLen; memset(GraphBuffer, 0x00, GraphTraceLen); GraphTraceLen = 0; if (redraw) @@ -41,7 +41,7 @@ int ClearGraph(bool redraw) { // option '1' to save GraphBuffer any other to restore void save_restoreGB(uint8_t saveOpt) { static int SavedGB[MAX_GRAPH_TRACE_LEN]; - static int SavedGBlen = 0; + static size_t SavedGBlen = 0; static bool GB_Saved = false; static int SavedGridOffsetAdj = 0; @@ -67,7 +67,7 @@ void setGraphBuf(uint8_t *buff, size_t size) { if (size > MAX_GRAPH_TRACE_LEN) size = MAX_GRAPH_TRACE_LEN; - for (uint32_t i = 0; i < size; ++i) + for (size_t i = 0; i < size; ++i) GraphBuffer[i] = buff[i] - 128; GraphTraceLen = size; @@ -77,7 +77,7 @@ void setGraphBuf(uint8_t *buff, size_t size) { size_t getFromGraphBuf(uint8_t *buff) { if (buff == NULL) return 0; - uint32_t i; + size_t i; for (i = 0; i < GraphTraceLen; ++i) { //trim if (GraphBuffer[i] > 127) GraphBuffer[i] = 127; @@ -89,7 +89,7 @@ size_t getFromGraphBuf(uint8_t *buff) { // A simple test to see if there is any data inside Graphbuffer. bool HasGraphData() { - if (GraphTraceLen <= 0) { + if (GraphTraceLen == 0) { PrintAndLogEx(NORMAL, "No data available, try reading something first"); return false; } diff --git a/client/graph.h b/client/graph.h index 98acec8dd..accd64de8 100644 --- a/client/graph.h +++ b/client/graph.h @@ -19,7 +19,7 @@ #include "cmddata.h" //for g_debugmode void AppendGraph(bool redraw, int clock, int bit); -int ClearGraph(bool redraw); +size_t ClearGraph(bool redraw); size_t getFromGraphBuf(uint8_t *buff); int GetAskClock(const char *str, bool printAns); int GetPskClock(const char *str, bool printAns); @@ -40,7 +40,7 @@ bool HasGraphData(void); #define GRAPH_RESTORE 0 extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; -extern int GraphTraceLen; +extern size_t GraphTraceLen; extern int s_Buff[MAX_GRAPH_TRACE_LEN]; #endif diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c index d85adc0c8..72d3e26af 100644 --- a/client/loclass/fileutils.c +++ b/client/loclass/fileutils.c @@ -92,7 +92,6 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, si int retval = 0; int blocks = datalen / blocksize; uint16_t currblock = 1; - int i, j; int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10); char *fileName = calloc(size, sizeof(char)); int num = 1; @@ -112,7 +111,7 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, si goto out; } - for (i = 0; i < datalen; i++) { + for (size_t i = 0; i < datalen; i++) { fprintf(f, "%02X", data[i]); // no extra line in the end @@ -124,7 +123,7 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, si // left overs if (datalen % blocksize != 0) { int index = blocks * blocksize; - for (j = 0; j < datalen % blocksize; j++) { + for (size_t j = 0; j < datalen % blocksize; j++) { fprintf(f, "%02X", data[index + j]); } } @@ -162,9 +161,9 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty } case jsfCardMemory: { JsonSaveStr(root, "FileType", "mfcard"); - for (int i = 0; i < (datalen / 16); i++) { + for (size_t i = 0; i < (datalen / 16); i++) { char path[PATH_MAX_LENGTH] = {0}; - sprintf(path, "$.blocks.%d", i); + sprintf(path, "$.blocks.%zu", i); JsonSaveBufAsHexCompact(root, path, &data[i * 16], 16); if (i == 0) { @@ -188,19 +187,19 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty JsonSaveBufAsHexCompact(root, path, &data[i * 16 + 6], 4); memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%d", mfSectorNum(i), i - 3); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 3); JsonSaveStr(root, path, mfGetAccessConditionsDesc(0, adata)); memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%d", mfSectorNum(i), i - 2); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 2); JsonSaveStr(root, path, mfGetAccessConditionsDesc(1, adata)); memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%d", mfSectorNum(i), i - 1); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 1); JsonSaveStr(root, path, mfGetAccessConditionsDesc(2, adata)); memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%d", mfSectorNum(i), i); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i); JsonSaveStr(root, path, mfGetAccessConditionsDesc(3, adata)); memset(path, 0x00, sizeof(path)); @@ -231,9 +230,9 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty // size of header 48b size_t len = (datalen - DUMP_PREFIX_LENGTH) / 4; - for (int i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { char path[PATH_MAX_LENGTH] = {0}; - sprintf(path, "$.blocks.%d", i); + sprintf(path, "$.blocks.%zu", i); JsonSaveBufAsHexCompact(root, path, tmp->data + (i * 4), 4); } break; @@ -245,9 +244,9 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); - for (int i = 0; i < (datalen / 4); i++) { + for (size_t i = 0; i < (datalen / 4); i++) { char path[PATH_MAX_LENGTH] = {0}; - sprintf(path, "$.blocks.%d", i); + sprintf(path, "$.blocks.%zu", i); JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4); } break; @@ -470,14 +469,14 @@ int loadFileJSON(const char *preferredName, const char *suffix, void *data, size if (!strcmp(ctype, "hitag")) { size_t sptr = 0; - for (int i = 0; i < (maxdatalen / 4); i++) { + for (size_t i = 0; i < (maxdatalen / 4); i++) { if (sptr + 4 > maxdatalen) { retval = 5; goto out; } char path[30] = {0}; - sprintf(path, "$.blocks.%d", i); + sprintf(path, "$.blocks.%zu", i); size_t len = 0; JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len); diff --git a/client/mifare/mfkey.c b/client/mifare/mfkey.c index b55c7e3c7..3ce2975b9 100644 --- a/client/mifare/mfkey.c +++ b/client/mifare/mfkey.c @@ -27,7 +27,7 @@ uint32_t intersection(uint64_t *listA, uint64_t *listB) { p1 = p3 = listA; p2 = listB; - while (*p1 != -1 && *p2 != -1) { + while (*p1 != UINT64_C(-1) && *p2 != UINT64_C(-1)) { if (compare_uint64(p1, p2) == 0) { *p3++ = *p1++; p2++; @@ -36,7 +36,7 @@ uint32_t intersection(uint64_t *listA, uint64_t *listB) { while (compare_uint64(p1, p2) > 0) ++p2; } } - *p3 = -1; + *p3 = UINT64_C(-1); return p3 - listA; } diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 0b2a49048..b7842dda0 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -89,13 +89,13 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { PrintAndLogEx(SUCCESS, "found %u candidate key%s\n", keycount, (keycount > 1) ? "s." : "."); - *key = -1; + *key = UINT64_C(-1); uint8_t keyBlock[USB_CMD_DATA_SIZE]; - int max_keys = USB_CMD_DATA_SIZE / 6; - for (int i = 0; i < keycount; i += max_keys) { + uint32_t max_keys = USB_CMD_DATA_SIZE / 6; + for (uint32_t i = 0; i < keycount; i += max_keys) { - int size = keycount - i > max_keys ? max_keys : keycount - i; - for (int j = 0; j < size; j++) { + uint32_t size = keycount - i > max_keys ? max_keys : keycount - i; + for (uint32_t j = 0; j < size; j++) { if (par_list == 0) { num_to_bytes(last_keylist[i * max_keys + j], 6, keyBlock + (j * 6)); } else { @@ -108,7 +108,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { } } - if (*key != -1) { + if (*key != UINT64_C(-1)) { break; } else { PrintAndLogEx(FAILED, "all candidate keys failed. Restarting darkside attack"); diff --git a/client/proxgui.h b/client/proxgui.h index 613f793d1..2c0cf0601 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -28,11 +28,12 @@ void ExitGraphics(void); #define MAX_GRAPH_TRACE_LEN (40000 * 8) #endif extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; -extern int GraphTraceLen; +extern size_t GraphTraceLen; extern int s_Buff[MAX_GRAPH_TRACE_LEN]; extern double CursorScaleFactor; -extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos, GridOffset; +extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, GridOffset; +extern uint32_t CursorCPos, CursorDPos; extern int CommandFinished; extern int offline; extern bool GridLocked; diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 102b006ce..2cf2d0200 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -33,7 +33,7 @@ extern "C" { bool g_useOverlays = false; int g_absVMax = 0; -int startMax; +uint32_t startMax; int PageWidth; int unlockStart = 0; @@ -274,7 +274,7 @@ QColor Plot::getColor(int graphNum) { } } -void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect) { +void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) { if (len == 0) return; startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); if (startMax < 0) { @@ -285,7 +285,7 @@ void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect) { } if (GraphStart > len) return; int vMin = INT_MAX, vMax = INT_MIN, v = 0; - int sample_index = GraphStart ; + uint32_t sample_index = GraphStart ; for (; sample_index < len && xCoordOf(sample_index, plotRect) < plotRect.right() ; sample_index++) { v = buffer[sample_index]; @@ -299,7 +299,7 @@ void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect) { g_absVMax = (int)(g_absVMax * 1.25 + 1); } -void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset) { +void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, uint32_t plotOffset) { if (len == 0 || PlotGridX <= 0) return; //clock_t begin = clock(); QPainterPath penPath; @@ -354,11 +354,12 @@ void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotati painter->drawPath(penPath); } -void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum) { +void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum) { if (len == 0) return; // clock_t begin = clock(); QPainterPath penPath; - int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0; + int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0; + uint32_t i = 0; int x = xCoordOf(GraphStart, plotRect); int y = yCoordOf(buffer[GraphStart], plotRect, g_absVMax); penPath.moveTo(x, y); @@ -416,7 +417,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, //Graph annotations painter->drawPath(penPath); char str[200]; - sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]", + sprintf(str, "max=%d min=%d mean=%d n=%d/%zu CursorAVal=[%d] CursorBVal=[%d]", vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]); painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str); diff --git a/client/proxguiqt.h b/client/proxguiqt.h index fd6e00f13..6d92c22e7 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -31,17 +31,17 @@ class ProxWidget; class Plot: public QWidget { private: QWidget *master; - int GraphStart; + uint32_t GraphStart; double GraphPixelsPerPoint; - int CursorAPos; - int CursorBPos; - void PlotGraph(int *buffer, int len, QRect r, QRect r2, QPainter *painter, int graphNum); - void PlotDemod(uint8_t *buffer, size_t len, QRect r, QRect r2, QPainter *painter, int graphNum, int plotOffset); + uint32_t CursorAPos; + uint32_t CursorBPos; + void PlotGraph(int *buffer, size_t len, QRect r, QRect r2, QPainter *painter, int graphNum); + void PlotDemod(uint8_t *buffer, size_t len, QRect r, QRect r2, QPainter *painter, int graphNum, uint32_t plotOffset); void plotGridLines(QPainter *painter, QRect r); int xCoordOf(int i, QRect r); int yCoordOf(int v, QRect r, int maxVal); int valueOf_yCoord(int y, QRect r, int maxVal); - void setMaxAndStart(int *buffer, int len, QRect plotRect); + void setMaxAndStart(int *buffer, size_t len, QRect plotRect); QColor getColor(int graphNum); public: diff --git a/client/proxmark3.c b/client/proxmark3.c index 2794099c6..600d975e3 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -298,7 +298,7 @@ int main(int argc, char *argv[]) { return 1; } - uint32_t i = 1; + int i = 1; port = argv[i++]; for (; i < argc; i++) { diff --git a/client/ui.c b/client/ui.c index c72b46806..2725fe093 100644 --- a/client/ui.c +++ b/client/ui.c @@ -18,7 +18,8 @@ #include "ui.h" double CursorScaleFactor = 1; -int PlotGridX = 0, PlotGridY = 0, PlotGridXdefault = 64, PlotGridYdefault = 64, CursorCPos = 0, CursorDPos = 0; +int PlotGridX = 0, PlotGridY = 0, PlotGridXdefault = 64, PlotGridYdefault = 64; +uint32_t CursorCPos = 0, CursorDPos = 0; bool flushAfterWrite = 0; int GridOffset = 0; bool GridLocked = false; @@ -33,13 +34,13 @@ void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) { char buff[2000] = "Options:\n"; char format[2000] = ""; size_t counts[2] = {0, 0}; - for (int i = 0; i < size; i++) - for (int j = 0 ; j < 2 ; j++) + for (size_t i = 0; i < size; i++) + for (size_t j = 0 ; j < 2 ; j++) if (counts[j] < strlen(str[i][j])) { counts[j] = strlen(str[i][j]); } - for (int i = 0; i < size; i++) { - for (int j = 0; j < 2; j++) { + for (size_t i = 0; i < size; i++) { + for (size_t j = 0; j < 2; j++) { if (j == 0) snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]); else @@ -203,8 +204,6 @@ void SetFlushAfterWrite(bool value) { void iceIIR_Butterworth(int *data, const size_t len) { - int i, j; - int *output = (int *) calloc(sizeof(int) * len, sizeof(uint8_t)); if (!output) return; @@ -219,7 +218,7 @@ void iceIIR_Butterworth(int *data, const size_t len) { float b[3] = {0.003621681514929, 0.007243363029857, 0.003621681514929}; float a[3] = {1.000000000000000, -1.822694925196308, 0.837181651256023}; - for (i = 0; i < adjustedLen; ++i) { + for (size_t i = 0; i < adjustedLen; ++i) { float sample = data[i]; // input sample read from array float complex x_prime = 1.0f; // save sample for estimating frequency @@ -246,7 +245,7 @@ void iceIIR_Butterworth(int *data, const size_t len) { // show data //memcpy(data, output, adjustedLen); - for (j = 0; j < adjustedLen; ++j) + for (size_t j = 0; j < adjustedLen; ++j) data[j] = output[j]; free(output); @@ -260,7 +259,7 @@ void iceSimple_Filter(int *data, const size_t len, uint8_t k) { int32_t filter_reg = 0; int8_t shift = (k <= 8) ? k : FILTER_SHIFT; - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { // Update filter with current sample filter_reg = filter_reg - (filter_reg >> shift) + data[i]; diff --git a/client/ui.h b/client/ui.h index ca235c11f..574881918 100644 --- a/client/ui.h +++ b/client/ui.h @@ -41,7 +41,8 @@ void SetLogFilename(char *fn); void SetFlushAfterWrite(bool value); extern double CursorScaleFactor; -extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos, GridOffset; +extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, GridOffset; +extern uint32_t CursorCPos, CursorDPos; extern bool GridLocked; extern bool showDemod; diff --git a/client/util.c b/client/util.c index a71f79ffd..05e9d700c 100644 --- a/client/util.c +++ b/client/util.c @@ -160,7 +160,7 @@ int FillBuffer(uint8_t *data, size_t maxDataLength, size_t *dataLength, ...) { } bool CheckStringIsHEXValue(const char *value) { - for (int i = 0; i < strlen(value); i++) + for (size_t i = 0; i < strlen(value); i++) if (!isxdigit(value[i])) return false; @@ -177,17 +177,17 @@ void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex size_t i; memset(tmp, 0x00, hex_max_len); - int maxLen = (hex_len > hex_max_len) ? hex_max_len : hex_len; + size_t maxLen = (hex_len > hex_max_len) ? hex_max_len : hex_len; for (i = 0; i < maxLen; ++i, tmp += 2 + spaces_between) { sprintf(tmp, (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]); - for (int j = 0; j < spaces_between; j++) + for (size_t j = 0; j < spaces_between; j++) sprintf(tmp + 2 + j, " "); } i *= (2 + spaces_between); - int minStrLen = min_str_len > i ? min_str_len : 0; + size_t minStrLen = min_str_len > i ? min_str_len : 0; if (minStrLen > hex_max_len) minStrLen = hex_max_len; for (; i < minStrLen; i++, tmp += 1) @@ -198,8 +198,7 @@ void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex // printing and converting functions void print_hex(const uint8_t *data, const size_t len) { - size_t i; - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) printf("%02x ", data[i]); printf("\n"); } @@ -207,7 +206,7 @@ void print_hex(const uint8_t *data, const size_t len) { void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) { int rownum = 0; printf("[%02d] | ", rownum); - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { printf("%02X ", data[i]); @@ -246,7 +245,7 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea // make sure we don't go beyond our char array memory size_t in_index = 0, out_index = 0; - int rowlen = (len > MAX_BIN_BREAK_LENGTH) ? MAX_BIN_BREAK_LENGTH : len; + size_t rowlen = (len > MAX_BIN_BREAK_LENGTH) ? MAX_BIN_BREAK_LENGTH : len; if (breaks > 0 && len % breaks != 0) rowlen = (len + (len / breaks) > MAX_BIN_BREAK_LENGTH) ? MAX_BIN_BREAK_LENGTH : len + (len / breaks); @@ -351,7 +350,7 @@ char *sprint_ascii_ex(const uint8_t *data, const size_t len, const size_t min_st ++i; } - int m = min_str_len > i ? min_str_len : 0; + size_t m = min_str_len > i ? min_str_len : 0; for (; i < m; ++i) tmp[i] = ' '; @@ -399,7 +398,7 @@ void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest) { //least significant bit first void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest) { - for (int i = 0 ; i < len ; ++i) { + for (size_t i = 0 ; i < len ; ++i) { dest[i] = n & 1; n >>= 1; } @@ -876,7 +875,7 @@ int num_CPUs(void) { } void str_lower(char *s) { - for (int i = 0; i < strlen(s); i++) + for (size_t i = 0; i < strlen(s); i++) s[i] = tolower(s[i]); } bool str_startswith(const char *s, const char *pre) { diff --git a/common/crc.c b/common/crc.c index c3bd90064..e197c0eee 100644 --- a/common/crc.c +++ b/common/crc.c @@ -94,7 +94,7 @@ static void print_crc(crc_t *crc) { uint32_t CRC8Maxim(uint8_t *buff, size_t size) { crc_t crc; crc_init_ref(&crc, 8, 0x31, 0, 0, true, true); - for (int i = 0; i < size; ++i) + for (size_t i = 0; i < size; ++i) crc_update2(&crc, buff[i], 8); return crc_finish(&crc); } @@ -102,7 +102,7 @@ uint32_t CRC8Maxim(uint8_t *buff, size_t size) { uint32_t CRC8Mad(uint8_t *buff, size_t size) { crc_t crc; crc_init_ref(&crc, 8, 0x1d, 0xc7, 0, false, false); - for (int i = 0; i < size; ++i) + for (size_t i = 0; i < size; ++i) crc_update2(&crc, buff[i], 8); return crc_finish(&crc); } @@ -120,7 +120,7 @@ uint32_t CRC4Legic(uint8_t *buff, size_t size) { uint32_t CRC8Legic(uint8_t *buff, size_t size) { crc_t crc; crc_init_ref(&crc, 8, 0x63, 0x55, 0, true, true); - for (int i = 0; i < size; ++i) + for (size_t i = 0; i < size; ++i) crc_update2(&crc, buff[i], 8); return reflect8(crc_finish(&crc)); } diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 2c1dc1b3b..8ea8aa619 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -231,7 +231,7 @@ void uart_close(const serial_port sp) { } bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size_t *pszRxLen) { - int byteCount; + size_t byteCount; fd_set rfds; struct timeval tv;