WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH]: minios: eliminate compile warning - use of unin

To: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH]: minios: eliminate compile warning - use of uninitialised variable
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
Date: Fri, 7 Jan 2011 20:27:59 +0100
Cc: Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>, Stefano Stabellini <Stefano.Stabellini@xxxxxxxxxxxxx>
Delivery-date: Fri, 07 Jan 2011 11:32:43 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1294420919.12018.89.camel@xxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>, Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>, Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>, Stefano Stabellini <Stefano.Stabellini@xxxxxxxxxxxxx>
References: <1294419169.12018.79.camel@xxxxxxxxxxxxxxxxxxxxxx> <20110107165822.GX5820@xxxxxxxxxxxxxxxxxxxxxxx> <1294420919.12018.89.camel@xxxxxxxxxxxxxxxxxxxxxx>
Resent-date: Fri, 7 Jan 2011 20:32:08 +0100
Resent-from: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
Resent-message-id: <20110107193208.GF5418@xxxxxxxxxxxxxxxxxxxxxxxxx>
Resent-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
Gianni Tedesco, le Fri 07 Jan 2011 17:21:59 +0000, a écrit :
> On Fri, 2011-01-07 at 16:58 +0000, Samuel Thibault wrote:
> > Gianni Tedesco, le Fri 07 Jan 2011 16:52:49 +0000, a écrit :
> > > I'm not sure if this is a legit catch by gcc or a false positive due to
> > > extra cleverness in gcc-4.5. Either way it causes the build to barf.
> > 
> > It seems a false positive to me. What is the warning message?
> 
> lib/math.c:197:22: error: ‘tmp.ul[1]’ may be used uninitialized in this 
> function
> lib/math.c:153:11: note: ‘tmp.ul[1]’ was declared here
> 
> I figured it was a false positive but looking at it now, maybe not?

Oooh, is this perhaps on a 64bit machine? There is actually a bug: these
should be ints, not longs... Use this instead.

Samuel

Replace long/int/short sizes with proper exact-size types for 64bit
architectures.

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>

diff -r a33886146b45 extras/mini-os/lib/math.c
--- a/extras/mini-os/lib/math.c Fri Oct 08 11:41:57 2010 +0100
+++ b/extras/mini-os/lib/math.c Fri Jan 07 20:26:34 2011 +0100
@@ -70,8 +70,8 @@
 union uu {
         int64_t           q;              /* as a (signed) quad */
         int64_t          uq;             /* as an unsigned quad */
-        long           sl[2];          /* as two signed longs */
-        unsigned long  ul[2];          /* as two unsigned longs */
+        int32_t        sl[2];          /* as two signed ints */
+        uint32_t       ul[2];          /* as two unsigned ints */
 };
 /* XXX RN: Yuck hardcoded endianess :) */
 #define _QUAD_HIGHWORD 1
@@ -91,17 +91,17 @@
 #define CHAR_BIT        8               /* number of bits in a char */
 #endif
 #define QUAD_BITS       (sizeof(int64_t) * CHAR_BIT)
-#define LONG_BITS       (sizeof(long) * CHAR_BIT)
-#define HALF_BITS       (sizeof(long) * CHAR_BIT / 2)
+#define LONG_BITS       (sizeof(int32_t) * CHAR_BIT)
+#define HALF_BITS       (sizeof(int32_t) * CHAR_BIT / 2)
 
 /*
- * Extract high and low shortwords from longword, and move low shortword of
- * longword to upper half of long, i.e., produce the upper longword of
- * ((quad_t)(x) << (number_of_bits_in_long/2)).  (`x' must actually be u_long.)
+ * Extract high and low shortwords from intword, and move low shortword of
+ * intword to upper half of int32_t, i.e., produce the upper intword of
+ * ((quad_t)(x) << (number_of_bits_in_int/2)).  (`x' must actually be 
uint32_t.)
  *
- * These are used in the multiply code, to split a longword into upper
+ * These are used in the multiply code, to split a intword into upper
  * and lower halves, and to reassemble a product as a quad_t, shifted left
- * (sizeof(long)*CHAR_BIT/2).
+ * (sizeof(int32_t)*CHAR_BIT/2).
  */
 #define HHALF(x)        ((x) >> HALF_BITS)
 #define LHALF(x)        ((x) & ((1UL << HALF_BITS) - 1))
@@ -114,14 +114,10 @@
 #define        B       (1UL << HALF_BITS)      /* digit base */
 
 /* Combine two `digits' to make a single two-digit number. */
-#define        COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b))
+#define        COMBINE(a, b) (((uint32_t)(a) << HALF_BITS) | (b))
 
-/* select a type for digits in base B: use unsigned short if they fit */
-#if ULONG_MAX == 0xffffffff && USHRT_MAX >= 0xffff
-typedef unsigned short digit;
-#else
-typedef u_long digit;
-#endif
+/* select a type for digits in base B: */
+typedef uint16_t digit;
 
 
 /*
@@ -143,7 +139,7 @@
  * __qdivrem(u, v, rem) returns u/v and, optionally, sets *rem to u%v.
  *
  * We do this in base 2-sup-HALF_BITS, so that all intermediate products
- * fit within u_long.  As a consequence, the maximum length dividend and
+ * fit within uint32_t.  As a consequence, the maximum length dividend and
  * divisor are 4 `digits' in this base (they are shorter if they have
  * leading zeros).
  */
@@ -153,7 +149,7 @@
        union uu tmp;
        digit *u, *v, *q;
        register digit v1, v2;
-       u_long qhat, rhat, t;
+       uint32_t qhat, rhat, t;
        int m, n, d, j, i;
        digit uspace[5], vspace[5], qspace[5];
 
@@ -204,7 +200,7 @@
        v[4] = LHALF(tmp.ul[L]);
        for (n = 4; v[1] == 0; v++) {
                if (--n == 1) {
-                       u_long rbj;     /* r*B+u[j] (not root boy jim) */
+                       uint32_t rbj;   /* r*B+u[j] (not root boy jim) */
                        digit q1, q2, q3, q4;
 
                        /*
@@ -280,7 +276,7 @@
                        rhat = uj1;
                        goto qhat_too_big;
                } else {
-                       u_long nn = COMBINE(uj0, uj1);
+                       uint32_t nn = COMBINE(uj0, uj1);
                        qhat = nn / v1;
                        rhat = nn % v1;
                }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel