diff --git a/firehose.c b/firehose.c index e6e8953..f3fd153 100644 --- a/firehose.c +++ b/firehose.c @@ -341,7 +341,7 @@ static int firehose_try_configure(struct qdl_device *qdl, bool skip_storage_init size_t size = 0; void *buf; int ret; - int i; + unsigned int i; ret = firehose_send_configure(qdl, qdl->max_payload_size, skip_storage_init, storage, &size); @@ -454,6 +454,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int int left; int ret; int n; + size_t i; uint32_t fill_value; /* @@ -526,8 +527,8 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int break; case CHUNK_TYPE_FILL: fill_value = program->sparse_fill_value; - for (n = 0; n < qdl->max_payload_size; n += sizeof(fill_value)) - memcpy(buf + n, &fill_value, sizeof(fill_value)); + for (i = 0; i < qdl->max_payload_size; i += sizeof(fill_value)) + memcpy(buf + i, &fill_value, sizeof(fill_value)); break; default: ux_err("[SPARSE] invalid chunk type\n"); @@ -555,7 +556,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int goto out; } - if (n < qdl->max_payload_size) + if ((size_t)n < qdl->max_payload_size) memset(buf + n, 0, qdl->max_payload_size - n); } @@ -587,7 +588,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int goto out; } - if (n != chunk_size * sector_size) { + if ((size_t)n != chunk_size * sector_size) { ux_err("USB write truncated\n"); ret = -1; goto out; @@ -686,12 +687,12 @@ static int firehose_issue_read(struct qdl_device *qdl, struct read_op *read_op, continue; } else if (expect_empty) { err(1, "expected empty transfer but received non-empty transfer during read"); - } else if (n != chunk_size * sector_size) { + } else if ((size_t)n != chunk_size * sector_size) { err(1, "failed to read full sector"); } if (out_buf) { - if (n > out_len - out_offset) + if ((size_t)n > out_len - out_offset) n = out_len - out_offset; memcpy(out_buf + out_offset, buf, n); @@ -699,7 +700,7 @@ static int firehose_issue_read(struct qdl_device *qdl, struct read_op *read_op, } else { n = write(fd, buf, n); - if (n != chunk_size * sector_size) { + if (n < 0 || (size_t)n != chunk_size * sector_size) { err(1, "failed to write"); } } diff --git a/gpt.c b/gpt.c index 188e8e3..cec962d 100644 --- a/gpt.c +++ b/gpt.c @@ -145,7 +145,7 @@ static int gpt_load_table_from_partition(struct qdl_device *qdl, unsigned int ph uint16_t name_utf16le[36]; char name[36 * 4]; int ret; - int i; + unsigned int i; memset(&op, 0, sizeof(op)); diff --git a/sahara.c b/sahara.c index 501316b..f3bda42 100644 --- a/sahara.c +++ b/sahara.c @@ -180,7 +180,7 @@ static void sahara_read(struct qdl_device *qdl, struct sahara_pkt *pkt, } ret = qdl_write(qdl, image->ptr + offset, len, SAHARA_CMD_TIMEOUT_MS); - if (ret != len) + if (ret < 0 || ((size_t)ret != len)) err(1, "failed to write %zu bytes to sahara", len); } @@ -220,7 +220,7 @@ static void sahara_read64(struct qdl_device *qdl, struct sahara_pkt *pkt, } ret = qdl_write(qdl, image->ptr + offset, len, SAHARA_CMD_TIMEOUT_MS); - if (ret != len) + if (ret < 0 || ((size_t)ret != len)) err(1, "failed to write %zu bytes to sahara", len); } @@ -302,7 +302,7 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl, goto out; } - while (buf_offset < n) { + while (buf_offset < (size_t)n) { written = write(fd, buf + buf_offset, n - buf_offset); if (written <= 0) { warn("failed to write ramdump chunk to \"%s\"", region.filename); @@ -373,7 +373,7 @@ static void sahara_debug64(struct qdl_device *qdl, struct sahara_pkt *pkt, struct sahara_debug_region64 *table; struct sahara_pkt read_req; ssize_t n; - int i; + size_t i; assert(pkt->length == SAHARA_MEM_DEBUG64_LENGTH); @@ -455,7 +455,7 @@ int sahara_run(struct qdl_device *qdl, const struct sahara_image *images, } pkt = (struct sahara_pkt *)buf; - if (n != pkt->length) { + if ((uint32_t)n != pkt->length) { ux_err("request length not matching received request\n"); return -EINVAL; } diff --git a/util.c b/util.c index 36b0bcc..31da16b 100644 --- a/util.c +++ b/util.c @@ -39,8 +39,8 @@ void print_hex_dump(const char *prefix, const void *buf, size_t len) uint8_t ch; char line[16 * 3 + 16 + 1]; int li; - int i; - int j; + unsigned int i; + unsigned int j; for (i = 0; i < len; i += 16) { linelen = MIN(16, len - i); diff --git a/vip.c b/vip.c index 3637294..d2a97a5 100644 --- a/vip.c +++ b/vip.c @@ -395,7 +395,7 @@ int vip_transfer_init(struct qdl_device *qdl, const char *vip_table_path) out_cleanup: close(qdl->vip_data.signed_table_fd); - for (int i = 0; i < qdl->vip_data.chained_num - 1; ++i) + for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i) close(qdl->vip_data.chained_fds[i]); return -1; } @@ -403,7 +403,7 @@ int vip_transfer_init(struct qdl_device *qdl, const char *vip_table_path) void vip_transfer_deinit(struct qdl_device *qdl) { close(qdl->vip_data.signed_table_fd); - for (int i = 0; i < qdl->vip_data.chained_num - 1; ++i) + for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i) close(qdl->vip_data.chained_fds[i]); } @@ -412,7 +412,7 @@ static int vip_transfer_send_raw(struct qdl_device *qdl, int table_fd) struct stat sb; int ret; void *buf; - size_t n; + ssize_t n; ret = fstat(table_fd, &sb); if (ret < 0) {