diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2020-07-25 11:10:14 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2020-07-26 09:28:23 +0200 |
commit | 1fef252d8101a5eeba700b85a0eca36f9cf3da62 (patch) | |
tree | c99a2ea3530aee76ba526be8d1bb513950795945 | |
parent | 7a90f9465be9640d14e670fb7dc33a29be9c46b7 (diff) | |
download | libqmi-1fef252d8101a5eeba700b85a0eca36f9cf3da62.tar.gz |
qmi-firmware-update: improve type checks for the chunk_i variable
Just so that coverity skips reporting unintended issues when the
guint16 value gets promoted to bigger signed int sizes.
(cherry picked from commit 121e8d655ceca389d0dc7b514aa529d986ed373f)
-rw-r--r-- | src/qmi-firmware-update/qfu-image.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/qmi-firmware-update/qfu-image.c b/src/qmi-firmware-update/qfu-image.c index 2352f43d..23621656 100644 --- a/src/qmi-firmware-update/qfu-image.c +++ b/src/qmi-firmware-update/qfu-image.c @@ -55,8 +55,10 @@ qfu_image_get_data_chunk_size (QfuImage *self, guint n_chunks; n_chunks = qfu_image_get_n_data_chunks (self); - if (chunk_i == (n_chunks - 1)) { - chunk_size = qfu_image_get_data_size (self) - (chunk_i * QFU_IMAGE_CHUNK_SIZE); + g_assert (chunk_i < n_chunks); + + if ((guint)chunk_i == (n_chunks - 1)) { + chunk_size = qfu_image_get_data_size (self) - ((gssize)chunk_i * QFU_IMAGE_CHUNK_SIZE); g_assert (chunk_size > 0); } else chunk_size = QFU_IMAGE_CHUNK_SIZE; @@ -100,7 +102,7 @@ qfu_image_read_data_chunk (QfuImage *self, } /* Compute chunk offset */ - chunk_offset = qfu_image_get_header_size (self) + (chunk_i * QFU_IMAGE_CHUNK_SIZE); + chunk_offset = qfu_image_get_header_size (self) + ((goffset)chunk_i * QFU_IMAGE_CHUNK_SIZE); g_debug ("[qfu-image] chunk #%u offset: %" G_GOFFSET_FORMAT " bytes", chunk_i, chunk_offset); /* Seek to the correct place: note that this is likely a noop if already in that offset */ |