Fix makesdna not checking alignment for a non-native platform
This was causing alignment issues which were only visible on a platform of particular bitness, so it was easy to break stuff for 32bit when working on 64bit platform and vice versa.
This commit is contained in:
parent
3ce3163379
commit
a27772cd66
|
@ -80,7 +80,7 @@ typedef struct bGPDstroke {
|
|||
|
||||
bGPDtriangle *triangles;/* tesselated triangles for GP Fill */
|
||||
int tot_triangles; /* number of triangles in array */
|
||||
short pad2[2]; /* avoid compiler align error */
|
||||
int pad1, *pad2;
|
||||
|
||||
double inittime; /* Init time of stroke */
|
||||
} bGPDstroke;
|
||||
|
|
|
@ -720,6 +720,28 @@ static int arraysize(const char *str)
|
|||
return mul;
|
||||
}
|
||||
|
||||
static bool check_field_alignment(int firststruct, int structtype, int type, int len,
|
||||
const char *name, const char *detail)
|
||||
{
|
||||
bool result = true;
|
||||
if (type < firststruct && typelens_native[type] > 4 && (len % 8)) {
|
||||
fprintf(stderr, "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
|
||||
detail, types[structtype], name, len % 8);
|
||||
result = false;
|
||||
}
|
||||
if (typelens_native[type] > 3 && (len % 4) ) {
|
||||
fprintf(stderr, "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
|
||||
detail, types[structtype], name, len % 4);
|
||||
result = false;
|
||||
}
|
||||
if (typelens_native[type] == 2 && (len % 2) ) {
|
||||
fprintf(stderr, "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
|
||||
detail, types[structtype], name, len % 2);
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int calculate_structlens(int firststruct)
|
||||
{
|
||||
int unknown = nr_structs, lastunknown;
|
||||
|
@ -815,20 +837,11 @@ static int calculate_structlens(int firststruct)
|
|||
}
|
||||
}
|
||||
|
||||
/* 2-4-8 aligned/ */
|
||||
if (type < firststruct && typelens_native[type] > 4 && (len_native % 8)) {
|
||||
fprintf(stderr, "Align 8 error in struct: %s %s (add %d padding bytes)\n",
|
||||
types[structtype], cp, len_native % 8);
|
||||
/* Check 2-4-8 aligned. */
|
||||
if (!check_field_alignment(firststruct, structtype, type, len_32, cp, "32 bit")) {
|
||||
dna_error = 1;
|
||||
}
|
||||
if (typelens_native[type] > 3 && (len_native % 4) ) {
|
||||
fprintf(stderr, "Align 4 error in struct: %s %s (add %d padding bytes)\n",
|
||||
types[structtype], cp, len_native % 4);
|
||||
dna_error = 1;
|
||||
}
|
||||
else if (typelens_native[type] == 2 && (len_native % 2) ) {
|
||||
fprintf(stderr, "Align 2 error in struct: %s %s (add %d padding bytes)\n",
|
||||
types[structtype], cp, len_native % 2);
|
||||
if (!check_field_alignment(firststruct, structtype, type, len_64, cp, "64 bit")) {
|
||||
dna_error = 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue