diff mbox

[2/2] qdev: fix OVERFLOW_BEFORE_WIDEN

Message ID 1435024385-9084-3-git-send-email-arei.gonglei@huawei.com
State New
Headers show

Commit Message

Gonglei (Arei) June 23, 2015, 1:53 a.m. UTC
From: Gonglei <arei.gonglei@huawei.com>

Potentially overflowing expression "1 << prop->bitnr" with
type "int" (32 bits, signed) is evaluated using 32-bit arithmetic,
and then used in a context that expects an expression of type
"uint64_t" (64 bits, unsigned).

Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/core/qdev-properties.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Markus Armbruster June 23, 2015, 7:37 a.m. UTC | #1
<arei.gonglei@huawei.com> writes:

> From: Gonglei <arei.gonglei@huawei.com>
>
> Potentially overflowing expression "1 << prop->bitnr" with
> type "int" (32 bits, signed) is evaluated using 32-bit arithmetic,
> and then used in a context that expects an expression of type
> "uint64_t" (64 bits, unsigned).
>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/core/qdev-properties.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index a1606de..f78b335 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -130,7 +130,7 @@ PropertyInfo qdev_prop_bit = {
>  static uint64_t qdev_get_prop_mask64(Property *prop)
>  {
>      assert(prop->info == &qdev_prop_bit);
> -    return 0x1 << prop->bitnr;
> +    return 0x1ull << prop->bitnr;
>  }
>  
>  static void bit64_prop_set(DeviceState *dev, Property *props, bool val)

In my opionion, the 0x in 0x1ull is pure noise :)
Gerd Hoffmann June 23, 2015, 7:48 a.m. UTC | #2
On Di, 2015-06-23 at 09:53 +0800, arei.gonglei@huawei.com wrote:
>  static uint64_t qdev_get_prop_mask64(Property *prop)
>  {
>      assert(prop->info == &qdev_prop_bit);
> -    return 0x1 << prop->bitnr;
> +    return 0x1ull << prop->bitnr;
>  }

Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
diff mbox

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index a1606de..f78b335 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -130,7 +130,7 @@  PropertyInfo qdev_prop_bit = {
 static uint64_t qdev_get_prop_mask64(Property *prop)
 {
     assert(prop->info == &qdev_prop_bit);
-    return 0x1 << prop->bitnr;
+    return 0x1ull << prop->bitnr;
 }
 
 static void bit64_prop_set(DeviceState *dev, Property *props, bool val)