diff mbox

acpi: dmar: fix portability warning from cppcheck on void * cast

Message ID 1469478983-56440-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King July 25, 2016, 8:36 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Minor fix, ensure we don't do void * pointer arithmeti as the behaviour
is undefined (even though most compilers assume it is a char * sized).
Cast to char * before doing the addition.

Fixes cppcheck portability warning:

[src/acpi/dmar/dmar.c:281]: (portability) '(void*)header' is of type 'void *'.
When using void pointers in calculations, the behaviour is undefined.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/dmar/dmar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Alex Hung Aug. 17, 2016, 9:56 a.m. UTC | #1
On 2016-07-26 04:36 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Minor fix, ensure we don't do void * pointer arithmeti as the behaviour
> is undefined (even though most compilers assume it is a char * sized).
> Cast to char * before doing the addition.
>
> Fixes cppcheck portability warning:
>
> [src/acpi/dmar/dmar.c:281]: (portability) '(void*)header' is of type 'void *'.
> When using void pointers in calculations, the behaviour is undefined.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/dmar/dmar.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/acpi/dmar/dmar.c b/src/acpi/dmar/dmar.c
> index 899d366..6dbc1f3 100644
> --- a/src/acpi/dmar/dmar.c
> +++ b/src/acpi/dmar/dmar.c
> @@ -278,7 +278,8 @@ static int dmar_acpi_table_check(fwts_framework *fw)
>  			failed++;
>  			break;
>  		}
> -		header = ((void *)header) + header->length;
> +		header = (struct acpi_dmar_entry_header *)
> +				(((char *)header) + header->length);
>  	}
>
>  	if (!failed)
>


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Aug. 18, 2016, 2:28 a.m. UTC | #2
On 2016年07月26日 04:36, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Minor fix, ensure we don't do void * pointer arithmeti as the behaviour
> is undefined (even though most compilers assume it is a char * sized).
> Cast to char * before doing the addition.
>
> Fixes cppcheck portability warning:
>
> [src/acpi/dmar/dmar.c:281]: (portability) '(void*)header' is of type 'void *'.
> When using void pointers in calculations, the behaviour is undefined.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/dmar/dmar.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/acpi/dmar/dmar.c b/src/acpi/dmar/dmar.c
> index 899d366..6dbc1f3 100644
> --- a/src/acpi/dmar/dmar.c
> +++ b/src/acpi/dmar/dmar.c
> @@ -278,7 +278,8 @@ static int dmar_acpi_table_check(fwts_framework *fw)
>  			failed++;
>  			break;
>  		}
> -		header = ((void *)header) + header->length;
> +		header = (struct acpi_dmar_entry_header *)
> +				(((char *)header) + header->length);
>  	}
>
>  	if (!failed)
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/acpi/dmar/dmar.c b/src/acpi/dmar/dmar.c
index 899d366..6dbc1f3 100644
--- a/src/acpi/dmar/dmar.c
+++ b/src/acpi/dmar/dmar.c
@@ -278,7 +278,8 @@  static int dmar_acpi_table_check(fwts_framework *fw)
 			failed++;
 			break;
 		}
-		header = ((void *)header) + header->length;
+		header = (struct acpi_dmar_entry_header *)
+				(((char *)header) + header->length);
 	}
 
 	if (!failed)