fix some CodeQL warnings

This commit is contained in:
Philippe Teuwen 2022-02-16 20:28:38 +01:00
parent 8082cbbdcb
commit 623169fe02
15 changed files with 25 additions and 27 deletions

View file

@ -2104,7 +2104,7 @@ void printMFUdumpEx(mfu_dump_t *card, uint16_t pages, uint8_t startpage) {
PrintAndLogEx(INFO, "DYNAMIC LOCK: %s", sprint_hex(lockbytes_dyn, 3));
}
for (uint8_t i = 0; i < pages; ++i) {
for (uint16_t i = 0; i < pages; ++i) {
if (i < 3) {
PrintAndLogEx(INFO, "%3d/0x%02X | %s| | %s", i + startpage, i + startpage, sprint_hex(data + i * 4, 4), sprint_ascii(data + i * 4, 4));
continue;

View file

@ -174,7 +174,7 @@ static int CmdLFTune(const char *Cmd) {
print_progress(0, max, style);
// loop forever (till button pressed) if iter = 0 (default)
for (uint8_t i = 0; iter == 0 || i < iter; i++) {
for (uint32_t i = 0; iter == 0 || i < iter; i++) {
if (kbd_enter_pressed()) {
break;
}
@ -840,13 +840,13 @@ int lfsim_upload_gb(void) {
//can send only 512 bits at a time (1 byte sent per bit...)
PrintAndLogEx(INFO, "." NOLF);
for (uint16_t i = 0; i < g_GraphTraceLen; i += PM3_CMD_DATA_SIZE - 3) {
for (size_t i = 0; i < g_GraphTraceLen; i += PM3_CMD_DATA_SIZE - 3) {
size_t len = MIN((g_GraphTraceLen - i), PM3_CMD_DATA_SIZE - 3);
clearCommandBuffer();
payload_up.offset = i;
for (uint16_t j = 0; j < len; j++)
for (size_t j = 0; j < len; j++)
payload_up.data[j] = g_GraphBuffer[i + j];
SendCommandNG(CMD_LF_UPLOAD_SIM_SAMPLES, (uint8_t *)&payload_up, sizeof(struct pupload));

View file

@ -201,7 +201,7 @@ static int CmdIdteckSim(const char *Cmd) {
memset(bs, 0x00, sizeof(bs));
uint8_t counter = 0;
for (int8_t i = 0; i < raw_len; i++) {
for (int32_t i = 0; i < raw_len; i++) {
uint8_t tmp = raw[i];
bs[counter++] = (tmp >> 7) & 1;
bs[counter++] = (tmp >> 6) & 1;

View file

@ -586,7 +586,7 @@ static int CmdIndalaSim(const char *Cmd) {
memset(bs, 0x00, sizeof(bs));
uint8_t counter = 0;
for (int8_t i = 0; i < raw_len; i++) {
for (int32_t i = 0; i < raw_len; i++) {
uint8_t tmp = raw[i];
bs[counter++] = (tmp >> 7) & 1;
bs[counter++] = (tmp >> 6) & 1;

View file

@ -102,7 +102,7 @@ int demodParadox(bool verbose) {
uint8_t error = 0;
// Remove manchester encoding from FSK bits, skip pre
for (uint8_t i = idx + PARADOX_PREAMBLE_LEN; i < (idx + 96); i += 2) {
for (uint32_t i = idx + PARADOX_PREAMBLE_LEN; i < (idx + 96); i += 2) {
// not manchester data
if (bits[i] == bits[i + 1]) {

View file

@ -296,7 +296,7 @@ bool t55xxAcquireAndCompareBlock0(bool usepwd, uint32_t password, uint32_t known
continue;
}
for (uint16_t i = 0; i < g_DemodBufferLen - 32; i++) {
for (size_t i = 0; i < g_DemodBufferLen - 32; i++) {
uint32_t tmp = PackBits(i, 32, g_DemodBuffer);
if (tmp == known_block0) {
config.offset = i;
@ -4091,7 +4091,7 @@ static int CmdT55xxSniff(const char *Cmd) {
// We auto find widths
if ((width0 == 0) && (width1 == 0)) {
// We ignore bit 0 for the moment as it may be a ref. pulse, so check last
uint8_t ii = 2;
uint32_t ii = 2;
minWidth = pulseBuffer[1];
maxWidth = pulseBuffer[1];
bool done = false;

View file

@ -35,7 +35,7 @@ static int CmdHelp(const char *Cmd);
// trace pointer
static uint8_t *gs_trace;
static long gs_traceLen = 0;
static uint16_t gs_traceLen = 0;
static bool is_last_record(uint16_t tracepos, uint16_t traceLen) {
return ((tracepos + TRACELOG_HDR_LEN) >= traceLen);

View file

@ -1645,7 +1645,7 @@ static int filelist(const char *path, const char *ext, uint8_t last, bool tentat
PrintAndLogEx(NORMAL, "%s── "_GREEN_("%s"), last ? "" : "", &path[strip]);
for (uint16_t i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
char tmp_fullpath[1024] = {0};
strncat(tmp_fullpath, path, sizeof(tmp_fullpath) - 1);

View file

@ -33,7 +33,7 @@ TODO, verfy that this doesn't overflow buffer (iceman)
*/
void AppendGraph(bool redraw, uint16_t clock, int bit) {
uint8_t half = clock / 2;
uint8_t i;
uint16_t i;
//set first half the clock bit (all 1's or 0's for a 0 or 1 bit)
for (i = 0; i < half; ++i)
g_GraphBuffer[g_GraphTraceLen++] = bit;

View file

@ -126,15 +126,13 @@ uint64_t x_bytes_to_num(uint8_t *src, size_t len) {
}
void reverse_arraybytes(uint8_t *arr, size_t len) {
uint8_t i;
for (i = 0; i < len ; i++) {
for (size_t i = 0; i < len ; i++) {
arr[i] = reflect8(arr[i]);
}
}
void reverse_arraycopy(uint8_t *arr, uint8_t *dest, size_t len) {
uint8_t i;
for (i = 0; i < len ; i++) {
for (size_t i = 0; i < len ; i++) {
dest[i] = reflect8(arr[i]);
}
}

View file

@ -445,7 +445,7 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
loclass_thread_arg_t args[loclass_tc];
// init thread arguments
for (int i = 0; i < loclass_tc; i++) {
for (size_t i = 0; i < loclass_tc; i++) {
args[i].thread_idx = i;
args[i].numbytes_to_recover = numbytes_to_recover;
args[i].endmask = 1 << 8 * numbytes_to_recover;
@ -458,7 +458,7 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
pthread_t threads[loclass_tc];
// create threads
for (int i = 0; i < loclass_tc; i++) {
for (size_t i = 0; i < loclass_tc; i++) {
int res = pthread_create(&threads[i], NULL, bf_thread, (void *)&args[i]);
if (res) {
PrintAndLogEx(NORMAL, "");
@ -468,7 +468,7 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
}
// wait for threads to terminate:
void *ptrs[loclass_tc];
for (int i = 0; i < loclass_tc; i++)
for (size_t i = 0; i < loclass_tc; i++)
pthread_join(threads[i], &ptrs[i]);
// was it a success?
@ -493,7 +493,7 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) {
keytable[bytes_to_recover[i]] &= 0xFF;
keytable[bytes_to_recover[i]] |= LOCLASS_CRACKED;
}
for (uint8_t i = 0; i < loclass_tc; i++) {
for (size_t i = 0; i < loclass_tc; i++) {
free(ptrs[i]);
}
}

View file

@ -426,7 +426,7 @@ void memcpy_filter_rlmarkers(void *dest, const void *src, size_t n) {
uint8_t *rdest = (uint8_t *)dest;
uint8_t *rsrc = (uint8_t *)src;
uint16_t si = 0;
for (uint16_t i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
if ((rsrc[i] == '\001') || (rsrc[i] == '\002'))
// skip readline special markers
continue;
@ -440,7 +440,7 @@ void memcpy_filter_ansi(void *dest, const void *src, size_t n, bool filter) {
uint8_t *rdest = (uint8_t *)dest;
uint8_t *rsrc = (uint8_t *)src;
uint16_t si = 0;
for (uint16_t i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
if ((i < n - 1)
&& (rsrc[i] == '\x1b')
&& (rsrc[i + 1] >= 0x40)
@ -531,7 +531,7 @@ void memcpy_filter_emoji(void *dest, const void *src, size_t n, emojiMode_t mode
char *rdest = (char *)dest;
char *rsrc = (char *)src;
uint16_t si = 0;
for (uint16_t i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
current_char = rsrc[i];
if (current_token_length == 0) {

View file

@ -280,8 +280,8 @@ void print_blocks(uint32_t *data, size_t len) {
if (!data) {
PrintAndLogEx(ERR, "..empty data");
} else {
for (uint8_t i = 0; i < len; i++)
PrintAndLogEx(SUCCESS, " %02d | %08X", i, data[i]);
for (size_t i = 0; i < len; i++)
PrintAndLogEx(SUCCESS, " %02zd | %08X", i, data[i]);
}
}

View file

@ -163,7 +163,7 @@ uint32_t CRC8Hitag1Bits(const uint8_t *buff, size_t bitsize) {
uint8_t data = 0;
uint8_t n = 0;
crc_init_ref(&crc, 8, 0x1d, 0xff, 0, false, false);
uint8_t i;
size_t i;
for (i = 0; i < bitsize; i++) {
data <<= 1;
data += (buff[i / 8] >> (7 - (i % 8))) & 1;

View file

@ -701,7 +701,7 @@ int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr) {
}
size_t i = 1;
uint16_t num_clks = 9;
uint8_t num_clks = 9;
// first 255 value pos0 is placeholder for user inputed clock.
uint16_t clk[] = {255, 8, 16, 32, 40, 50, 64, 100, 128, 255};