Skip to content

Commit

Permalink
global: fix sign-compare warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
suda-morris committed Jan 12, 2021
1 parent 6504d89 commit 753a929
Show file tree
Hide file tree
Showing 103 changed files with 221 additions and 215 deletions.
2 changes: 1 addition & 1 deletion components/app_trace/app_trace.c
Expand Up @@ -880,7 +880,7 @@ static esp_err_t esp_apptrace_trax_status_reg_get(uint32_t *val)

static esp_err_t esp_apptrace_trax_dest_init(void)
{
for (int i = 0; i < ESP_APPTRACE_TRAX_BLOCKS_NUM; i++) {
for (size_t i = 0; i < ESP_APPTRACE_TRAX_BLOCKS_NUM; i++) {
s_trace_buf.trax.blocks[i].start = (uint8_t *)s_trax_blocks[i];
s_trace_buf.trax.blocks[i].sz = ESP_APPTRACE_TRAX_BLOCK_SIZE;
s_trace_buf.trax.state.markers[i] = 0;
Expand Down
2 changes: 1 addition & 1 deletion components/app_update/esp_ota_ops.c
Expand Up @@ -404,7 +404,7 @@ static esp_err_t esp_rewrite_ota_data(esp_partition_subtype_t subtype)
return ESP_ERR_NOT_FOUND;
}

int ota_app_count = get_ota_partition_count();
uint8_t ota_app_count = get_ota_partition_count();
if (SUB_TYPE_ID(subtype) >= ota_app_count) {
return ESP_ERR_INVALID_ARG;
}
Expand Down
Expand Up @@ -127,7 +127,7 @@ int uECC_verify_antifault(const uint8_t *public_key,
const uECC_word_t *mhash_words = (const uECC_word_t *)message_hash;
uECC_word_t *vhash_words = (uECC_word_t *)verified_hash;
unsigned hash_words = hash_size / sizeof(uECC_word_t);
for (int w = 0; w < hash_words; w++) {
for (unsigned int w = 0; w < hash_words; w++) {
/* note: using curve->num_words here to encourage compiler to re-read this variable */
vhash_words[w] = mhash_words[w] ^ rx[w % curve->num_words] ^ r[w % curve->num_words];
}
Expand Down
2 changes: 1 addition & 1 deletion components/bootloader_support/src/bootloader_common.c
Expand Up @@ -88,7 +88,7 @@ bool bootloader_common_label_search(const char *list, char *label)

// [start_delim] + label + [end_delim] was not found.
// Position is moving to next delimiter if it is not the end of list.
int pos_delim = strcspn(sub_list_start_like_label, ", ");
size_t pos_delim = strcspn(sub_list_start_like_label, ", ");
if (pos_delim == strlen(sub_list_start_like_label)) {
break;
}
Expand Down
Expand Up @@ -93,7 +93,7 @@ int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata,
}
int active_otadata = -1;
if (valid_two_otadata[0] && valid_two_otadata[1]) {
int condition = (max == true) ? MAX(two_otadata[0].ota_seq, two_otadata[1].ota_seq) : MIN(two_otadata[0].ota_seq, two_otadata[1].ota_seq);
uint32_t condition = (max == true) ? MAX(two_otadata[0].ota_seq, two_otadata[1].ota_seq) : MIN(two_otadata[0].ota_seq, two_otadata[1].ota_seq);
if (condition == two_otadata[0].ota_seq) {
active_otadata = 0;
} else {
Expand Down
2 changes: 1 addition & 1 deletion components/bootloader_support/src/bootloader_flash.c
Expand Up @@ -300,7 +300,7 @@ static esp_err_t bootloader_flash_read_allow_decrypt(size_t src_addr, void *dest
{
uint32_t *dest_words = (uint32_t *)dest;

for (int word = 0; word < size / 4; word++) {
for (size_t word = 0; word < size / 4; word++) {
uint32_t word_src = src_addr + word * 4; /* Read this offset from flash */
uint32_t map_at = word_src & MMU_FLASH_MASK; /* Map this 64KB block from flash */
uint32_t *map_ptr;
Expand Down
2 changes: 1 addition & 1 deletion components/bootloader_support/src/bootloader_random.c
Expand Up @@ -34,7 +34,7 @@

assert(buffer != NULL);

for (int i = 0; i < length; i++) {
for (size_t i = 0; i < length; i++) {
if (i == 0 || i % 4 == 0) { /* redundant check is for a compiler warning */
/* in bootloader with ADC feeding HWRNG, we accumulate 1
bit of entropy per 40 APB cycles (==80 CPU cycles.)
Expand Down
10 changes: 5 additions & 5 deletions components/bootloader_support/src/bootloader_utility.c
Expand Up @@ -230,7 +230,7 @@ static esp_partition_pos_t index_to_partition(const bootloader_state_t *bs, int
return bs->test;
}

if (index >= 0 && index < MAX_OTA_SLOTS && index < bs->app_count) {
if (index >= 0 && index < MAX_OTA_SLOTS && index < (int)bs->app_count) {
return bs->ota[index];
}

Expand Down Expand Up @@ -500,7 +500,7 @@ void bootloader_utility_load_boot_image(const bootloader_state_t *bs, int start_
}

/* failing that work forwards from start_index, try valid OTA slots */
for (index = start_index + 1; index < bs->app_count; index++) {
for (index = start_index + 1; index < (int)bs->app_count; index++) {
part = index_to_partition(bs, index);
if (part.size == 0) {
continue;
Expand Down Expand Up @@ -718,7 +718,7 @@ static void set_cache_and_start_app(
DPORT_PRO_FLASH_MMU_TABLE[i] = DPORT_FLASH_MMU_TABLE_INVALID_VAL;
}
#else
for (int i = 0; i < FLASH_MMU_TABLE_SIZE; i++) {
for (size_t i = 0; i < FLASH_MMU_TABLE_SIZE; i++) {
FLASH_MMU_TABLE[i] = MMU_TABLE_INVALID_VAL;
}
#endif
Expand Down Expand Up @@ -828,7 +828,7 @@ esp_err_t bootloader_sha256_hex_to_str(char *out_str, const uint8_t *in_array_he
if (out_str == NULL || in_array_hex == NULL || len == 0) {
return ESP_ERR_INVALID_ARG;
}
for (int i = 0; i < len; i++) {
for (size_t i = 0; i < len; i++) {
for (int shift = 0; shift < 2; shift++) {
uint8_t nibble = (in_array_hex[i] >> (shift ? 0 : 4)) & 0x0F;
if (nibble < 10) {
Expand All @@ -848,7 +848,7 @@ void bootloader_debug_buffer(const void *buffer, size_t length, const char *labe
const uint8_t *bytes = (const uint8_t *)buffer;
char hexbuf[length * 2 + 1];
hexbuf[length * 2] = 0;
for (int i = 0; i < length; i++) {
for (size_t i = 0; i < length; i++) {
for (int shift = 0; shift < 2; shift++) {
uint8_t nibble = (bytes[i] >> (shift ? 0 : 4)) & 0x0F;
if (nibble < 10) {
Expand Down
4 changes: 2 additions & 2 deletions components/bootloader_support/src/esp32/bootloader_sha.c
Expand Up @@ -55,7 +55,7 @@ void bootloader_sha256_data(bootloader_sha256_handle_t handle, const void *data,
while (REG_READ(SHA_256_BUSY_REG) != 0) { }

// Copy to memory block
for (int i = 0; i < copy_words; i++) {
for (size_t i = 0; i < copy_words; i++) {
sha_text_reg[block_count + i] = __builtin_bswap32(w[i]);
}
asm volatile ("memw");
Expand Down Expand Up @@ -117,7 +117,7 @@ void bootloader_sha256_finish(bootloader_sha256_handle_t handle, uint8_t *digest

uint32_t *digest_words = (uint32_t *)digest;
uint32_t *sha_text_reg = (uint32_t *)(SHA_TEXT_BASE);
for (int i = 0; i < DIGEST_WORDS; i++) {
for (size_t i = 0; i < DIGEST_WORDS; i++) {
digest_words[i] = __builtin_bswap32(sha_text_reg[i]);
}
asm volatile ("memw");
Expand Down
2 changes: 1 addition & 1 deletion components/bootloader_support/src/esp32/secure_boot.c
Expand Up @@ -76,7 +76,7 @@ static bool secure_boot_generate(uint32_t image_len){
ESP_LOGE(TAG, "bootloader_mmap(0x1000, 0x%x) failed", image_len);
return false;
}
for (int i = 0; i < image_len; i+= sizeof(digest.iv)) {
for (size_t i = 0; i < image_len; i+= sizeof(digest.iv)) {
ets_secure_boot_hash(&image[i/sizeof(uint32_t)]);
}
bootloader_munmap(image);
Expand Down
6 changes: 3 additions & 3 deletions components/bootloader_support/src/esp_image_format.c
Expand Up @@ -301,7 +301,7 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
uint32_t load_addr = data->segments[i].load_addr;
if (should_load(load_addr)) {
uint32_t *loaded = (uint32_t *)load_addr;
for (int j = 0; j < data->segments[i].data_len / sizeof(uint32_t); j++) {
for (size_t j = 0; j < data->segments[i].data_len / sizeof(uint32_t); j++) {
loaded[j] ^= (j & 1) ? ram_obfs_value[0] : ram_obfs_value[1];
}
}
Expand Down Expand Up @@ -555,7 +555,7 @@ static esp_err_t process_segment(int index, uint32_t flash_addr, esp_image_segme
uint32_t free_page_count = bootloader_mmap_get_free_pages();
ESP_LOGD(TAG, "free data page_count 0x%08x", free_page_count);

int32_t data_len_remain = data_len;
uint32_t data_len_remain = data_len;
while (data_len_remain > 0) {
#if SECURE_BOOT_CHECK_SIGNATURE && defined(BOOTLOADER_BUILD)
/* Double check the address verification done above */
Expand Down Expand Up @@ -619,7 +619,7 @@ static esp_err_t process_segment_data(intptr_t load_addr, uint32_t data_addr, ui

const uint32_t *src = data;

for (int i = 0; i < data_len; i += 4) {
for (size_t i = 0; i < data_len; i += 4) {
int w_i = i / 4; // Word index
uint32_t w = src[w_i];
if (checksum != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion components/bootloader_support/src/flash_partitions.c
Expand Up @@ -28,7 +28,7 @@ static const char *TAG = "flash_parts";
esp_err_t esp_partition_table_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions)
{
int md5_found = 0;
int num_parts;
size_t num_parts;
uint32_t chip_size = g_rom_flashchip.chip_size;
*num_partitions = 0;

Expand Down
2 changes: 1 addition & 1 deletion components/bootloader_support/src/flash_qio_mode.c
Expand Up @@ -123,7 +123,7 @@ void bootloader_enable_qio_mode(void)
uint32_t raw_flash_id;
uint8_t mfg_id;
uint16_t flash_id;
int i;
size_t i;

ESP_LOGD(TAG, "Probing for QIO mode enable...");
esp_rom_spiflash_wait_idle(&g_rom_flashchip);
Expand Down
4 changes: 2 additions & 2 deletions components/console/commands.c
Expand Up @@ -162,7 +162,7 @@ void esp_console_get_completion(const char *buf, linenoiseCompletions *lc)

const char *esp_console_get_hint(const char *buf, int *color, int *bold)
{
int len = strlen(buf);
size_t len = strlen(buf);
cmd_item_t *it;
SLIST_FOREACH(it, &s_cmd_list, next) {
if (strlen(it->command) == len &&
Expand All @@ -179,7 +179,7 @@ static const cmd_item_t *find_command_by_name(const char *name)
{
const cmd_item_t *cmd = NULL;
cmd_item_t *it;
int len = strlen(name);
size_t len = strlen(name);
SLIST_FOREACH(it, &s_cmd_list, next) {
if (strlen(it->command) == len &&
strcmp(name, it->command) == 0) {
Expand Down
37 changes: 26 additions & 11 deletions components/console/linenoise/linenoise.c
Expand Up @@ -238,6 +238,7 @@ static int getCursorPosition(void) {
* if it fails. */
static int getColumns(void) {
int start, cols;
int fd = fileno(stdout);

/* Get the initial position so we can restore it later. */
start = getCursorPosition();
Expand All @@ -253,7 +254,7 @@ static int getColumns(void) {
if (cols > start) {
char seq[32];
snprintf(seq,32,"\x1b[%dD",cols-start);
if (fwrite(seq, 1, strlen(seq), stdout) == -1) {
if (write(fd, seq, strlen(seq)) == -1) {
/* Can't recover... */
}
flushWrite();
Expand Down Expand Up @@ -298,6 +299,7 @@ static int completeLine(struct linenoiseState *ls) {
linenoiseCompletions lc = { 0, NULL };
int nread, nwritten;
char c = 0;
int in_fd = fileno(stdin);

completionCallback(ls->buf,&lc);
if (lc.len == 0) {
Expand All @@ -320,7 +322,7 @@ static int completeLine(struct linenoiseState *ls) {
refreshLine(ls);
}

nread = fread(&c, 1, 1, stdin);
nread = read(in_fd, &c, 1);
if (nread <= 0) {
freeCompletions(&lc);
return -1;
Expand Down Expand Up @@ -449,6 +451,7 @@ void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int plen) {
static void refreshSingleLine(struct linenoiseState *l) {
char seq[64];
size_t plen = l->plen;
int fd = fileno(stdout);
char *buf = l->buf;
size_t len = l->len;
size_t pos = l->pos;
Expand Down Expand Up @@ -478,7 +481,7 @@ static void refreshSingleLine(struct linenoiseState *l) {
/* Move cursor to original position. */
snprintf(seq,64,"\r\x1b[%dC", (int)(pos+plen));
abAppend(&ab,seq,strlen(seq));
if (fwrite(ab.b, ab.len, 1, stdout) == -1) {} /* Can't recover from write error. */
if (write(fd, ab.b, ab.len) == -1) {} /* Can't recover from write error. */
flushWrite();
abFree(&ab);
}
Expand All @@ -496,6 +499,7 @@ static void refreshMultiLine(struct linenoiseState *l) {
int col; /* colum position, zero-based. */
int old_rows = l->maxrows;
int j;
int fd = fileno(stdout);
struct abuf ab;

/* Update maxrows if needed. */
Expand Down Expand Up @@ -566,7 +570,7 @@ static void refreshMultiLine(struct linenoiseState *l) {
lndebug("\n");
l->oldpos = l->pos;

if (fwrite(ab.b,ab.len,1,stdout) == -1) {} /* Can't recover from write error. */
if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
flushWrite();
abFree(&ab);
}
Expand All @@ -584,6 +588,7 @@ static void refreshLine(struct linenoiseState *l) {
*
* On error writing to the terminal -1 is returned, otherwise 0. */
int linenoiseEditInsert(struct linenoiseState *l, char c) {
int fd = fileno(stdout);
if (l->len < l->buflen) {
if (l->len == l->pos) {
l->buf[l->pos] = c;
Expand All @@ -593,7 +598,9 @@ int linenoiseEditInsert(struct linenoiseState *l, char c) {
if ((!mlmode && l->plen+l->len < l->cols && !hintsCallback)) {
/* Avoid a full update of the line in the
* trivial case. */
if (fwrite(&c,1,1,stdout) == -1) return -1;
if (write(fd, &c,1) == -1) {
return -1;
}
flushWrite();
} else {
refreshLine(l);
Expand Down Expand Up @@ -717,6 +724,8 @@ void linenoiseEditDeletePrevWord(struct linenoiseState *l) {
static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
{
struct linenoiseState l;
int out_fd = fileno(stdout);
int in_fd = fileno(stdin);

/* Populate the linenoise state that we pass to functions implementing
* specific editing functionalities. */
Expand All @@ -739,7 +748,9 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
linenoiseHistoryAdd("");

int pos1 = getCursorPosition();
if (fwrite(prompt,l.plen,1,stdout) == -1) return -1;
if (write(out_fd, prompt,l.plen) == -1) {
return -1;
}
flushWrite();
int pos2 = getCursorPosition();
if (pos1 >= 0 && pos2 >= 0) {
Expand All @@ -750,7 +761,7 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
int nread;
char seq[3];

nread = fread(&c, 1, 1, stdin);
nread = read(in_fd, &c, 1);
if (nread <= 0) return l.len;

/* Only autocomplete when the callback is set. It returns < 0 when
Expand Down Expand Up @@ -819,13 +830,17 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
break;
case ESC: /* escape sequence */
/* Read the next two bytes representing the escape sequence. */
if (fread(seq, 1, 2, stdin) < 2) break;
if (read(in_fd, seq, 2) < 2) {
break;
}

/* ESC [ sequences. */
if (seq[0] == '[') {
if (seq[1] >= '0' && seq[1] <= '9') {
/* Extended escape, read additional byte. */
if (fread(seq+2, 1, 1, stdin) == -1) break;
if (read(in_fd, seq+2, 1) == -1) {
break;
}
if (seq[2] == '~') {
switch(seq[1]) {
case '3': /* Delete key. */
Expand Down Expand Up @@ -924,7 +939,7 @@ int linenoiseProbe(void) {
while (timeout_ms > 0 && read_bytes < 4) { // response is ESC[0n or ESC[3n
usleep(10000);
char c;
int cb = fread(&c, 1, 1, stdin);
int cb = read(stdin_fileno, &c, 1);
read_bytes += cb;
timeout_ms--;
}
Expand Down Expand Up @@ -957,7 +972,7 @@ static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
static int linenoiseDumb(char* buf, size_t buflen, const char* prompt) {
/* dumb terminal, fall back to fgets */
fputs(prompt, stdout);
int count = 0;
size_t count = 0;
while (count < buflen) {
int c = fgetc(stdin);
if (c == '\n') {
Expand Down
2 changes: 1 addition & 1 deletion components/console/split_argv.c
Expand Up @@ -44,7 +44,7 @@ size_t esp_console_split_argv(char *line, char **argv, size_t argv_size)
const int ESCAPE = '\\';
const int SPACE = ' ';
split_state_t state = SS_SPACE;
int argc = 0;
size_t argc = 0;
char *next_arg_start = line;
char *out_ptr = line;
for (char *in_ptr = line; argc < argv_size - 1; ++in_ptr) {
Expand Down
2 changes: 1 addition & 1 deletion components/driver/esp32s2/rtc_tempsensor.c
Expand Up @@ -92,7 +92,7 @@ esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens)
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
tsens->dac_offset = REGI2C_READ_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC);
for (int i = TSENS_DAC_L0; i < TSENS_DAC_MAX; i++) {
if (tsens->dac_offset == dac_offset[i].set_val) {
if ((int)tsens->dac_offset == dac_offset[i].set_val) {
tsens->dac_offset = dac_offset[i].index;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion components/driver/esp32s2/touch_sensor.c
Expand Up @@ -75,7 +75,7 @@ static void touch_pad_workaround_isr_internal(void *arg)
{
uint16_t ch_mask = 0;
uint32_t intr_mask = touch_hal_read_intr_status_mask();
uint32_t pad_num = touch_hal_get_current_meas_channel();
int pad_num = touch_hal_get_current_meas_channel();
/* Make sure that the scan done interrupt is generated after the last channel measurement is completed. */
if (intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) {
touch_hal_get_channel_mask(&ch_mask);
Expand Down

0 comments on commit 753a929

Please sign in to comment.