OSSP CVS Repository

ossp - Check-in [3175]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3175
Date: 2003-Feb-06 17:58:40 (local)
2003-Feb-06 16:58:40 (UTC)
User:thl
Branch:
Comment: swap keyptr/datptr to fix datptr alignment problem on non-i386 architectures [mlelstv]
Tickets:
Inspections:
Files:
ossp-pkg/val/val.c      1.13 -> 1.14     13 inserted, 13 deleted

ossp-pkg/val/val.c 1.13 -> 1.14

--- val.c        2003/02/02 14:22:43     1.13
+++ val.c        2003/02/06 16:58:40     1.14
@@ -123,8 +123,8 @@
 #define SEGINDEX(addr) (int)((addr) % SEGMENTSIZE)
 
 /* on-the-fly calculate lengths of key and data to reduce memory in element_t */
-#define el_keylen(el) ((char *)((el)->e_datptr)-(char *)((el)->e_keyptr))
-#define el_datlen(el) ((char *)((el)->e_endptr)-(char *)((el)->e_datptr))
+#define el_keylen(el) ((char *)((el)->e_endptr)-(char *)((el)->e_keyptr))
+#define el_datlen(el) ((char *)((el)->e_keyptr)-(char *)((el)->e_datptr))
 
 /*
  * BJDDJ Hash Function (Bob Jenkins, Dr. Dobbs Journal):
@@ -384,15 +384,15 @@
     /* create a duplicate of key and data */
     if ((vp = malloc(keylen+datlen)) == NULL)
         return FALSE;
-    memmove(vp, keyptr, keylen);
-    memmove((char *)vp+keylen, datptr, datlen);
-    keyptr = vp;
-    datptr = (char *)vp+keylen;
+    memmove(vp, datptr, datlen);
+    memmove(((char *)vp)+datlen, keyptr, keylen);
+    datptr = vp;
+    keyptr = ((char *)vp)+datlen;
 
     if (bFound) {
         /* reuse existing element by freeing old contents */
-        if (el->e_keyptr != NULL)
-            free(el->e_keyptr);
+        if (el->e_datptr != NULL)
+            free(el->e_datptr);
     }
     else {
         /* allocate new element and chain into list */
@@ -409,7 +409,7 @@
     /* insert contents into element structure */
     el->e_keyptr = (void *)keyptr;
     el->e_datptr = (void *)datptr;
-    el->e_endptr = (char *)datptr+datlen;
+    el->e_endptr = (char *)keyptr+keylen;
     el->e_hash   = hash;
 
     /* do we need to expand the table now? */
@@ -481,8 +481,8 @@
             && el_keylen(el) == keylen
             && memcmp(el->e_keyptr, keyptr, el_keylen(el)) == 0) {
             /* free key+data memory chunk */
-            if (el->e_keyptr != NULL)
-                free(el->e_keyptr);
+            if (el->e_datptr != NULL)
+                free(el->e_datptr);
             /* remove element from collision chain */
             if (lel == NULL)
                 *pel = el->e_next; 
@@ -553,8 +553,8 @@
             pel = &h->h_dir[i]->s_element[j];
             for (el = *pel; el != NULL; ) {
                 /* deallocate key+data memory chunk */
-                if (el->e_keyptr != NULL)
-                    free(el->e_keyptr);
+                if (el->e_datptr != NULL)
+                    free(el->e_datptr);
                 el_next = el->e_next;
                 free(el);
                 el = el_next;

CVSTrac 2.0.1