]> git.wh0rd.org - fontconfig.git/commitdiff
Fix for unaligned memory accesses.
authorPatrick Lam <plam@MIT.EDU>
Thu, 19 Jan 2006 19:20:30 +0000 (19:20 +0000)
committerPatrick Lam <plam@MIT.EDU>
Thu, 19 Jan 2006 19:20:30 +0000 (19:20 +0000)
reviewed by: plam

ChangeLog
src/fcpat.c

index 18a626caa89b9e7a2d5eff1d3a5599ac4c079cbe..98e404c51cf9acb932b1b98280212faf880014cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-01-19  Andreas Schwab  <schwab@suse.de>
+       reviewed by: plam
+
+       * src/fcpat.c (FcStrNeededBytes):
+
+       Fix for unaligned memory accesses.
+
 2006-01-18  Mike Fabian  <mfabian@suse.de>
        reviewed by: plam
        
@@ -6,7 +13,7 @@
        Properly order the FcConfigAddFontDir and FcConfigNormalizeFontDir
        calls to avoid crashes.
 
-2006-01-14  Patirck Lam  <plam@mit.edu>
+2006-01-14  Patrick Lam  <plam@mit.edu>
        * src/fccache.c (FcDirCacheConsume):
 
        Fix segfault when consuming zero-length caches in fc-cat
index f1506140651cfa142325c5be8bdfcf94e7e61310..aa1e8d6bffef8088e5d0b4f7ce718a6e1bc45dc7 100644 (file)
@@ -1888,6 +1888,7 @@ FcStrNeededBytes (const FcChar8 * s)
     struct objectBucket **p;
     struct objectBucket *b;
     int                 size;
+    FcChar8 *const null = 0;
 
     for (p = &FcStrBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
         if (b->hash == hash && !strcmp ((char *)s, (char *) (b + 1)))
@@ -1905,7 +1906,8 @@ FcStrNeededBytes (const FcChar8 * s)
      * incorrect to replace the with a memset, because the C
      * specification doesn't guarantee that the null pointer is
      * the same as the zero bit pattern. */
-    *(char **)((char *) (b + 1) + strlen((char *)s) + 1) = 0;
+    /* Misaligned pointers are not guaranteed to work, either! */
+    memcpy (((char *) (b + 1) + strlen((char *)s) + 1), &null, sizeof (null));
     *p = b;
 
     fcstr_count += strlen((char *)s) + 1;
@@ -1968,13 +1970,15 @@ FcStrSerialize (int bank, const FcChar8 * s)
     for (p = &FcStrBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
         if (b->hash == hash && !strcmp ((char *)s, (char *) (b + 1)))
        {
-           FcChar8 * t = *(FcChar8 **)(((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1);
+           FcChar8 * t;
+           memcpy (&t, ((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1, sizeof (FcChar8 *));
            if (!t)
            {
                strcpy((char *)(static_strs[bi] + fcstr_ptr), (char *)s);
-               *(FcChar8 **)((FcChar8 *) (b + 1) + strlen((char *)s) + 1) = (static_strs[bi] + fcstr_ptr);
+               t = static_strs[bi] + fcstr_ptr;
+               memcpy ((FcChar8 *) (b + 1) + strlen((char *)s) + 1, &t, sizeof (FcChar8 *));
                fcstr_ptr += strlen((char *)s) + 1;
-               t = *(FcChar8 **)(((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1);
+               memcpy (&t, ((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1, sizeof (FcChar8 *));
            }
            return t;
        }