From: Pierre Gondois <pierre.gond...@arm.com>

By default, gcc allows void* pointer arithmetic.
This is a GCC extension.
However, the C reference manual states that void*
pointer "cannot be operands of addition or subtraction
operators". Cf s5.3.1 "Generic Pointers".

This patch adds casts to avoid doing void* pointer arithmetic.

Signed-off-by: Pierre Gondois <pierre.gond...@arm.com>
---

The changes can be seen at: 
https://github.com/PierreARM/edk2-platforms/commits/Casts_avoiding_void_pointer_arith_v1

Notes:
    v1:
     - Use casts to avoid void* pointer arithmetic. [Pierre]

 Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c                  
                       | 14 +++++++++++---
 
Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
 |  3 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c 
b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c
index 
c9fc4d6e2d8e495a39a2edf24490dfea424d14e5..25cc1ac2b12f67a254799be1b57620466fd8dd6d
 100644
--- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c
+++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c
@@ -2,6 +2,7 @@
 
   Copyright (c) 2016 Socionext Inc. All rights reserved.<BR>
   Copyright (c) 2017, Linaro, Ltd. All rights reserved.<BR>
+  Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -774,11 +775,18 @@ SnpTransmit (
     // Copy destination address
     CopyMem (BufAddr, (VOID *)DstAddr, NET_ETHER_ADDR_LEN);
     // Copy source address
-    CopyMem (BufAddr + NET_ETHER_ADDR_LEN, (VOID *)SrcAddr, 
NET_ETHER_ADDR_LEN);
+    CopyMem (
+      (VOID*)((UINTN)BufAddr + NET_ETHER_ADDR_LEN),
+      (VOID*)SrcAddr,
+      NET_ETHER_ADDR_LEN
+      );
     // Copy protocol
     Proto = HTONS (*Protocol);
-    CopyMem (BufAddr + (NET_ETHER_ADDR_LEN * 2), (VOID *)&Proto,
-      sizeof (UINT16));
+    CopyMem (
+      (VOID*)((UINTN)BufAddr + (NET_ETHER_ADDR_LEN * 2)),
+      (VOID*)&Proto,
+      sizeof (UINT16)
+      );
   }
 
   Status = DmaMap (MapOperationBusMasterRead, BufAddr, &BufSize,
diff --git 
a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
 
b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
index 
1a654e4430c8451fe755b066e11a33f4887d9332..bded74dc4f02dc2444db724ee46fb75096234126
 100644
--- 
a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
+++ 
b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
@@ -3,6 +3,7 @@
 
   Copyright (c) 2016, Linaro, Ltd. All rights reserved.<BR>
   Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -316,7 +317,7 @@ PerformFlashWriteWithProgress (
       Print (L".");
     }
 
-    Buffer += BlockSize;
+    Buffer = (VOID*)((UINTN)Buffer + BlockSize);
     Length -= BlockSize;
     Lba++;
   }
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#63518): https://edk2.groups.io/g/devel/message/63518
Mute This Topic: https://groups.io/mt/75893335/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to