Proof positive the "signedness of char *" warning is useless.

Ihno Krumreich ihno at suse.de
Mon Dec 5 18:16:51 UTC 2005


hi,

attached is a patch to remove some of signed warnings.
The code was compiled with a gcc 4.1.0.

Regards

Ihno


On Wed, Nov 30, 2005 at 07:48:12AM -0800, John Z. Bohach wrote:
> On Wednesday 30 November 2005 01:25, Ihno Krumreich wrote:
> > On Tue, Nov 29, 2005 at 08:29:33PM -0800, John Z. Bohach wrote:
> 
> > > I agree.  Be very careful about eliminating warnings.  Signed vs.
> > > unsigned generates machine code with/without sign extensions, and thus
> > > generates very different code.  You can run into situations where -1 is
> > > greater than 127 if a signed/unsigned char comparison isn't right.  To
> > > make things more more fun, not all compilers treat signed/usigned
> > > promotions the same in C, and whether that's a compiler bug or
> > > implementation-dependent feature of C, I forget...what I do remember is
> > > the hideous runtime debug of such machine code on the rare occasion that
> > > it matters...anyways, I digress.  Just be careful. Couldn't such code be
> > > fixed to actually use casts to eliminate the warnings?
> >
> > If you fix it _never_ use casts! There are _very_ rare cases where a cast
> > is really needed to avoid these massages. In all other cases you are just
> > hiding the possible bugs (especially if the compiler changes behaviour or
> > the code is compiled by a new compiler).
> 
> I am not aware how a single cast can introduce bugs.  There are predefined 
> promotion rules in the C standard that control what happens when two items of 
> differing types are used in the same statement, and those promotion rules are 
> implicit, but they happen anyway.  Now I've seen bugs etc. when relying on 
> implicit promotion rules that surface when switching compilers, or buggy 
> compilers have issues, but I far prefer an explicit cast so at least you can 
> see that the type mismatch was intentional.  But I do agree that you should 
> write code to not need casts in the first place, yet sometimes that is 
> unavoidable.
> 
> As for Rob's current quandry, I think he's got it under control.  If the 
> warnings surfaced because of a compiler switch, perhaps there is a way to 
> turn off those warnings with a '-Wno-sign-compare' option to gcc...but I 
> don't know how to limit that just to chars...
> 
> -- 
>      ###  Any similarity between my views and the truth is completely ###
>      ###  coincidental, except that they are endorsed by NO ONE       ###
> 
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://busybox.net/cgi-bin/mailman/listinfo/busybox

-- 
Best regards/Mit freundlichen Grüßen

Ihno Krumreich

"Never trust a computer you can lift."
--
Ihno Krumreich            ihno at suse.de
SUSE LINUX Products GmbH  Projectmanager S390 & zSeries
Maxfeldstr. 5             +49-911-74053-439
D-90409 Nürnberg          http://www.suse.de
-------------- next part --------------
Index: scripts/config/confdata.c
===================================================================
--- scripts/config/confdata.c	(revision 12662)
+++ scripts/config/confdata.c	(working copy)
@@ -23,10 +23,10 @@
 	NULL,
 };
 
-static char *conf_expand_value(const signed char *in)
+static char *conf_expand_value(const char *in)
 {
 	struct symbol *sym;
-	const signed char *src;
+	const char *src;
 	static char res_value[SYMBOL_MAXLENGTH];
 	char *dst, name[SYMBOL_MAXLENGTH];
 
Index: scripts/config/conf.c
===================================================================
--- scripts/config/conf.c	(revision 12662)
+++ scripts/config/conf.c	(working copy)
@@ -31,14 +31,14 @@
 static int indent = 1;
 static int valid_stdin = 1;
 static int conf_cnt;
-static signed char line[128];
+static char line[128];
 static struct menu *rootEntry;
 
 static char nohelp_text[] = "Sorry, no help available for this option yet.\n";
 
-static void strip(signed char *str)
+static void strip(char *str)
 {
-	signed char *p = str;
+	char *p = str;
 	int l;
 
 	while ((isspace(*p)))
Index: networking/libiproute/utils.c
===================================================================
--- networking/libiproute/utils.c	(revision 12662)
+++ networking/libiproute/utils.c	(working copy)
@@ -168,7 +168,7 @@
 int get_prefix_1(inet_prefix * dst, char *arg, int family)
 {
 	int err;
-	unsigned plen;
+	int plen;
 	char *slash;
 
 	memset(dst, 0, sizeof(*dst));
Index: networking/libiproute/iplink.c
===================================================================
--- networking/libiproute/iplink.c	(revision 12662)
+++ networking/libiproute/iplink.c	(working copy)
@@ -166,7 +166,7 @@
 {
 	struct ifreq ifr;
 	struct sockaddr_ll me;
-	int alen;
+	socklen_t alen;
 	int s;
 
 	s = socket(PF_PACKET, SOCK_DGRAM, 0);
@@ -206,7 +206,7 @@
 
 static int parse_address(char *dev, int hatype, int halen, char *lla, struct ifreq *ifr)
 {
-	int alen;
+	socklen_t alen;
 
 	memset(ifr, 0, sizeof(*ifr));
 	strcpy(ifr->ifr_name, dev);
Index: networking/libiproute/libnetlink.c
===================================================================
--- networking/libiproute/libnetlink.c	(revision 12662)
+++ networking/libiproute/libnetlink.c	(working copy)
@@ -30,7 +30,7 @@
 
 int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
 {
-	int addr_len;
+	socklen_t addr_len;
 
 	memset(rth, 0, sizeof(rth));
 


More information about the busybox mailing list