[rtems commit] libfdt.h: add explicit cast from void* to uint8_t* in fdt( 32|64)_st

Sebastian Huber sebh at rtems.org
Mon Mar 2 06:52:33 UTC 2020


Module:    rtems
Branch:    master
Commit:    94d5b6ea563d57d66080a999a9d2d4c3806b1741
Changeset: http://git.rtems.org/rtems/commit/?id=94d5b6ea563d57d66080a999a9d2d4c3806b1741

Author:    Luc Michel <luc.michel at greensocs.com>
Date:      Tue Sep 10 12:48:24 2019 +0200

libfdt.h: add explicit cast from void* to uint8_t* in fdt(32|64)_st

Including libfdt.h in a C++ project fails during compilation with recent
version of GCC or Clang.

This simple example:

extern "C" {
 #include <libfdt.h>
}

int main(void) { return 0; }

leads to the following errors with GCC 9.1.0:

/usr/include/libfdt.h: In function ‘void fdt32_st(void*, uint32_t)’:
/usr/include/libfdt.h:139:16: error: invalid conversion from ‘void*’ to ‘uint8_t*’ {aka ‘unsigned char*’} [-fpermissive]
  139 |  uint8_t *bp = property;
      |                ^~~~~~~~
      |                |
      |                void*
/usr/include/libfdt.h: In function ‘void fdt64_st(void*, uint64_t)’:
/usr/include/libfdt.h:163:16: error: invalid conversion from ‘void*’ to ‘uint8_t*’ {aka ‘unsigned char*’} [-fpermissive]
  163 |  uint8_t *bp = property;
      |                ^~~~~~~~
      |                |
      |                void*

This commit adds an explicit cast to uint8_t* to fix this issue.

Signed-off-by: Luc Michel <luc.michel at greensocs.com>
Message-Id: <20190910104824.1321594-1-luc.michel at greensocs.com>
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>

---

 cpukit/include/libfdt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpukit/include/libfdt.h b/cpukit/include/libfdt.h
index 8037f39..fc4c496 100644
--- a/cpukit/include/libfdt.h
+++ b/cpukit/include/libfdt.h
@@ -136,7 +136,7 @@ static inline uint32_t fdt32_ld(const fdt32_t *p)
 
 static inline void fdt32_st(void *property, uint32_t value)
 {
-	uint8_t *bp = property;
+	uint8_t *bp = (uint8_t *)property;
 
 	bp[0] = value >> 24;
 	bp[1] = (value >> 16) & 0xff;
@@ -160,7 +160,7 @@ static inline uint64_t fdt64_ld(const fdt64_t *p)
 
 static inline void fdt64_st(void *property, uint64_t value)
 {
-	uint8_t *bp = property;
+	uint8_t *bp = (uint8_t *)property;
 
 	bp[0] = value >> 56;
 	bp[1] = (value >> 48) & 0xff;



More information about the vc mailing list