[erlang-patches] [PATCH] Correct formating in exit error messages

Michael Santos <>
Tue May 8 18:55:05 CEST 2012


Ensure displayed sizes are not negative.
---
 erts/emulator/drivers/common/efile_drv.c     |    2 +-
 erts/emulator/drivers/unix/unix_efile.c      |    8 ++++----
 lib/kernel/examples/uds_dist/c_src/uds_drv.c |    4 ++--
 lib/runtime_tools/c_src/trace_ip_drv.c       |    8 ++++----
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/erts/emulator/drivers/common/efile_drv.c b/erts/emulator/drivers/common/efile_drv.c
index 603d1d4..347247e 100644
--- a/erts/emulator/drivers/common/efile_drv.c
+++ b/erts/emulator/drivers/common/efile_drv.c
@@ -522,7 +522,7 @@ static void *ef_safe_alloc(Uint s)
 static void *ef_safe_realloc(void *op, Uint s)
 {
     void *p = EF_REALLOC(op, s);
-    if (!p) erl_exit(1, "efile drv: Can't reallocate %d bytes of memory\n", s);
+    if (!p) erl_exit(1, "efile drv: Can't reallocate %lu bytes of memory\n", (unsigned long)s);
     return p;
 }
 
diff --git a/erts/emulator/drivers/unix/unix_efile.c b/erts/emulator/drivers/unix/unix_efile.c
index ad112f7..b250bac 100644
--- a/erts/emulator/drivers/unix/unix_efile.c
+++ b/erts/emulator/drivers/unix/unix_efile.c
@@ -107,8 +107,8 @@ static void *ef_safe_alloc(Uint s)
 {
     void *p = EF_ALLOC(s);
     if (!p) erl_exit(1,
-		     "unix efile drv: Can't allocate %d bytes of memory\n",
-		     s);
+		     "unix efile drv: Can't allocate %lu bytes of memory\n",
+		     (unsigned long)s);
     return p;
 }
 
@@ -118,8 +118,8 @@ static void *ef_safe_realloc(void *op, Uint s)
 {
     void *p = EF_REALLOC(op, s);
     if (!p) erl_exit(1,
-		     "unix efile drv: Can't reallocate %d bytes of memory\n",
-		     s);
+		     "unix efile drv: Can't reallocate %lu bytes of memory\n",
+		     (unsigned long)s);
     return p;
 }
 
diff --git a/lib/kernel/examples/uds_dist/c_src/uds_drv.c b/lib/kernel/examples/uds_dist/c_src/uds_drv.c
index 9327ab1..9ad6b85 100644
--- a/lib/kernel/examples/uds_dist/c_src/uds_drv.c
+++ b/lib/kernel/examples/uds_dist/c_src/uds_drv.c
@@ -967,7 +967,7 @@ static void *my_malloc(size_t size)
     void *ptr;
 
     if ((ptr = driver_alloc(size)) == NULL) {
-	erl_exit(1,"Could not allocate %d bytes of memory",(int) size);
+	erl_exit(1,"Could not allocate %lu bytes of memory",(unsigned long) size);
     }
     return ptr;
 }
@@ -977,7 +977,7 @@ static void *my_realloc(void *ptr, size_t size)
     void erl_exit(int, char *, ...);
     void *nptr;
     if ((nptr = driver_realloc(ptr, size)) == NULL) {
-	erl_exit(1,"Could not reallocate %d bytes of memory",(int) size);
+	erl_exit(1,"Could not reallocate %lu bytes of memory",(unsigned long) size);
     }
     return nptr;
 }
diff --git a/lib/runtime_tools/c_src/trace_ip_drv.c b/lib/runtime_tools/c_src/trace_ip_drv.c
index 7f7ab8d..6b77128 100644
--- a/lib/runtime_tools/c_src/trace_ip_drv.c
+++ b/lib/runtime_tools/c_src/trace_ip_drv.c
@@ -590,8 +590,8 @@ static void *my_alloc(size_t size)
     void *ret;
     if ((ret = driver_alloc(size)) == NULL) {
 	/* May or may not work... */
-	fprintf(stderr, "Could not allocate %d bytes of memory in %s.",
-		(int) size, __FILE__);
+	fprintf(stderr, "Could not allocate %lu bytes of memory in %s.",
+		(unsigned long) size, __FILE__);
 	exit(1);
     }
     return ret;
@@ -605,8 +605,8 @@ static ErlDrvBinary *my_alloc_binary(int size)
     ErlDrvBinary *ret;
     if ((ret = driver_alloc_binary(size)) == NULL) {
 	/* May or may not work... */
-	fprintf(stderr, "Could not allocate a binary of %d bytes in %s.",
-		(int) size, __FILE__);
+	fprintf(stderr, "Could not allocate a binary of %lu bytes in %s.",
+		(unsigned long) size, __FILE__);
 	exit(1);
     }
     return ret;
-- 
1.7.9.5



More information about the erlang-patches mailing list