[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: more warnings patrol
From: |
Jim Meyering |
Subject: |
Re: more warnings patrol |
Date: |
Sat, 31 Oct 2009 09:43:39 +0100 |
Eric Blake wrote:
> I'm committing this, to silence some unused variables, and to make
> inttostr.c quiet even on older gcc.
...
> diff --git a/lib/inttostr.c b/lib/inttostr.c
...
> +#ifndef inttype_is_unsigned
> if (i < 0)
> {
> do
> @@ -45,6 +41,7 @@ inttostr (inttype i, char *buf)
> *--p = '-';
> }
> else
> +#endif
> {
> do
> *--p = '0' + i % 10;
...
> diff --git a/lib/uinttostr.c b/lib/uinttostr.c
> index 52d288e..d6fc964 100644
> --- a/lib/uinttostr.c
> +++ b/lib/uinttostr.c
> @@ -1,3 +1,4 @@
> #define inttostr uinttostr
> #define inttype unsigned int
> +#define inttype_is_unsigned
> #include "inttostr.c"
> diff --git a/lib/umaxtostr.c b/lib/umaxtostr.c
> index 4f49a7f..75346a4 100644
> --- a/lib/umaxtostr.c
> +++ b/lib/umaxtostr.c
> @@ -1,3 +1,4 @@
> #define inttostr umaxtostr
> #define inttype uintmax_t
> +#define inttype_is_unsigned
> #include "inttostr.c"
For inttostr.c and the modules that depend on it,
I would like a safety check,
verify (TYPE_SIGNED (inttype) == inttype_is_signed);
and I prefer to avoid double negatives, when it's easy,
-#ifndef inttype_is_unsigned
+#if inttype_is_signed
so I've pushed this:
>From c74c2411db5f3bf06848008c0d121a23fd31cf91 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 31 Oct 2009 09:42:37 +0100
Subject: [PATCH] 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.
---
ChangeLog | 14 ++++++++++++++
lib/imaxtostr.c | 1 +
lib/inttostr.c | 4 +++-
lib/offtostr.c | 1 +
lib/uinttostr.c | 2 +-
lib/umaxtostr.c | 2 +-
modules/inttostr | 1 +
7 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e9515dd..251829a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-10-31 Jim Meyering <address@hidden>
+
+ 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 <address@hidden>
build: avoid compiler warnings
diff --git a/lib/imaxtostr.c b/lib/imaxtostr.c
index 5e87ad5..34ef96c 100644
--- a/lib/imaxtostr.c
+++ b/lib/imaxtostr.c
@@ -1,3 +1,4 @@
#define inttostr imaxtostr
#define inttype intmax_t
+#define inttype_is_signed 1
#include "inttostr.c"
diff --git a/lib/inttostr.c b/lib/inttostr.c
index 749aea7..c7c0d73 100644
--- a/lib/inttostr.c
+++ b/lib/inttostr.c
@@ -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
diff --git a/lib/offtostr.c b/lib/offtostr.c
index 45196e2..3a60c6e 100644
--- a/lib/offtostr.c
+++ b/lib/offtostr.c
@@ -1,3 +1,4 @@
#define inttostr offtostr
#define inttype off_t
+#define inttype_is_signed 1
#include "inttostr.c"
diff --git a/lib/uinttostr.c b/lib/uinttostr.c
index d6fc964..1662985 100644
--- a/lib/uinttostr.c
+++ b/lib/uinttostr.c
@@ -1,4 +1,4 @@
#define inttostr uinttostr
#define inttype unsigned int
-#define inttype_is_unsigned
+#define inttype_is_signed 0
#include "inttostr.c"
diff --git a/lib/umaxtostr.c b/lib/umaxtostr.c
index 75346a4..914f388 100644
--- a/lib/umaxtostr.c
+++ b/lib/umaxtostr.c
@@ -1,4 +1,4 @@
#define inttostr umaxtostr
#define inttype uintmax_t
-#define inttype_is_unsigned
+#define inttype_is_signed 0
#include "inttostr.c"
diff --git a/modules/inttostr b/modules/inttostr
index 56ec6fc..2c2b76e 100644
--- a/modules/inttostr
+++ b/modules/inttostr
@@ -13,6 +13,7 @@ m4/inttostr.m4
Depends-on:
intprops
stdint
+verify
configure.ac:
gl_INTTOSTR
--
1.6.5.2.375.g164f1