commit 3429b552bc4367136f015c182f723ee977bb55a3
parent 954a9f9100e8f30e0303a3815c4104526aceb4a0
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sat, 28 Sep 2024 17:47:49 +0200
Solved alignment UB issue
Diffstat:
4 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/src/solvers/tables.h b/src/solvers/tables.h
@@ -7,34 +7,34 @@
#define TABLETYPE_PRUNING 0
#define TABLETYPE_SPECIAL 1
-#define INFO_OFFSET_SOLVER 0
-#define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN
+#define INFO_OFFSET_DISTRIBUTION 0
+#define INFO_OFFSET_TYPE (INFO_DISTRIBUTION_LEN * sizeof(uint64_t))
#define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t))
#define INFO_OFFSET_FULLSIZE (INFO_OFFSET_INFOSIZE + sizeof(uint64_t))
#define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t))
#define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t))
#define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t))
-#define INFO_OFFSET_H48H (INFO_OFFSET_CLASSES + sizeof(uint64_t))
+#define INFO_OFFSET_NEXT (INFO_OFFSET_CLASSES + sizeof(uint64_t))
+#define INFO_OFFSET_SOLVER (INFO_OFFSET_NEXT + sizeof(uint64_t))
+#define INFO_OFFSET_H48H (INFO_OFFSET_SOLVER + INFO_SOLVER_STRLEN)
#define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t))
#define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t))
#define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t))
-#define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t))
-#define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t))
typedef struct {
- char solver[INFO_SOLVER_STRLEN];
+ uint64_t distribution[INFO_DISTRIBUTION_LEN];
uint64_t type;
uint64_t infosize;
uint64_t fullsize;
uint64_t hash;
uint64_t entries;
uint64_t classes; /* Used only by cocsepdata, for now */
+ uint64_t next;
+ char solver[INFO_SOLVER_STRLEN];
uint8_t h48h; /* Specific to H48 tables */
uint8_t bits;
uint8_t base;
uint8_t maxvalue;
- uint64_t next;
- uint64_t distribution[INFO_DISTRIBUTION_LEN];
} tableinfo_t;
STATIC bool readtableinfo(const void *, tableinfo_t *);
@@ -54,21 +54,24 @@ readtableinfo(const void *buf, tableinfo_t *info)
return false;
}
- memcpy(info->solver, OFFSET(buf, INFO_OFFSET_SOLVER),
- INFO_SOLVER_STRLEN);
+ memcpy(info->distribution, OFFSET(buf, INFO_OFFSET_DISTRIBUTION),
+ INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
+
info->type = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_TYPE);
info->infosize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE);
info->fullsize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE);
info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH);
info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES);
info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES);
+ info->next = *(const uint64_t* )OFFSET(buf, INFO_OFFSET_NEXT);
+
+ memcpy(info->solver, OFFSET(buf, INFO_OFFSET_SOLVER),
+ INFO_SOLVER_STRLEN);
+
info->h48h = *OFFSET(buf, INFO_OFFSET_H48H);
info->bits = *OFFSET(buf, INFO_OFFSET_BITS);
info->base = *OFFSET(buf, INFO_OFFSET_BASE);
info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE);
- info->next = *(const uint64_t* )OFFSET(buf, INFO_OFFSET_NEXT);
- memcpy(info->distribution, OFFSET(buf, INFO_OFFSET_DISTRIBUTION),
- INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
return true;
}
@@ -98,6 +101,17 @@ writetableinfo(const tableinfo_t *info, void *buf)
return false;
}
+ memcpy(OFFSET(buf, INFO_OFFSET_DISTRIBUTION), info->distribution,
+ INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
+
+ *(uint64_t *)OFFSET(buf, INFO_OFFSET_TYPE) = info->type;
+ *(uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE) = info->infosize;
+ *(uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE) = info->fullsize;
+ *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash;
+ *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries;
+ *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes;
+ *(uint64_t *)OFFSET(buf, INFO_OFFSET_NEXT) = info->next;
+
memcpy(OFFSET(buf, INFO_OFFSET_SOLVER), info->solver,
INFO_SOLVER_STRLEN);
@@ -106,20 +120,10 @@ writetableinfo(const tableinfo_t *info, void *buf)
if (*OFFSET(buf, i) == 0)
*OFFSET(buf, i) = 0;
- *(uint64_t *)OFFSET(buf, INFO_OFFSET_TYPE) = info->type;
- *(uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE) = info->infosize;
- *(uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE) = info->fullsize;
- *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash;
- *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries;
- *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes;
*OFFSET(buf, INFO_OFFSET_H48H) = info->h48h;
*OFFSET(buf, INFO_OFFSET_BITS) = info->bits;
*OFFSET(buf, INFO_OFFSET_BASE) = info->base;
*OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue;
- *(uint64_t *)OFFSET(buf, INFO_OFFSET_NEXT) = info->next;
-
- memcpy(OFFSET(buf, INFO_OFFSET_DISTRIBUTION), info->distribution,
- INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
return true;
}
diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c
@@ -5,19 +5,19 @@
#define INFO_DISTRIBUTION_LEN 21
typedef struct {
- char solver[INFO_SOLVER_STRLEN];
+ uint64_t distribution[INFO_DISTRIBUTION_LEN];
uint64_t type;
uint64_t infosize;
uint64_t fullsize;
uint64_t hash;
uint64_t entries;
uint64_t classes;
+ uint64_t next;
+ char solver[INFO_SOLVER_STRLEN];
uint8_t h48h;
uint8_t bits;
uint8_t base;
uint8_t maxvalue;
- uint64_t next;
- uint64_t distribution[INFO_DISTRIBUTION_LEN];
} tableinfo_t;
bool readtableinfo(const void *, tableinfo_t *);
diff --git a/test/100_gendata_cocsep/gendata_cocsep_tests.c b/test/100_gendata_cocsep/gendata_cocsep_tests.c
@@ -6,19 +6,19 @@
#define COCSEP_CLASSES 3393
typedef struct {
- char solver[INFO_SOLVER_STRLEN];
+ uint64_t distribution[INFO_DISTRIBUTION_LEN];
uint64_t type;
uint64_t infosize;
uint64_t fullsize;
uint64_t hash;
uint64_t entries;
uint64_t classes; /* Used only by cocsepdata, for now */
+ uint64_t next;
+ char solver[INFO_SOLVER_STRLEN];
uint8_t h48h;
uint8_t bits;
uint8_t base;
uint8_t maxvalue;
- uint64_t next;
- uint64_t distribution[INFO_DISTRIBUTION_LEN];
} tableinfo_t;
size_t gendata_cocsep(void *, uint64_t *, cube_t *);
diff --git a/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c
@@ -6,19 +6,19 @@
#define INFO_DISTRIBUTION_LEN 21
typedef struct {
- char solver[INFO_SOLVER_STRLEN];
+ uint64_t distribution[INFO_DISTRIBUTION_LEN];
uint64_t type;
uint64_t infosize;
uint64_t fullsize;
uint64_t hash;
uint64_t entries;
uint64_t classes; /* Used only by cocsepdata, for now */
+ uint64_t next;
+ char solver[INFO_SOLVER_STRLEN];
uint8_t h48h;
uint8_t bits;
uint8_t base;
uint8_t maxvalue;
- uint64_t next;
- uint64_t distribution[INFO_DISTRIBUTION_LEN];
} tableinfo_t;
typedef struct {