Skip to contentSkip to conversation

fix warnings from printf target addresses

PATCH In review Mike Frysinger 3 participants 5 messages Sep 16, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix warnings from printf target addresses

Current code triggers:
memory.c: In function 'invalid_read':
memory.c:1001: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'
memory.c: In function 'invalid_write':
memory.c:1013: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'

---
 memory.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
memory.c +4 -2
index 58a242d..7d5f4a3 100644
@@ -998,7 +998,8 @@ static uint64_t invalid_read(void *opaque, target_phys_addr_t addr,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid read from memory region %s at offset %#x\n", mr->name, addr);
+        fprintf(stderr, "Invalid read from memory region %s at offset %#llx\n",
+                mr->name, (unsigned long long)addr);
         mr->warning_printed = true;
     }
     return -1U;
@@ -1010,7 +1011,8 @@ static void invalid_write(void *opaque, target_phys_addr_t addr, uint64_t data,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid write to memory region %s at offset %#x\n", mr->name, addr);
+        fprintf(stderr, "Invalid write to memory region %s at offset %#llx\n",
+                mr->name, (unsigned long long)addr);
         mr->warning_printed = true;
     }
 }
Signature · 1 line
1.7.9.7
#1 lore raw
Quoted 18 lines · Mike Frysinger

Current code triggers:
memory.c: In function 'invalid_read':
memory.c:1001: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'
memory.c: In function 'invalid_write':
memory.c:1013: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'

---
 memory.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
memory.c +0 -0
index 58a242d..7d5f4a3 100644

memory.c static uint64_t invalid_read(void *opaque, target_phys_addr_t addr, · line 1002

Quoted 6 lines
memory.c +2 -1
@@ -998,7 +998,8 @@ static uint64_t invalid_read(void *opaque, target_phys_addr_t addr,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid read from memory region %s at offset %#x\n", mr->name, addr);
+        fprintf(stderr, "Invalid read from memory region %s at offset %#llx\n",
+                mr->name, (unsigned long long)addr);

The right way is not adding potentially dangerous casts but using TARGET_PRIxPHYS or TARGET_FMT_plx.

Quoted 17 lines
memory.c +2 -2
         mr->warning_printed = true;
     }
     return -1U;
@@ -1010,7 +1011,8 @@ static void invalid_write(void *opaque, target_phys_addr_t addr, uint64_t data,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid write to memory region %s at offset %#x\n", mr->name, addr);
+        fprintf(stderr, "Invalid write to memory region %s at offset %#llx\n",
+                mr->name, (unsigned long long)addr);
         mr->warning_printed = true;
     }
 }
--

1.7.9.7

#2 lore raw
Quoted 9 lines · On Sunday 16 September 2012 03:24:22 Blue Swirl wrote:
Quoted 8 lines · Mike Frysinger

Current code triggers:
memory.c: In function 'invalid_read':
memory.c:1001: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'
memory.c: In function 'invalid_write':
memory.c:1013: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'

Quoted 6 lines
Quoted 4 lines

- fprintf(stderr, "Invalid read from memory region %s at offset
%#x\n", mr->name, addr); + fprintf(stderr, "Invalid read from
memory region %s at offset %#llx\n", + mr->name,
(unsigned long long)addr);

The right way is not adding potentially dangerous casts

they're not dangerous here at all

Quoted 1 line

but using TARGET_PRIxPHYS or TARGET_FMT_plx.

np. i just copied what was already in memory.c, but i guess that's broken too.
-mike

#3 lore raw
In reply to Mike Frysinger
Quoted 7 lines · Mike Frysinger

Current code triggers:
memory.c: In function 'invalid_read':
memory.c:1001: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'
memory.c: In function 'invalid_write':
memory.c:1013: warning: format '%#x' expects type 'unsigned int',
but argument 4 has type 'target_phys_addr_t'

This version was never in git. Which QEMU are you patching, a local one?

Jan

Quoted 31 lines
---
 memory.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
memory.c +4 -2
index 58a242d..7d5f4a3 100644
@@ -998,7 +998,8 @@ static uint64_t invalid_read(void *opaque, target_phys_addr_t addr,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid read from memory region %s at offset %#x\n", mr->name, addr);
+        fprintf(stderr, "Invalid read from memory region %s at offset %#llx\n",
+                mr->name, (unsigned long long)addr);
         mr->warning_printed = true;
     }
     return -1U;
@@ -1010,7 +1011,8 @@ static void invalid_write(void *opaque, target_phys_addr_t addr, uint64_t data,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid write to memory region %s at offset %#x\n", mr->name, addr);
+        fprintf(stderr, "Invalid write to memory region %s at offset %#llx\n",
+                mr->name, (unsigned long long)addr);
         mr->warning_printed = true;
     }
 }
#4 lore raw

PATCH 1/1 include address in invalid memory region accesses

The current code to display invalid memory accesses isn't terribly useful as it doesn't tell you what address is actually being accessed. Include it in the error message.

---
 memory.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
memory.c +6 -2
index d528d1f..0ea0320 100644
@@ -998,7 +998,9 @@ static uint64_t invalid_read(void *opaque, target_phys_addr_t addr,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid read from memory region %s\n", mr->name);
+        fprintf(stderr,
+                "Invalid read from memory region %s at %#" TARGET_PRIxPHYS "\n",
+                mr->name, addr);
         mr->warning_printed = true;
     }
     return -1U;
@@ -1010,7 +1012,9 @@ static void invalid_write(void *opaque, target_phys_addr_t addr, uint64_t data,
     MemoryRegion *mr = opaque;
 
     if (!mr->warning_printed) {
-        fprintf(stderr, "Invalid write to memory region %s\n", mr->name);
+        fprintf(stderr,
+                "Invalid write to memory region %s at %#" TARGET_PRIxPHYS "\n",
+                mr->name, addr);
         mr->warning_printed = true;
     }
 }
Signature · 1 line
1.7.9.7