diff dyncall/dyncall_aggregate_x64.c @ 551:eef302b7a58d

- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts - changelog wording tweaks for clarity - comment tweaks for clarity - (mostly pointless) microoptimization in aggr alignment calculation, avoiding a modulo, as alignment always a power of 2 - cleanups
author Tassilo Philipp
date Mon, 20 Jun 2022 14:57:49 +0200
parents ba70fb631bea
children
line wrap: on
line diff
--- a/dyncall/dyncall_aggregate_x64.c	Mon Jun 20 14:24:37 2022 +0200
+++ b/dyncall/dyncall_aggregate_x64.c	Mon Jun 20 14:57:49 2022 +0200
@@ -70,7 +70,8 @@
       continue;
 
     /* if field is unaligned, class is MEMORY */
-    if(f->alignment && (offset % f->alignment) != 0)
+    assert((f->alignment & (f->alignment - 1)) == 0);      /* f->alignment required to be a power of 2*/
+    if(f->alignment && (offset & (f->alignment - 1)) != 0) /* offset not a multiple of (power of 2) f->alignment? */
       return SYSVC_MEMORY;
 
     DCuchar new_class = SYSVC_NONE;
@@ -96,8 +97,8 @@
         new_class = SYSVC_SSE;
         break;
       case DC_SIGCHAR_AGGREGATE:
-	    /* skip empty structs */
-	    if(f->size)
+        /* skip empty structs */
+        if(f->size)
         {
           /* aggregate arrays need to be checked per element, as an aggregate can be composed of
            * multiple types, potentially split across an 8byte; loop only over parts within 8byte */
@@ -106,11 +107,8 @@
           if(k > f->array_len)
             k = f->array_len;
 
-          for(; j<k; ++j) {
-            //@@@STRUCT new_class = dc_get_sysv_class_for_8byte(f->sub_aggr, index, offset + f->size*j);
-            //@@@STRUCT clz = dc_merge_sysv_classes(clz, new_class);
+          for(; j<k; ++j)
             new_class = dc_merge_sysv_classes(new_class, dc_get_sysv_class_for_8byte(f->sub_aggr, index, offset + f->size*j));
-          }
         }
         break;
       /*case DClongdouble, DCcomplexfloat DCcomplexdouble DCcomplexlongdouble etc... -> x87/x87up/complexx87 classes @@@AGGR implement */