This is the mail archive of the newlib@sourceware.cygnus.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fixes for compile warnings


Hi,

when compiling newlib with a recent gcc snapshot, I noticed quite
a lot of warnings.  The patch below eliminates some of them (and
also fixes a few bugs related to operator precedence).  A few
warnings are still there but are less important, and I wanted to
avoid making too many changes in one huge patch.

I hope you find it useful.  Concerning my problems with newlib build,
the following workaround seems to work for me (avr target):

$ ./configure --target=avr
$ cd avr
$ ln -s ../config.sub			# for newlib/configure
$ ln -s ../install-sh			# for newlib/configure
$ ln -s ../newlib/configure.host	# for newlib/configure
$ ln -s ../newlib/libc			# for gcc to find header files
$ cd ..
$ make

I guess this is not the correct fix, but I hope it will give some
hints what is wrong.

One more thing: are there any plans to make more frequent snapshots
(newlib-2000xxxx.tar.bz2) from the newlib CVS tree?

Thanks,
Marek

/* begin patch */
diff -urN orig/src/newlib/libc/signal/signal.c src/newlib/libc/signal/signal.c
--- orig/src/newlib/libc/signal/signal.c	Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/signal/signal.c	Sat Mar 25 15:51:48 2000
@@ -144,7 +144,7 @@
 	int sig _AND
 	_sig_func_ptr func)
 {
-  _sig_func_ptr old_func, *temp;
+  _sig_func_ptr old_func;
 
   if (sig < 0 || sig >= NSIG)
     {
diff -urN orig/src/newlib/libc/stdio/findfp.c src/newlib/libc/stdio/findfp.c
--- orig/src/newlib/libc/stdio/findfp.c	Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/stdio/findfp.c	Sat Mar 25 14:50:01 2000
@@ -26,6 +26,8 @@
 static void
 std (ptr, flags, file, data)
      FILE *ptr;
+     int flags;
+     int file;
      struct _reent *data;
 {
   ptr->_p = 0;
diff -urN orig/src/newlib/libc/stdio/mktemp.c src/newlib/libc/stdio/mktemp.c
--- orig/src/newlib/libc/stdio/mktemp.c	Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/stdio/mktemp.c	Sat Mar 25 14:57:33 2000
@@ -102,7 +102,7 @@
 #include <ctype.h>
 #include <reent.h>
 
-static
+static int
 _DEFUN (_gettemp, (ptr, path, doopen),
 	struct _reent *ptr _AND
 	char *path _AND
@@ -182,6 +182,7 @@
   /*NOTREACHED*/
 }
 
+int
 _DEFUN (_mkstemp_r, (ptr, path),
 	struct _reent *ptr _AND
 	char *path)
@@ -201,6 +202,7 @@
 
 #ifndef _REENT_ONLY
 
+int
 _DEFUN (mkstemp, (path),
 	char *path)
 {
diff -urN orig/src/newlib/libc/stdio/putchar.c src/newlib/libc/stdio/putchar.c
--- orig/src/newlib/libc/stdio/putchar.c	Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/stdio/putchar.c	Sat Mar 25 14:59:36 2000
@@ -88,7 +88,7 @@
 {
   /* CHECK_INIT is (eventually) called by __swbuf.  */
 
-  _putchar_r (_REENT, c);
+  return _putchar_r (_REENT, c);
 }
 
 #endif
diff -urN orig/src/newlib/libc/stdio/refill.c src/newlib/libc/stdio/refill.c
--- orig/src/newlib/libc/stdio/refill.c	Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/stdio/refill.c	Sat Mar 25 15:01:11 2000
@@ -25,7 +25,7 @@
 lflush (fp)
      FILE *fp;
 {
-  if ((fp->_flags & (__SLBF | __SWR)) == __SLBF | __SWR)
+  if ((fp->_flags & (__SLBF | __SWR)) == (__SLBF | __SWR))
     return fflush (fp);
   return 0;
 }
diff -urN orig/src/newlib/libc/stdio/vfprintf.c src/newlib/libc/stdio/vfprintf.c
--- orig/src/newlib/libc/stdio/vfprintf.c	Mon Feb 21 17:59:23 2000
+++ src/newlib/libc/stdio/vfprintf.c	Sat Mar 25 15:03:40 2000
@@ -824,7 +824,7 @@
 					ox[0] = *cp++;
 					ox[1] = '.';
 					PRINT(ox, 2);
-					if (_double || flags & ALT == 0) {
+					if (_double || (flags & ALT) == 0) {
 						PRINT(cp, ndig-1);
 					} else	/* 0.[0..] */
 						/* __dtoa irregularity */
diff -urN orig/src/newlib/libc/stdio/vfscanf.c src/newlib/libc/stdio/vfscanf.c
--- orig/src/newlib/libc/stdio/vfscanf.c	Fri Mar 17 21:40:20 2000
+++ src/newlib/libc/stdio/vfscanf.c	Sat Mar 25 15:49:05 2000
@@ -825,7 +825,7 @@
 		     truncate some trailing digits to make room.  */
 		  if (exp_start >= buf + sizeof (buf) - MAX_LONG_LEN)
 		    exp_start = buf + sizeof (buf) - MAX_LONG_LEN - 1;
-		  sprintf (exp_start, "e%d", new_exp);
+		  sprintf (exp_start, "e%ld", new_exp);
 		}
 	      res = atof (buf);
 	      if (flags & LONG)
diff -urN orig/src/newlib/libc/stdlib/dtoa.c src/newlib/libc/stdlib/dtoa.c
--- orig/src/newlib/libc/stdlib/dtoa.c	Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/stdlib/dtoa.c	Sat Mar 25 14:33:32 2000
@@ -291,7 +291,7 @@
 #ifdef Sudden_Underflow
   i = (int) (word0 (d) >> Exp_shift1 & (Exp_mask >> Exp_shift1));
 #else
-  if (i = (int) (word0 (d) >> Exp_shift1 & (Exp_mask >> Exp_shift1)))
+  if ((i = (int) (word0 (d) >> Exp_shift1 & (Exp_mask >> Exp_shift1))) != 0)
     {
 #endif
       d2.d = d.d;
@@ -337,8 +337,8 @@
       /* d is denormalized */
 
       i = bbits + be + (Bias + (P - 1) - 1);
-      x = i > 32 ? word0 (d) << 64 - i | word1 (d) >> i - 32
-	: word1 (d) << 32 - i;
+      x = (i > 32) ? (word0 (d) << (64 - i)) | (word1 (d) >> (i - 32))
+	: (word1 (d) << (32 - i));
       d2.d = x;
       word0 (d2) -= 31 * Exp_msk1;	/* adjust exponent */
       i -= (Bias + (P - 1) - 1) + 1;
@@ -388,11 +388,11 @@
       try_quick = 0;
     }
   leftright = 1;
+  ilim = ilim1 = -1;
   switch (mode)
     {
     case 0:
     case 1:
-      ilim = ilim1 = -1;
       i = 18;
       ndigits = 0;
       break;
@@ -449,7 +449,7 @@
 	      }
 	  d.d /= ds;
 	}
-      else if (j1 = -k)
+      else if ((j1 = -k) != 0)
 	{
 	  d.d *= tens[j1 & 0xf];
 	  for (j = j1 >> 4; j; j >>= 1, i++)
@@ -564,7 +564,7 @@
 	  if (i == ilim)
 	    {
 	      d.d += d.d;
-	      if (d.d > ds || d.d == ds && L & 1)
+	      if ((d.d > ds) || ((d.d == ds) && (L & 1)))
 		{
 		bump_up:
 		  while (*--s == '9')
@@ -640,7 +640,7 @@
 	      Bfree (ptr, b);
 	      b = b1;
 	    }
-	  if (j = b5 - m5)
+	  if ((j = b5 - m5) != 0)
 	    b = pow5mult (ptr, b, j);
 	}
       else
@@ -652,6 +652,7 @@
 
   /* Check for special case that d is a normalized power of 2. */
 
+  spec_case = 0;
   if (mode < 2)
     {
       if (!word1 (d) && !(word0 (d) & Bndry_mask)
@@ -665,8 +666,6 @@
 	  s2 += Log2P;
 	  spec_case = 1;
 	}
-      else
-	spec_case = 0;
     }
 
   /* Arrange for convenient computation of quotients:
@@ -678,10 +677,10 @@
    */
 
 #ifdef Pack_32
-  if (i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0x1f)
+  if ((i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0x1f) != 0)
     i = 32 - i;
 #else
-  if (i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0xf)
+  if ((i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0xf) != 0)
     i = 16 - i;
 #endif
   if (i > 4)
@@ -765,17 +764,17 @@
 	      goto ret;
 	    }
 #endif
-	  if (j < 0 || j == 0 && !mode
+	  if ((j < 0) || ((j == 0) && !mode
 #ifndef ROUND_BIASED
 	      && !(word1 (d) & 1)
 #endif
-	    )
+	    ))
 	    {
 	      if (j1 > 0)
 		{
 		  b = lshift (ptr, b, 1);
 		  j1 = cmp (b, S);
-		  if ((j1 > 0 || j1 == 0 && dig & 1)
+		  if (((j1 > 0) || ((j1 == 0) && (dig & 1)))
 		      && dig++ == '9')
 		    goto round_9_up;
 		}
@@ -819,7 +818,7 @@
 
   b = lshift (ptr, b, 1);
   j = cmp (b, S);
-  if (j > 0 || j == 0 && dig & 1)
+  if ((j > 0) || ((j == 0) && (dig & 1)))
     {
     roundoff:
       while (*--s == '9')
diff -urN orig/src/newlib/libc/stdlib/ecvtbuf.c src/newlib/libc/stdlib/ecvtbuf.c
--- orig/src/newlib/libc/stdlib/ecvtbuf.c	Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/stdlib/ecvtbuf.c	Sat Mar 25 14:35:35 2000
@@ -151,7 +151,6 @@
 	char type _AND
 	int dot)
 {
-  int dp;
   int sign;
   char *end;
   char *p;
diff -urN orig/src/newlib/libc/stdlib/mbctype.h src/newlib/libc/stdlib/mbctype.h
--- orig/src/newlib/libc/stdlib/mbctype.h	Thu Feb 17 20:39:48 2000
+++ src/newlib/libc/stdlib/mbctype.h	Sat Mar 25 14:48:09 2000
@@ -12,8 +12,8 @@
 int _EXFUN(_iseucjp, (int c));
 int _EXFUN(_isjis, (int c));
 
-#define _issjis1(c)    ((c) >= 0x81 && (c) <= 0x9f || (c) >= 0xe0 && (c) <= 0xef)
-#define _issjis2(c)    ((c) >= 0x40 && (c) <= 0x7e || (c) >= 0x80 && (c) <= 0xfc)
+#define _issjis1(c)    (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xef))
+#define _issjis2(c)    (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))
 #define _iseucjp(c)    ((c) >= 0xa1 && (c) <= 0xfe)
 #define _isjis(c)      ((c) >= 0x21 && (c) <= 0x7e)
 
diff -urN orig/src/newlib/libc/stdlib/mprec.c src/newlib/libc/stdlib/mprec.c
--- orig/src/newlib/libc/stdlib/mprec.c	Thu Feb 17 20:39:48 2000
+++ src/newlib/libc/stdlib/mprec.c	Sat Mar 25 14:41:19 2000
@@ -107,7 +107,7 @@
 	}
     }
 
-  if (rv = ptr->_freelist[k])
+  if ((rv = ptr->_freelist[k]) != 0)
     {
       ptr->_freelist[k] = rv->_next;
     }
@@ -354,7 +354,7 @@
 #ifdef Pack_32
   for (; xb < xbe; xb++, xc0++)
     {
-      if (y = *xb & 0xffff)
+      if ((y = *xb & 0xffff) != 0)
 	{
 	  x = xa;
 	  xc = xc0;
@@ -370,7 +370,7 @@
 	  while (x < xae);
 	  *xc = carry;
 	}
-      if (y = *xb >> 16)
+      if ((y = *xb >> 16) != 0)
 	{
 	  x = xa;
 	  xc = xc0;
@@ -420,7 +420,7 @@
   int i;
   static _CONST int p05[3] = {5, 25, 125};
 
-  if (i = k & 3)
+  if ((i = k & 3) != 0)
     b = multadd (ptr, b, p05[i - 1], 0);
 
   if (!(k >>= 2))
@@ -484,7 +484,7 @@
 	  z = *x++ >> k1;
 	}
       while (x < xe);
-      if (*x1 = z)
+      if ((*x1 = z) != 0)
 	++n1;
     }
 #else
@@ -697,17 +697,17 @@
 #ifdef Pack_32
   if (k < Ebits)
     {
-      d0 = Exp_1 | y >> Ebits - k;
+      d0 = Exp_1 | y >> (Ebits - k);
       w = xa > xa0 ? *--xa : 0;
 #ifndef _DOUBLE_IS_32BITS
-      d1 = y << (32 - Ebits) + k | w >> Ebits - k;
+      d1 = y << ((32 - Ebits) + k) | w >> (Ebits - k);
 #endif
       goto ret_d;
     }
   z = xa > xa0 ? *--xa : 0;
   if (k -= Ebits)
     {
-      d0 = Exp_1 | y << k | z >> 32 - k;
+      d0 = Exp_1 | y << k | z >> (32 - k);
       y = xa > xa0 ? *--xa : 0;
 #ifndef _DOUBLE_IS_32BITS
       d1 = z << k | y >> 32 - k;
@@ -789,7 +789,7 @@
   z |= Exp_msk11;
 #endif
 #else
-  if (de = (int) (d0 >> Exp_shift))
+  if ((de = (int) (d0 >> Exp_shift)) != 0)
     z |= Exp_msk1;
 #endif
 #ifdef Pack_32
diff -urN orig/src/newlib/libc/stdlib/setenv_r.c src/newlib/libc/stdlib/setenv_r.c
--- orig/src/newlib/libc/stdlib/setenv_r.c	Thu Feb 17 20:39:48 2000
+++ src/newlib/libc/stdlib/setenv_r.c	Sat Mar 25 14:44:03 2000
@@ -64,7 +64,7 @@
         }
       if (strlen (C) >= l_value)
 	{			/* old larger; copy over */
-	  while (*C++ = *value++);
+	  while ((*C++ = *value++) != 0);
           ENV_UNLOCK;
 	  return 0;
 	}
@@ -108,7 +108,7 @@
       return -1;
     }
   for (C = environ[offset]; (*C = *name++) && *C != '='; ++C);
-  for (*C++ = '='; *C++ = *value++;);
+  for (*C++ = '='; (*C++ = *value++) != 0;);
 
   ENV_UNLOCK;
 
diff -urN orig/src/newlib/libc/stdlib/strtod.c src/newlib/libc/stdlib/strtod.c
--- orig/src/newlib/libc/stdlib/strtod.c	Thu Feb 17 20:39:48 2000
+++ src/newlib/libc/stdlib/strtod.c	Sat Mar 25 14:44:41 2000
@@ -316,7 +316,7 @@
 
   if (e1 > 0)
     {
-      if (i = e1 & 15)
+      if ((i = e1 & 15) != 0)
 	rv.d *= tens[i];
       if (e1 &= ~15)
 	{
@@ -373,7 +373,7 @@
   else if (e1 < 0)
     {
       e1 = -e1;
-      if (i = e1 & 15)
+      if ((i = e1 & 15) != 0)
 	rv.d /= tens[i];
       if (e1 &= ~15)
 	{
diff -urN orig/src/newlib/libc/stdlib/strtol.c src/newlib/libc/stdlib/strtol.c
--- orig/src/newlib/libc/stdlib/strtol.c	Thu Feb 17 20:39:48 2000
+++ src/newlib/libc/stdlib/strtol.c	Sat Mar 25 14:45:04 2000
@@ -194,7 +194,7 @@
 			break;
 		if (c >= base)
 			break;
-		if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
 			any = -1;
 		else {
 			any = 1;
diff -urN orig/src/newlib/libc/stdlib/strtoul.c src/newlib/libc/stdlib/strtoul.c
--- orig/src/newlib/libc/stdlib/strtoul.c	Thu Feb 17 20:39:48 2000
+++ src/newlib/libc/stdlib/strtoul.c	Sat Mar 25 14:45:15 2000
@@ -174,7 +174,7 @@
 			break;
 		if (c >= base)
 			break;
-		if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
 			any = -1;
 		else {
 			any = 1;
diff -urN orig/src/newlib/libm/common/sf_expm1.c src/newlib/libm/common/sf_expm1.c
--- orig/src/newlib/libm/common/sf_expm1.c	Thu Feb 17 20:39:51 2000
+++ src/newlib/libm/common/sf_expm1.c	Sat Mar 25 15:57:59 2000
@@ -102,9 +102,10 @@
 	    e  = (x*(e-c)-c);
 	    e -= hxs;
 	    if(k== -1) return (float)0.5*(x-e)-(float)0.5;
-	    if(k==1) 
+	    if(k==1) {
 	       	if(x < (float)-0.25) return -(float)2.0*(e-(x+(float)0.5));
 	       	else 	      return  one+(float)2.0*(x-e);
+	    }
 	    if (k <= -2 || k>56) {   /* suffice to return exp(x)-1 */
 	        __int32_t i;
 	        y = one-(e-x);
diff -urN orig/src/newlib/libm/common/sf_log1p.c src/newlib/libm/common/sf_log1p.c
--- orig/src/newlib/libm/common/sf_log1p.c	Thu Feb 17 20:39:51 2000
+++ src/newlib/libm/common/sf_log1p.c	Sat Mar 25 15:58:21 2000
@@ -93,8 +93,8 @@
 	}
 	hfsq=(float)0.5*f*f;
 	if(hu==0) {	/* |f| < 2**-20 */
-	    if(f==zero) if(k==0) return zero;  
-			else {c += k*ln2_lo; return k*ln2_hi+c;}
+	    if(f==zero) { if(k==0) return zero;  
+			else {c += k*ln2_lo; return k*ln2_hi+c;}}
 	    R = hfsq*((float)1.0-(float)0.66666666666666666*f);
 	    if(k==0) return f-R; else
 	    	     return k*ln2_hi-((R-(k*ln2_lo+c))-f);
diff -urN orig/src/newlib/libm/common/sf_scalbn.c src/newlib/libm/common/sf_scalbn.c
--- orig/src/newlib/libm/common/sf_scalbn.c	Thu Feb 17 20:39:51 2000
+++ src/newlib/libm/common/sf_scalbn.c	Sat Mar 25 15:57:24 2000
@@ -54,10 +54,11 @@
         if (k >  0xfe) return huge*copysignf(huge,x); /* overflow  */
         if (k > 0) 				/* normal result */
 	    {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
-        if (k <= -25)
+        if (k <= -25) {
             if (n > OVERFLOW_INT) 	/* in case integer overflow in n+k */
 		return huge*copysignf(huge,x);	/*overflow*/
 	    else return tiny*copysignf(tiny,x);	/*underflow*/
+	}
         k += 25;				/* subnormal result */
 	SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
         return x*twom25;
diff -urN orig/src/newlib/libm/math/ef_log.c src/newlib/libm/math/ef_log.c
--- orig/src/newlib/libm/math/ef_log.c	Thu Feb 17 20:39:51 2000
+++ src/newlib/libm/math/ef_log.c	Sat Mar 25 15:56:20 2000
@@ -65,8 +65,8 @@
 	k += (i>>23);
 	f = x-(float)1.0;
 	if((0x007fffff&(15+ix))<16) {	/* |f| < 2**-20 */
-	    if(f==zero) if(k==0) return zero;  else {dk=(float)k;
-				 return dk*ln2_hi+dk*ln2_lo;}
+	    if(f==zero) { if(k==0) return zero;  else {dk=(float)k;
+				 return dk*ln2_hi+dk*ln2_lo;}}
 	    R = f*f*((float)0.5-(float)0.33333333333333333*f);
 	    if(k==0) return f-R; else {dk=(float)k;
 	    	     return dk*ln2_hi-((R-dk*ln2_lo)-f);}
/* end patch */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]