On 10/01/2010 03:21 PM, Sven Neumann wrote:
On Fri, 2010-10-01 at 00:46 -0700, Patrick Horgan wrote:
  The fix would be to make a union:

       union {
          gchar idaschars[16];
          int idasints[4];
      } id;

and access the appropriate sections.

    id.idasints[0] = ebx;
    id.idasints[1] = edx;
    id.idasints[2] = ecx;

    id.idaschars[12] = '\0';

then do the comparisons against id.idaschars.
Could you send a patch please, preferably generated from a git commit?
Ok.  Attached.

Patrick
>From 11c9c527cf080a8f3554ab82788f1cfa3115a4d9 Mon Sep 17 00:00:00 2001
From: Patrick Horgan <phorg...@gmail.com>
Date: Sat, 2 Oct 2010 19:32:31 -0700
Subject: [PATCH] Avoid aliasing error by using a union for id instead of casting address to a int*.

---
 libgimpbase/gimpcpuaccel.c |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/libgimpbase/gimpcpuaccel.c b/libgimpbase/gimpcpuaccel.c
index 3162f58..40dea27 100644
--- a/libgimpbase/gimpcpuaccel.c
+++ b/libgimpbase/gimpcpuaccel.c
@@ -151,7 +151,10 @@ static X86Vendor
 arch_get_vendor (void)
 {
   guint32 eax, ebx, ecx, edx;
-  gchar   id[16];
+  union{
+      gchar idaschar[16];
+      int   idasint[4];
+  }id;
 
 #ifndef ARCH_X86_64
   /* Only need to check this on ia32 */
@@ -179,38 +182,38 @@ arch_get_vendor (void)
   if (eax == 0)
     return ARCH_X86_VENDOR_NONE;
 
-  *(int *)&id[0] = ebx;
-  *(int *)&id[4] = edx;
-  *(int *)&id[8] = ecx;
+  id.idasint[0] = ebx;
+  id.idasint[1] = edx;
+  id.idasint[2] = ecx;
 
-  id[12] = '\0';
+  id.idaschar[12] = '\0';
 
 #ifdef ARCH_X86_64
-  if (strcmp (id, "AuthenticAMD") == 0)
+  if (strcmp (id.idaschar, "AuthenticAMD") == 0)
     return ARCH_X86_VENDOR_AMD;
-  else if (strcmp (id, "GenuineIntel") == 0)
+  else if (strcmp (id.idaschar, "GenuineIntel") == 0)
     return ARCH_X86_VENDOR_INTEL;
 #else
-  if (strcmp (id, "GenuineIntel") == 0)
+  if (strcmp (id.idaschar, "GenuineIntel") == 0)
     return ARCH_X86_VENDOR_INTEL;
-  else if (strcmp (id, "AuthenticAMD") == 0)
+  else if (strcmp (id.idaschar, "AuthenticAMD") == 0)
     return ARCH_X86_VENDOR_AMD;
-  else if (strcmp (id, "CentaurHauls") == 0)
+  else if (strcmp (id.idaschar, "CentaurHauls") == 0)
     return ARCH_X86_VENDOR_CENTAUR;
-  else if (strcmp (id, "CyrixInstead") == 0)
+  else if (strcmp (id.idaschar, "CyrixInstead") == 0)
     return ARCH_X86_VENDOR_CYRIX;
-  else if (strcmp (id, "Geode by NSC") == 0)
+  else if (strcmp (id.idaschar, "Geode by NSC") == 0)
     return ARCH_X86_VENDOR_NSC;
-  else if (strcmp (id, "GenuineTMx86") == 0 ||
-           strcmp (id, "TransmetaCPU") == 0)
+  else if (strcmp (id.idaschar, "GenuineTMx86") == 0 ||
+           strcmp (id.idaschar, "TransmetaCPU") == 0)
     return ARCH_X86_VENDOR_TRANSMETA;
-  else if (strcmp (id, "NexGenDriven") == 0)
+  else if (strcmp (id.idaschar, "NexGenDriven") == 0)
     return ARCH_X86_VENDOR_NEXGEN;
-  else if (strcmp (id, "RiseRiseRise") == 0)
+  else if (strcmp (id.idaschar, "RiseRiseRise") == 0)
     return ARCH_X86_VENDOR_RISE;
-  else if (strcmp (id, "UMC UMC UMC ") == 0)
+  else if (strcmp (id.idaschar, "UMC UMC UMC ") == 0)
     return ARCH_X86_VENDOR_UMC;
-  else if (strcmp (id, "SiS SiS SiS ") == 0)
+  else if (strcmp (id.idaschar, "SiS SiS SiS ") == 0)
     return ARCH_X86_VENDOR_SIS;
 #endif
 
-- 
1.7.0.4

_______________________________________________
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

Reply via email to