comparison of integers of different signs [-Wsign-compare]

This commit is contained in:
Philippe Teuwen 2019-04-13 23:38:34 +02:00
commit 97676d3210
17 changed files with 85 additions and 86 deletions

View file

@ -1985,7 +1985,7 @@ static void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int
//old CmdFSKdemod adapted by marshmellow //old CmdFSKdemod adapted by marshmellow
//converts FSK to clear NRZ style wave. (or demodulates) //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; uint8_t ans = 0;
if (clk == 0 || LowToneFC == 0 || HighToneFC == 0) { if (clk == 0 || LowToneFC == 0 || HighToneFC == 0) {
int firstClockEdge = 0; int firstClockEdge = 0;
@ -2002,17 +2002,16 @@ static int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighTon
return 0; return 0;
} }
int i, j;
int LowTone[clk]; int LowTone[clk];
int HighTone[clk]; int HighTone[clk];
GetHiLoTone(LowTone, HighTone, clk, LowToneFC, HighToneFC); GetHiLoTone(LowTone, HighTone, clk, LowToneFC, HighToneFC);
// loop through ([all samples] - clk) // 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; 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) // 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]; lowSum += LowTone[j] * data[i + j];
highSum += HighTone[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 // now we have the abs( [average sample value per clk] * 100 ) for each tone
// loop through again [all samples] - clk - 16 // loop through again [all samples] - clk - 16
// note why 16??? is 16 the largest FC? changed to LowToneFC as that should be the > fc // 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; int lowTot = 0, highTot = 0;
// sum a field clock width of abs( [average sample values per clk] * 100) for each tone // 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); 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); highTot += (data[i + j] >> 16);
} }

View file

