scsi-disk: assert positive value to avoid compiler warning
PATCH 1/1 scsi-disk: assert positive value to avoid compiler warning
While investigating link-time-optimization, the compiler complained as
follows:
In function ‘scsi_disk_new_request_dump’,
inlined from ‘scsi_new_request.part.24’ at hw/scsi/scsi-disk.c:2549:9,
inlined from ‘scsi_new_request’ at hw/scsi/scsi-disk.c:2533:21:hw/scsi/scsi-disk.c:2523:19: error: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=] hw/scsi/scsi-disk.c: In function ‘scsi_new_request’:/usr/include/glib-2.0/glib/gmem.h:78:10: note: in a call to allocation function ‘g_malloc’ declared here
gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
Asserting that len is positive avoids this diagnostic. This assert is reasonable since the error case of scsi_cdb_length() has already been handled by a previous call to that function.
--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)
hw/scsi/scsi-disk.c +1 -0
@@ -2520,6 +2520,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)int len =scsi_cdb_length (buf);char *line_buffer, *p; +assert (len >0 ); line_buffer =g_malloc (len *5 +1 );for (i =0 , p = line_buffer; i < len; i++) {
Signature · 1 line
2.21.0
Quoted 25 lines · Bruce Rogers
While investigating link-time-optimization, the compiler complained as
follows:
In function ‘scsi_disk_new_request_dump’,
inlined from ‘scsi_new_request.part.24’ athw/scsi/scsi-disk.c:2549:9,
inlined from ‘scsi_new_request’ athw/scsi/scsi-disk.c:2533:21:hw/scsi/scsi-disk.c:2523:19: error: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]hw/scsi/scsi-disk.c: In function ‘scsi_new_request’:/usr/include/glib-2.0/glib/gmem.h:78:10: note: in a call to allocation function ‘g_malloc’ declared here
gpointerg_malloc(gsizen_bytes)G_GNUC_MALLOCG_GNUC_ALLOC_SIZE(1);Asserting that len is positive avoids this diagnostic. This assert is reasonable since the error case of
scsi_cdb_length()has already been handled by a previous call to that function.Signed-off-by Bruce Rogers <[email protected]>--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)hw/scsi/scsi-disk.c +0
-0
hw/scsi/scsi-disk.c static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) · line 2526
Quoted 7 lines
hw/scsi/scsi-disk.c +1
-0@@ -2520,6 +2520,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)int len =scsi_cdb_length (buf);char *line_buffer, *p; +assert (len >0 ); line_buffer =g_malloc (len *5 +1 );for (i =0 , p = line_buffer; i < len; i++) {