On Mon, 2009-05-04 at 12:21 +0200, Uwe Hermann wrote:
> Hi,
> 
> I uploaded a new Debian package of OpenOCD recently (based on r1583)
> which produced a number of build warnings (now errors because of
> -Werror). Haven't had the time to look into the issues, but the build
> logs could be useful for others:
> 
> https://buildd.debian.org/pkg.cgi?pkg=openocd
> 
> Please follow every link in the "State" column there for a build log,
> except i386 and powerpc (which build fine). All other architectures
> fail to build as of r1583. s390 and arm are intentionally not built
> (at the moment at least).

The attached patch should fix the cast alignment warnings caused by
jim.c on platforms with stricter alignment rules.

If you get more problems, please run the builds with --disable-werror so
I can try to fix all of them in one pass.

Cheers,

Zach
Index: src/helper/jim.c
===================================================================
--- src/helper/jim.c	(revision 1602)
+++ src/helper/jim.c	(working copy)
@@ -7650,6 +7650,8 @@
                 scanned += 1;
                 break;
             case 'd': case 'o': case 'x': case 'u': case 'i': {
+                jim_wide jwvalue;
+                long lvalue;
                 char *endp;  /* Position where the number finished */
                 int base = descr->type == 'o' ? 8
                     : descr->type == 'x' ? 16
@@ -7659,16 +7661,22 @@
                 do {
                     /* Try to scan a number with the given base */
                     if (descr->modifier == 'l')
+                    {
 #ifdef HAVE_LONG_LONG
-                      *(jim_wide*)value = JimStrtoll(tok, &endp, base);
+                        jwvalue = JimStrtoll(tok, &endp, base),
 #else
-                      *(jim_wide*)value = strtol(tok, &endp, base);
+                        jwvalue = strtol(tok, &endp, base),
 #endif
+                        memcpy(value, &jwvalue, sizeof(jim_wide));
+                    }
                     else
+                    {
                       if (descr->type == 'u')
-                        *(long*)value = strtoul(tok, &endp, base);
+                        lvalue = strtoul(tok, &endp, base);
                       else
-                        *(long*)value = strtol(tok, &endp, base);
+                        lvalue = strtol(tok, &endp, base);
+                      memcpy(value, &lvalue, sizeof(lvalue));
+                    }
                     /* If scanning failed, and base was undetermined, simply
                      * put it to 10 and try once more. This should catch the
                      * case where %i begin to parse a number prefix (e.g. 
@@ -7680,9 +7688,9 @@
                 if (endp != tok) {
                     /* There was some number sucessfully scanned! */
                     if (descr->modifier == 'l')
-                        *valObjPtr = Jim_NewIntObj(interp, *(jim_wide*)value);
+                        *valObjPtr = Jim_NewIntObj(interp, jwvalue);
                     else
-                        *valObjPtr = Jim_NewIntObj(interp, *(long*)value);
+                        *valObjPtr = Jim_NewIntObj(interp, lvalue);
                     /* Adjust the number-of-chars scanned so far */
                     scanned += endp - tok;
                 } else {
@@ -7701,10 +7709,11 @@
             case 'e': case 'f': case 'g': {
                 char *endp;
 
-                *(double*)value = strtod(tok, &endp);
+                double dvalue = strtod(tok, &endp);
+                memcpy(value, &dvalue, sizeof(double));
                 if (endp != tok) {
                     /* There was some number sucessfully scanned! */
-                    *valObjPtr = Jim_NewDoubleObj(interp, *(double*)value);
+                    *valObjPtr = Jim_NewDoubleObj(interp, dvalue);
                     /* Adjust the number-of-chars scanned so far */
                     scanned += endp - tok;
                 } else {
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to