@ -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) { static void asn1_tag_dump_octet_string(const struct tlv *tlv, const struct asn1_tag *tag, FILE *f, int level, bool *needdump) {
*needdump = false; *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])) { if (!isspace(tlv->value[i]) && !isprint(tlv->value[i])) {
*needdump = true; *needdump = true;
break; 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) { static unsigned long asn1_value_integer(const struct tlv *tlv, unsigned start, unsigned end) {
unsigned long ret = 0; unsigned long ret = 0;
int i; unsigned i;
if (end > tlv->len * 2) if (end > tlv->len * 2)
return ret; return ret;
@ -222,7 +222,7 @@ static void asn1_tag_dump_integer(const struct tlv *tlv, const struct asn1_tag *
PRINT_INDENT(level); PRINT_INDENT(level);
if (tlv->len == 4) { if (tlv->len == 4) {
int32_t val = 0; 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]; val = (val << 8) + tlv->value[i];
fprintf(f, "\tvalue4b: %d\n", val); fprintf(f, "\tvalue4b: %d\n", val);
return; return;

View file

@ -150,7 +150,7 @@ fido2Desc_t fido2CmdGetInfoRespDesc[] = {
}; };
const char *fido2GetCmdErrorDescription(uint8_t errorCode) { 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) if (fido2Errors[i].ErrorCode == errorCode)
return fido2Errors[i].Description; return fido2Errors[i].Description;
@ -158,7 +158,7 @@ const char *fido2GetCmdErrorDescription(uint8_t errorCode) {
} }
const char *fido2GetCmdMemberDescription(uint8_t cmdCode, bool isResponse, int memberNum) { 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 && if (fido2CmdGetInfoRespDesc[i].Command == cmdCode &&
fido2CmdGetInfoRespDesc[i].PckType == (isResponse ? ptResponse : ptQuery) && fido2CmdGetInfoRespDesc[i].PckType == (isResponse ? ptResponse : ptQuery) &&
fido2CmdGetInfoRespDesc[i].MemberNumber == memberNum) fido2CmdGetInfoRespDesc[i].MemberNumber == memberNum)

View file

@ -10,7 +10,7 @@
#include "graph.h" #include "graph.h"
int GraphBuffer[MAX_GRAPH_TRACE_LEN]; int GraphBuffer[MAX_GRAPH_TRACE_LEN];
int GraphTraceLen; size_t GraphTraceLen;
int s_Buff[MAX_GRAPH_TRACE_LEN]; int s_Buff[MAX_GRAPH_TRACE_LEN];
/* write a manchester bit to the graph /* write a manchester bit to the graph
@ -30,8 +30,8 @@ void AppendGraph(bool redraw, int clock, int bit) {
} }
// clear out our graph window // clear out our graph window
int ClearGraph(bool redraw) { size_t ClearGraph(bool redraw) {
int gtl = GraphTraceLen; size_t gtl = GraphTraceLen;
memset(GraphBuffer, 0x00, GraphTraceLen); memset(GraphBuffer, 0x00, GraphTraceLen);
GraphTraceLen = 0; GraphTraceLen = 0;
if (redraw) if (redraw)
@ -41,7 +41,7 @@ int ClearGraph(bool redraw) {
// option '1' to save GraphBuffer any other to restore // option '1' to save GraphBuffer any other to restore
void save_restoreGB(uint8_t saveOpt) { void save_restoreGB(uint8_t saveOpt) {
static int SavedGB[MAX_GRAPH_TRACE_LEN]; static int SavedGB[MAX_GRAPH_TRACE_LEN];
static int SavedGBlen = 0; static size_t SavedGBlen = 0;
static bool GB_Saved = false; static bool GB_Saved = false;
static int SavedGridOffsetAdj = 0; static int SavedGridOffsetAdj = 0;
@ -67,7 +67,7 @@ void setGraphBuf(uint8_t *buff, size_t size) {
if (size > MAX_GRAPH_TRACE_LEN) if (size > MAX_GRAPH_TRACE_LEN)
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; GraphBuffer[i] = buff[i] - 128;
GraphTraceLen = size; GraphTraceLen = size;
@ -77,7 +77,7 @@ void setGraphBuf(uint8_t *buff, size_t size) {
size_t getFromGraphBuf(uint8_t *buff) { size_t getFromGraphBuf(uint8_t *buff) {
if (buff == NULL) return 0; if (buff == NULL) return 0;
uint32_t i; size_t i;
for (i = 0; i < GraphTraceLen; ++i) { for (i = 0; i < GraphTraceLen; ++i) {
//trim //trim
if (GraphBuffer[i] > 127) GraphBuffer[i] = 127; 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. // A simple test to see if there is any data inside Graphbuffer.
bool HasGraphData() { bool HasGraphData() {
if (GraphTraceLen <= 0) { if (GraphTraceLen == 0) {
PrintAndLogEx(NORMAL, "No data available, try reading something first"); PrintAndLogEx(NORMAL, "No data available, try reading something first");
return false; return false;
} }

View file

@ -19,7 +19,7 @@
#include "cmddata.h" //for g_debugmode #include "cmddata.h" //for g_debugmode
void AppendGraph(bool redraw, int clock, int bit); void AppendGraph(bool redraw, int clock, int bit);
int ClearGraph(bool redraw); size_t ClearGraph(bool redraw);
size_t getFromGraphBuf(uint8_t *buff); size_t getFromGraphBuf(uint8_t *buff);
int GetAskClock(const char *str, bool printAns); int GetAskClock(const char *str, bool printAns);
int GetPskClock(const char *str, bool printAns); int GetPskClock(const char *str, bool printAns);
@ -40,7 +40,7 @@ bool HasGraphData(void);
#define GRAPH_RESTORE 0 #define GRAPH_RESTORE 0
extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphBuffer[MAX_GRAPH_TRACE_LEN];
extern int GraphTraceLen; extern size_t GraphTraceLen;
extern int s_Buff[MAX_GRAPH_TRACE_LEN]; extern int s_Buff[MAX_GRAPH_TRACE_LEN];
#endif #endif

View file

@ -92,7 +92,6 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, si
int retval = 0; int retval = 0;
int blocks = datalen / blocksize; int blocks = datalen / blocksize;
uint16_t currblock = 1; uint16_t currblock = 1;
int i, j;
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10); int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
char *fileName = calloc(size, sizeof(char)); char *fileName = calloc(size, sizeof(char));
int num = 1; int num = 1;
@ -112,7 +111,7 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, si
goto out; goto out;
} }
for (i = 0; i < datalen; i++) { for (size_t i = 0; i < datalen; i++) {
fprintf(f, "%02X", data[i]); fprintf(f, "%02X", data[i]);
// no extra line in the end // no extra line in the end
@ -124,7 +123,7 @@ int saveFileEML(const char *preferredName, const char *suffix, uint8_t *data, si
// left overs // left overs
if (datalen % blocksize != 0) { if (datalen % blocksize != 0) {
int index = blocks * blocksize; 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]); fprintf(f, "%02X", data[index + j]);
} }
} }
@ -162,9 +161,9 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty
} }
case jsfCardMemory: { case jsfCardMemory: {
JsonSaveStr(root, "FileType", "mfcard"); 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}; char path[PATH_MAX_LENGTH] = {0};
sprintf(path, "$.blocks.%d", i); sprintf(path, "$.blocks.%zu", i);
JsonSaveBufAsHexCompact(root, path, &data[i * 16], 16); JsonSaveBufAsHexCompact(root, path, &data[i * 16], 16);
if (i == 0) { 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); JsonSaveBufAsHexCompact(root, path, &data[i * 16 + 6], 4);
memset(path, 0x00, sizeof(path)); 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)); JsonSaveStr(root, path, mfGetAccessConditionsDesc(0, adata));
memset(path, 0x00, sizeof(path)); 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)); JsonSaveStr(root, path, mfGetAccessConditionsDesc(1, adata));
memset(path, 0x00, sizeof(path)); 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)); JsonSaveStr(root, path, mfGetAccessConditionsDesc(2, adata));
memset(path, 0x00, sizeof(path)); 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)); JsonSaveStr(root, path, mfGetAccessConditionsDesc(3, adata));
memset(path, 0x00, sizeof(path)); memset(path, 0x00, sizeof(path));
@ -231,9 +230,9 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty
// size of header 48b // size of header 48b
size_t len = (datalen - DUMP_PREFIX_LENGTH) / 4; 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}; char path[PATH_MAX_LENGTH] = {0};
sprintf(path, "$.blocks.%d", i); sprintf(path, "$.blocks.%zu", i);
JsonSaveBufAsHexCompact(root, path, tmp->data + (i * 4), 4); JsonSaveBufAsHexCompact(root, path, tmp->data + (i * 4), 4);
} }
break; break;
@ -245,9 +244,9 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty
JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); 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}; char path[PATH_MAX_LENGTH] = {0};
sprintf(path, "$.blocks.%d", i); sprintf(path, "$.blocks.%zu", i);
JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4); JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4);
} }
break; break;
@ -470,14 +469,14 @@ int loadFileJSON(const char *preferredName, const char *suffix, void *data, size
if (!strcmp(ctype, "hitag")) { if (!strcmp(ctype, "hitag")) {
size_t sptr = 0; 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) { if (sptr + 4 > maxdatalen) {
retval = 5; retval = 5;
goto out; goto out;
} }
char path[30] = {0}; char path[30] = {0};
sprintf(path, "$.blocks.%d", i); sprintf(path, "$.blocks.%zu", i);
size_t len = 0; size_t len = 0;
JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len); JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len);

View file

@ -27,7 +27,7 @@ uint32_t intersection(uint64_t *listA, uint64_t *listB) {
p1 = p3 = listA; p1 = p3 = listA;
p2 = listB; p2 = listB;
while (*p1 != -1 && *p2 != -1) { while (*p1 != UINT64_C(-1) && *p2 != UINT64_C(-1)) {
if (compare_uint64(p1, p2) == 0) { if (compare_uint64(p1, p2) == 0) {
*p3++ = *p1++; *p3++ = *p1++;
p2++; p2++;
@ -36,7 +36,7 @@ uint32_t intersection(uint64_t *listA, uint64_t *listB) {
while (compare_uint64(p1, p2) > 0) ++p2; while (compare_uint64(p1, p2) > 0) ++p2;
} }
} }
*p3 = -1; *p3 = UINT64_C(-1);
return p3 - listA; return p3 - listA;
} }

View file

@ -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." : "."); 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]; uint8_t keyBlock[USB_CMD_DATA_SIZE];
int max_keys = USB_CMD_DATA_SIZE / 6; uint32_t max_keys = USB_CMD_DATA_SIZE / 6;
for (int i = 0; i < keycount; i += max_keys) { for (uint32_t i = 0; i < keycount; i += max_keys) {
int size = keycount - i > max_keys ? max_keys : keycount - i; uint32_t size = keycount - i > max_keys ? max_keys : keycount - i;
for (int j = 0; j < size; j++) { for (uint32_t j = 0; j < size; j++) {
if (par_list == 0) { if (par_list == 0) {
num_to_bytes(last_keylist[i * max_keys + j], 6, keyBlock + (j * 6)); num_to_bytes(last_keylist[i * max_keys + j], 6, keyBlock + (j * 6));
} else { } 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; break;
} else { } else {
PrintAndLogEx(FAILED, "all candidate keys failed. Restarting darkside attack"); PrintAndLogEx(FAILED, "all candidate keys failed. Restarting darkside attack");

View file

@ -28,11 +28,12 @@ void ExitGraphics(void);
#define MAX_GRAPH_TRACE_LEN (40000 * 8) #define MAX_GRAPH_TRACE_LEN (40000 * 8)
#endif #endif
extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphBuffer[MAX_GRAPH_TRACE_LEN];
extern int GraphTraceLen; extern size_t GraphTraceLen;
extern int s_Buff[MAX_GRAPH_TRACE_LEN]; extern int s_Buff[MAX_GRAPH_TRACE_LEN];
extern double CursorScaleFactor; 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 CommandFinished;
extern int offline; extern int offline;
extern bool GridLocked; extern bool GridLocked;

View file

@ -33,7 +33,7 @@ extern "C" {
bool g_useOverlays = false; bool g_useOverlays = false;
int g_absVMax = 0; int g_absVMax = 0;
int startMax; uint32_t startMax;
int PageWidth; int PageWidth;
int unlockStart = 0; 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; if (len == 0) return;
startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
if (startMax < 0) { if (startMax < 0) {
@ -285,7 +285,7 @@ void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect) {
} }
if (GraphStart > len) return; if (GraphStart > len) return;
int vMin = INT_MAX, vMax = INT_MIN, v = 0; 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++) { for (; sample_index < len && xCoordOf(sample_index, plotRect) < plotRect.right() ; sample_index++) {
v = buffer[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); 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; if (len == 0 || PlotGridX <= 0) return;
//clock_t begin = clock(); //clock_t begin = clock();
QPainterPath penPath; QPainterPath penPath;
@ -354,11 +354,12 @@ void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotati
painter->drawPath(penPath); 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; if (len == 0) return;
// clock_t begin = clock(); // clock_t begin = clock();
QPainterPath penPath; 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 x = xCoordOf(GraphStart, plotRect);
int y = yCoordOf(buffer[GraphStart], plotRect, g_absVMax); int y = yCoordOf(buffer[GraphStart], plotRect, g_absVMax);
penPath.moveTo(x, y); penPath.moveTo(x, y);
@ -416,7 +417,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
//Graph annotations //Graph annotations
painter->drawPath(penPath); painter->drawPath(penPath);
char str[200]; 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]); vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]);
painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str); painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);

View file

@ -31,17 +31,17 @@ class ProxWidget;
class Plot: public QWidget { class Plot: public QWidget {
private: private:
QWidget *master; QWidget *master;
int GraphStart; uint32_t GraphStart;
double GraphPixelsPerPoint; double GraphPixelsPerPoint;
int CursorAPos; uint32_t CursorAPos;
int CursorBPos; uint32_t CursorBPos;
void PlotGraph(int *buffer, int len, QRect r, QRect r2, QPainter *painter, int graphNum); 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, int plotOffset); 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); void plotGridLines(QPainter *painter, QRect r);
int xCoordOf(int i, QRect r); int xCoordOf(int i, QRect r);
int yCoordOf(int v, QRect r, int maxVal); int yCoordOf(int v, QRect r, int maxVal);
int valueOf_yCoord(int y, 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); QColor getColor(int graphNum);
public: public:

View file

@ -298,7 +298,7 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
uint32_t i = 1; int i = 1;
port = argv[i++]; port = argv[i++];
for (; i < argc; i++) { for (; i < argc; i++) {

View file

@ -18,7 +18,8 @@
#include "ui.h" #include "ui.h"
double CursorScaleFactor = 1; 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; bool flushAfterWrite = 0;
int GridOffset = 0; int GridOffset = 0;
bool GridLocked = false; 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 buff[2000] = "Options:\n";
char format[2000] = ""; char format[2000] = "";
size_t counts[2] = {0, 0}; size_t counts[2] = {0, 0};
for (int i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
for (int j = 0 ; j < 2 ; j++) for (size_t j = 0 ; j < 2 ; j++)
if (counts[j] < strlen(str[i][j])) { if (counts[j] < strlen(str[i][j])) {
counts[j] = strlen(str[i][j]); counts[j] = strlen(str[i][j]);
} }
for (int i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
for (int j = 0; j < 2; j++) { for (size_t j = 0; j < 2; j++) {
if (j == 0) if (j == 0)
snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]); snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]);
else else
@ -203,8 +204,6 @@ void SetFlushAfterWrite(bool value) {
void iceIIR_Butterworth(int *data, const size_t len) { void iceIIR_Butterworth(int *data, const size_t len) {
int i, j;
int *output = (int *) calloc(sizeof(int) * len, sizeof(uint8_t)); int *output = (int *) calloc(sizeof(int) * len, sizeof(uint8_t));
if (!output) return; 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 b[3] = {0.003621681514929, 0.007243363029857, 0.003621681514929};
float a[3] = {1.000000000000000, -1.822694925196308, 0.837181651256023}; 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 sample = data[i]; // input sample read from array
float complex x_prime = 1.0f; // save sample for estimating frequency 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 // show data
//memcpy(data, output, adjustedLen); //memcpy(data, output, adjustedLen);
for (j = 0; j < adjustedLen; ++j) for (size_t j = 0; j < adjustedLen; ++j)
data[j] = output[j]; data[j] = output[j];
free(output); free(output);
@ -260,7 +259,7 @@ void iceSimple_Filter(int *data, const size_t len, uint8_t k) {
int32_t filter_reg = 0; int32_t filter_reg = 0;
int8_t shift = (k <= 8) ? k : FILTER_SHIFT; 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 // Update filter with current sample
filter_reg = filter_reg - (filter_reg >> shift) + data[i]; filter_reg = filter_reg - (filter_reg >> shift) + data[i];

View file

@ -41,7 +41,8 @@ void SetLogFilename(char *fn);
void SetFlushAfterWrite(bool value); void SetFlushAfterWrite(bool value);
extern double CursorScaleFactor; 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 GridLocked;
extern bool showDemod; extern bool showDemod;

View file

@ -160,7 +160,7 @@ int FillBuffer(uint8_t *data, size_t maxDataLength, size_t *dataLength, ...) {
} }
bool CheckStringIsHEXValue(const char *value) { 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])) if (!isxdigit(value[i]))
return false; 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; size_t i;
memset(tmp, 0x00, hex_max_len); 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) { for (i = 0; i < maxLen; ++i, tmp += 2 + spaces_between) {
sprintf(tmp, (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]); 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, " "); sprintf(tmp + 2 + j, " ");
} }
i *= (2 + spaces_between); 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) if (minStrLen > hex_max_len)
minStrLen = hex_max_len; minStrLen = hex_max_len;
for (; i < minStrLen; i++, tmp += 1) 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 // printing and converting functions
void print_hex(const uint8_t *data, const size_t len) { void print_hex(const uint8_t *data, const size_t len) {
size_t i; for (size_t i = 0; i < len; i++)
for (i = 0; i < len; i++)
printf("%02x ", data[i]); printf("%02x ", data[i]);
printf("\n"); 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) { void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) {
int rownum = 0; int rownum = 0;
printf("[%02d] | ", rownum); printf("[%02d] | ", rownum);
for (int i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
printf("%02X ", data[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 // make sure we don't go beyond our char array memory
size_t in_index = 0, out_index = 0; 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) if (breaks > 0 && len % breaks != 0)
rowlen = (len + (len / breaks) > MAX_BIN_BREAK_LENGTH) ? MAX_BIN_BREAK_LENGTH : len + (len / breaks); 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; ++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) for (; i < m; ++i)
tmp[i] = ' '; tmp[i] = ' ';
@ -399,7 +398,7 @@ void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest) {
//least significant bit first //least significant bit first
void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest) { 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; dest[i] = n & 1;
n >>= 1; n >>= 1;
} }
@ -876,7 +875,7 @@ int num_CPUs(void) {
} }
void str_lower(char *s) { 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]); s[i] = tolower(s[i]);
} }
bool str_startswith(const char *s, const char *pre) { bool str_startswith(const char *s, const char *pre) {

View file

@ -94,7 +94,7 @@ static void print_crc(crc_t *crc) {
uint32_t CRC8Maxim(uint8_t *buff, size_t size) { uint32_t CRC8Maxim(uint8_t *buff, size_t size) {
crc_t crc; crc_t crc;
crc_init_ref(&crc, 8, 0x31, 0, 0, true, true); 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); crc_update2(&crc, buff[i], 8);
return crc_finish(&crc); 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) { uint32_t CRC8Mad(uint8_t *buff, size_t size) {
crc_t crc; crc_t crc;
crc_init_ref(&crc, 8, 0x1d, 0xc7, 0, false, false); 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); crc_update2(&crc, buff[i], 8);
return crc_finish(&crc); 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) { uint32_t CRC8Legic(uint8_t *buff, size_t size) {
crc_t crc; crc_t crc;
crc_init_ref(&crc, 8, 0x63, 0x55, 0, true, true); 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); crc_update2(&crc, buff[i], 8);
return reflect8(crc_finish(&crc)); return reflect8(crc_finish(&crc));
} }

View file

@ -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) { bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size_t *pszRxLen) {
int byteCount; size_t byteCount;
fd_set rfds; fd_set rfds;
struct timeval tv; struct timeval tv;