inttostr: aesthetics and improved (compile-time) safety
authorJim Meyering <meyering@redhat.com>
Sat, 31 Oct 2009 08:42:37 +0000 (09:42 +0100)
committerJim Meyering <meyering@redhat.com>
Sat, 31 Oct 2009 08:42:37 +0000 (09:42 +0100)
Define inttype_is_signed rather than inttype_is_unsigned,
since the sole use is via "#if inttype_is_signed".
* lib/imaxtostr.c (inttype_is_signed): Define this, rather than
inttype_is_unsigned.
* lib/offtostr.c (inttype_is_signed): Likewise.
* lib/uinttostr.c (inttype_is_signed): Likewise.
* lib/umaxtostr.c (inttype_is_signed): Likewise.
* lib/inttostr.c (inttostr): Use verify to cross-check the
inttype_is_signed value and the signedness of the actual type.
* modules/inttostr (Depends-on): Add verify.

ChangeLog
lib/imaxtostr.c
lib/inttostr.c
lib/offtostr.c
lib/uinttostr.c
lib/umaxtostr.c
modules/inttostr

index e9515dddee8b372f8ec2a62d70d20cfd131ef6b3..251829a376952dd74c486b01cbaea33c04cbde3b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-10-31  Jim Meyering  <meyering@redhat.com>
+
+       inttostr: aesthetics and improved (compile-time) safety
+       Define inttype_is_signed rather than inttype_is_unsigned,
+       since the sole use is via "#if inttype_is_signed".
+       * lib/imaxtostr.c (inttype_is_signed): Define this, rather than
+       inttype_is_unsigned.
+       * lib/offtostr.c (inttype_is_signed): Likewise.
+       * lib/uinttostr.c (inttype_is_signed): Likewise.
+       * lib/umaxtostr.c (inttype_is_signed): Likewise.
+       * lib/inttostr.c (inttostr): Use verify to cross-check the
+       inttype_is_signed value and the signedness of the actual type.
+       * modules/inttostr (Depends-on): Add verify.
+
 2009-10-30  Eric Blake  <ebb9@byu.net>
 
        build: avoid compiler warnings
index 5e87ad526f50ffc3116757d5cdd0eefc85d4ae99..34ef96c4500968aad3d3972894dbd014d20ef274 100644 (file)
@@ -1,3 +1,4 @@
 #define inttostr imaxtostr
 #define inttype intmax_t
+#define inttype_is_signed 1
 #include "inttostr.c"
index 749aea7f6f25a739a447dd5a06c9e155c1a53f33..c7c0d736a659275e83141f0976a4755716335fcd 100644 (file)
@@ -20,6 +20,7 @@
 #include <config.h>
 
 #include "inttostr.h"
+#include "verify.h"
 
 /* Convert I to a printable string in BUF, which must be at least
    INT_BUFSIZE_BOUND (INTTYPE) bytes long.  Return the address of the
@@ -31,7 +32,8 @@ inttostr (inttype i, char *buf)
   char *p = buf + INT_STRLEN_BOUND (inttype);
   *p = 0;
 
-#ifndef inttype_is_unsigned
+  verify (TYPE_SIGNED (inttype) == inttype_is_signed);
+#if inttype_is_signed
   if (i < 0)
     {
       do
index 45196e28a4861815e4f07408bac6eede433a1ad3..3a60c6e7445ca9691d1127cd40fd97c71bae7e71 100644 (file)
@@ -1,3 +1,4 @@
 #define inttostr offtostr
 #define inttype off_t
+#define inttype_is_signed 1
 #include "inttostr.c"
index d6fc9645a632351a5f8ab0847a000d500a97ca77..1662985f4091331644bf217ff0b432a915b8e1f8 100644 (file)
@@ -1,4 +1,4 @@
 #define inttostr uinttostr
 #define inttype unsigned int
-#define inttype_is_unsigned
+#define inttype_is_signed 0
 #include "inttostr.c"
index 75346a44f78876691c4ccf34fb3496cc3e7a7937..914f388d1b323d67486c1a9b478d4f6c2419efd2 100644 (file)
@@ -1,4 +1,4 @@
 #define inttostr umaxtostr
 #define inttype uintmax_t
-#define inttype_is_unsigned
+#define inttype_is_signed 0
 #include "inttostr.c"
index 56ec6fc563498d93e545f3a03a686d2d5f344811..2c2b76e5bbfa9931637bf612ade217ed56acab2e 100644 (file)
@@ -13,6 +13,7 @@ m4/inttostr.m4
 Depends-on:
 intprops
 stdint
+verify
 
 configure.ac:
 gl_INTTOSTR