Skip to contentSkip to conversation

s390x/snippets/c/sie-dat: Fix compiler warning with GCC 11.2

PATCH In review Thomas Huth 2 participants 2 messages Feb 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/snippets/c/sie-dat: Fix compiler warning with GCC 11.2

GCC 11.2.1 from RHEL 9.0 complains:

s390x/snippets/c/sie-dat.c: In function ‘main’:
s390x/snippets/c/sie-dat.c:51:22: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]

    51 |         *invalid_ptr = 42;
       |         ~~~~~~~~~~~~~^~~~

cc1: all warnings being treated as errors

Let's use the OPAQUE_PTR() macro here too, which we already used in other spots to fix similar -Wstringop-overflow warnings.

---
 s390x/snippets/c/sie-dat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
s390x/snippets/c/sie-dat.c +2 -1
index ecfcb60e..9d89801d 100644
@@ -9,6 +9,7 @@
  */
 #include <libcflat.h>
 #include <asm-generic/page.h>
+#include <asm/mem.h>
 #include "sie-dat.h"
 
 static uint8_t test_pages[GUEST_TEST_PAGE_COUNT * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
@@ -47,7 +48,7 @@ int main(void)
 	force_exit();
 
 	/* the first unmapped address */
-	invalid_ptr = (uint8_t *)(GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE);
+	invalid_ptr = OPAQUE_PTR(GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE);
 	*invalid_ptr = 42;
 
 	/* indicate we've written the non-allowed page (should never get here) */
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Fri, 16 Feb 2024 20:00:48 +0100 Thomas Huth <[email protected]> wrote:

GCC 11.2.1 from RHEL 9.0 complains:

s390x/snippets/c/sie-dat.c: In function ‘main’:
s390x/snippets/c/sie-dat.c:51:22: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]

    51 |         *invalid_ptr = 42;
       |         ~~~~~~~~~~~~~^~~~
Quoted 7 lines

cc1: all warnings being treated as errors

Let's use the OPAQUE_PTR() macro here too, which we already used in other spots to fix similar -Wstringop-overflow warnings.

Quoted 25 lines
---
 s390x/snippets/c/sie-dat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
s390x/snippets/c/sie-dat.c +2 -1
index ecfcb60e..9d89801d 100644
@@ -9,6 +9,7 @@
  */
 #include <libcflat.h>
 #include <asm-generic/page.h>
+#include <asm/mem.h>
 #include "sie-dat.h"
 
 static uint8_t test_pages[GUEST_TEST_PAGE_COUNT * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
@@ -47,7 +48,7 @@ int main(void)
 	force_exit();
 
 	/* the first unmapped address */
-	invalid_ptr = (uint8_t *)(GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE);
+	invalid_ptr = OPAQUE_PTR(GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE);
 	*invalid_ptr = 42;
 
 	/* indicate we've written the non-allowed page (should never get here) */