diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-09 10:53:50 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-09 10:54:51 +0300 |
commit | a27772cd661839b0194acb782fdf8beab19b000d (patch) | |
tree | 224b1926ffd39acc8e63b4c5d6295f0f9724322c /source/blender/makesdna/intern | |
parent | 3ce31633796cd1139cff96eaa4697d6d6f8ba10e (diff) |
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.
Diffstat (limited to 'source/blender/makesdna/intern')
-rw-r--r-- | source/blender/makesdna/intern/makesdna.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index 651794da50d..fc94a8d9ff4 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -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); - 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); + /* Check 2-4-8 aligned. */ + if (!check_field_alignment(firststruct, structtype, type, len_32, cp, "32 bit")) { 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; } |