[Asterisk-code-review] backtrace.c: Fix casting pointer to/from integral type. (asterisk[master])

George Joseph asteriskteam at digium.com
Wed Jan 2 09:51:37 CST 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10825 )

Change subject: backtrace.c: Fix casting pointer to/from integral type.
......................................................................

backtrace.c: Fix casting pointer to/from integral type.

The backtrace library bfd.h include file does not get the sizes of
pointers and ints right on some platforms.  On my old test box the size
of bfd_vma is 8 while the size of a pointer is 4.  gcc on the box
complains of the integer casting to/from pointers size mismatch.

* uintptr_t to the rescue by doing an appropriate two stage cast.

Change-Id: Icb2621583f50c8728de08a3c824d95fe53cc45d0
---
M main/backtrace.c
1 file changed, 5 insertions(+), 5 deletions(-)

Approvals:
  Corey Farrell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/main/backtrace.c b/main/backtrace.c
index 16f5a56..2623d7f 100644
--- a/main/backtrace.c
+++ b/main/backtrace.c
@@ -122,7 +122,7 @@
 	char *fn;
 	int inlined = 0;
 
-	offset = data->pc - (data->dynamic ? (bfd_vma) data->dli.dli_fbase : 0);
+	offset = data->pc - (data->dynamic ? (bfd_vma)(uintptr_t) data->dli.dli_fbase : 0);
 
 	if (!(bfd_get_section_flags(bfdobj, section) & SEC_ALLOC)) {
 		return;
@@ -151,11 +151,11 @@
 		/* file can possibly be null even with a success result from bfd_find_nearest_line */
 		file = file ? file : "";
 		fn = strrchr(file, '/');
-#define FMT_INLINED "[%s] %s %s:%u %s()"
+#define FMT_INLINED     "[%s] %s %s:%u %s()"
 #define FMT_NOT_INLINED "[%p] %s %s:%u %s()"
 
 		snprintf(data->msg, MSG_BUFF_LEN, inlined ? FMT_INLINED : FMT_NOT_INLINED,
-			inlined ? "inlined" : (char *)data->pc,
+			inlined ? "inlined" : (char *)(uintptr_t) data->pc,
 			data->libname,
 			fn ? fn + 1 : file,
 			line, S_OR(func, "???"));
@@ -192,14 +192,14 @@
 		struct bfd_data data = {
 			.return_strings = return_strings,
 			.msg = msg,
-			.pc = (bfd_vma)addresses[stackfr],
+			.pc = (bfd_vma)(uintptr_t) addresses[stackfr],
 			.found = 0,
 			.dynamic = 0,
 		};
 
 		msg[0] = '\0';
 
-		if (!dladdr((void *)data.pc, &data.dli)) {
+		if (!dladdr((void *)(uintptr_t) data.pc, &data.dli)) {
 			continue;
 		}
 		data.libname = strrchr(data.dli.dli_fname, '/');

-- 
To view, visit https://gerrit.asterisk.org/10825
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Icb2621583f50c8728de08a3c824d95fe53cc45d0
Gerrit-Change-Number: 10825
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Friendly Automation (1000185)
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190102/6627b960/attachment.html>


More information about the asterisk-code-review mailing list