Martin Milata
2013-04-23 16:14:03 UTC
Using uintptr_t might pose a problem when processing data from 64-bit
machine on a 32-bit machine.
Related to rhbz#951506.
Signed-off-by: Martin Milata <mmilata-H+wXaHxf7aLQT0dZR+***@public.gmane.org>
---
lib/disasm.c | 5 +++--
lib/elves.c | 7 ++++---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/lib/disasm.c b/lib/disasm.c
index 9df9cd9..c47a58c 100644
--- a/lib/disasm.c
+++ b/lib/disasm.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include <string.h>
#include <stdio.h>
+#include <inttypes.h>
#if HAVE_LIBOPCODES
#include <bfd.h>
@@ -269,8 +270,8 @@ sr_disasm_instruction_parse_single_address_operand(char *instruction,
/* Parse the address. */
int chars_read;
- uintptr_t addr;
- int ret = sscanf(p, "%jx %n", &addr, &chars_read);
+ uint64_t addr;
+ int ret = sscanf(p, "%"SCNx64" %n", &addr, &chars_read);
if (ret < 1)
return false;
diff --git a/lib/elves.c b/lib/elves.c
index bf844d6..a4f1957 100644
--- a/lib/elves.c
+++ b/lib/elves.c
@@ -35,6 +35,7 @@
#include <libelf.h>
#include <string.h>
#include <unistd.h>
+#include <inttypes.h>
/**
* Finds a section by its name in an ELF file.
@@ -166,7 +167,7 @@ sr_elf_get_procedure_linkage_table(const char *filename,
/* Find the relocation section for .plt (typically .rela.plt), together
* with its symbol and string table
*/
- uintptr_t plt_base = shdr.sh_addr;
+ uint64_t plt_base = shdr.sh_addr;
Elf_Data *rela_plt_data = NULL;
Elf_Data *plt_symbols = NULL;
size_t stringtable = 0;
@@ -477,7 +478,7 @@ read_cie(Dwarf_CFI_Entry *cfi,
* Assumption: we'll always run on architecture the ELF is run on,
* therefore we don't consider byte order.
*/
-static uintptr_t
+static uint64_t
fde_read_address(const uint8_t *p, unsigned len)
{
int i;
@@ -491,7 +492,7 @@ fde_read_address(const uint8_t *p, unsigned len)
for (i = 0; i < len; i++)
u.b[i] = *p++;
- return (len == 4 ? (uintptr_t)u.n4 : (uintptr_t)u.n8);
+ return (len == 4 ? (uint64_t)u.n4 : u.n8);
}
#endif /* WITH_ELFUTILS */
machine on a 32-bit machine.
Related to rhbz#951506.
Signed-off-by: Martin Milata <mmilata-H+wXaHxf7aLQT0dZR+***@public.gmane.org>
---
lib/disasm.c | 5 +++--
lib/elves.c | 7 ++++---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/lib/disasm.c b/lib/disasm.c
index 9df9cd9..c47a58c 100644
--- a/lib/disasm.c
+++ b/lib/disasm.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include <string.h>
#include <stdio.h>
+#include <inttypes.h>
#if HAVE_LIBOPCODES
#include <bfd.h>
@@ -269,8 +270,8 @@ sr_disasm_instruction_parse_single_address_operand(char *instruction,
/* Parse the address. */
int chars_read;
- uintptr_t addr;
- int ret = sscanf(p, "%jx %n", &addr, &chars_read);
+ uint64_t addr;
+ int ret = sscanf(p, "%"SCNx64" %n", &addr, &chars_read);
if (ret < 1)
return false;
diff --git a/lib/elves.c b/lib/elves.c
index bf844d6..a4f1957 100644
--- a/lib/elves.c
+++ b/lib/elves.c
@@ -35,6 +35,7 @@
#include <libelf.h>
#include <string.h>
#include <unistd.h>
+#include <inttypes.h>
/**
* Finds a section by its name in an ELF file.
@@ -166,7 +167,7 @@ sr_elf_get_procedure_linkage_table(const char *filename,
/* Find the relocation section for .plt (typically .rela.plt), together
* with its symbol and string table
*/
- uintptr_t plt_base = shdr.sh_addr;
+ uint64_t plt_base = shdr.sh_addr;
Elf_Data *rela_plt_data = NULL;
Elf_Data *plt_symbols = NULL;
size_t stringtable = 0;
@@ -477,7 +478,7 @@ read_cie(Dwarf_CFI_Entry *cfi,
* Assumption: we'll always run on architecture the ELF is run on,
* therefore we don't consider byte order.
*/
-static uintptr_t
+static uint64_t
fde_read_address(const uint8_t *p, unsigned len)
{
int i;
@@ -491,7 +492,7 @@ fde_read_address(const uint8_t *p, unsigned len)
for (i = 0; i < len; i++)
u.b[i] = *p++;
- return (len == 4 ? (uintptr_t)u.n4 : (uintptr_t)u.n8);
+ return (len == 4 ? (uint64_t)u.n4 : u.n8);
}
#endif /* WITH_ELFUTILS */
--
1.7.11.7
1.7.11.7