Skip to contentSkip to conversation

megasas: Fix MinGW compiler warning caused by illegal type cast

PATCH In review Stefan Weil 3 participants 4 messages Aug 23, 2012 – Aug 24, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 megasas: Fix MinGW compiler warning caused by illegal type cast

Type casts from pointer to integer values must use uintptr_t instead of unsigned long. Otherwise the compiler complains on hosts with sizeof(pointer) != sizeof(long).

The patch also replace magic number 32 by sizeof(info.serial_number) which has the same value but is better for code reviews.

---
 hw/megasas.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/megasas.c +2 -2
index c35a15d..f2d6783 100644
@@ -698,8 +698,8 @@ static int megasas_ctrl_get_info(MegasasState *s, MegasasCmd *cmd)
     }
 
     memcpy(info.product_name, "MegaRAID SAS 8708EM2", 20);
-    snprintf(info.serial_number, 32, "QEMU%08lx",
-             (unsigned long)s & 0xFFFFFFFF);
+    snprintf(info.serial_number, sizeof(info.serial_number),
+             "QEMU%08" PRIxPTR, (uintptr_t)s & 0xFFFFFFFF);
     snprintf(info.package_version, 0x60, "%s-QEMU", QEMU_VERSION);
     memcpy(info.image_component[0].name, "APP", 3);
     memcpy(info.image_component[0].version, MEGASAS_VERSION "-QEMU", 9);
Signature · 1 line
1.7.10
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Stefan Weil

Type casts from pointer to integer values must use uintptr_t instead of unsigned long. Otherwise the compiler complains on hosts with sizeof(pointer) != sizeof(long).

The patch also replace magic number 32 by sizeof(info.serial_number) which has the same value but is better for code reviews.

Sigh. I never seem to get the hang of typecasting.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      zSeries & Storage
[email protected]			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)
#2 lore raw

Il 24/08/2012 10:31, Hannes Reinecke ha scritto:

Quoted 5 lines
Quoted 5 lines

Type casts from pointer to integer values must use uintptr_t instead of unsigned long. Otherwise the compiler complains on hosts with sizeof(pointer) != sizeof(long).

Quoted 8 lines
Quoted 4 lines

The patch also replace magic number 32 by sizeof(info.serial_number) which has the same value but is better for code reviews.

Sigh. I never seem to get the hang of typecasting.

Nope, this needs to be fixed using the same scheme that you used for SAS addresses. Quick before Anthony notices and disables MEGASAS. :)

Paolo

#3 lore raw
Quoted 9 lines · Paolo Bonzini

Il 24/08/2012 10:31, Hannes Reinecke ha scritto:

Quoted 8 lines
Quoted 8 lines

Type casts from pointer to integer values must use uintptr_t instead of unsigned long. Otherwise the compiler complains on hosts with sizeof(pointer) != sizeof(long).

The patch also replace magic number 32 by sizeof(info.serial_number) which has the same value but is better for code reviews.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Sigh. I never seem to get the hang of typecasting.

Nope, this needs to be fixed using the same scheme that you used for SAS addresses. Quick before Anthony notices and disables MEGASAS. :)

Ok, done.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      zSeries & Storage
[email protected]			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)