summaryrefslogtreecommitdiff
path: root/src/codegen/struct_layout.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-11-01 19:13:44 -0500
committerGitHub <noreply@github.com>2017-11-01 19:13:44 -0500
commitf059edee4a6b165323623af0c993d3c3889ed2c1 (patch)
tree8ef8de4c297599b629e43e9ea6cd9d61fd9eab7f /src/codegen/struct_layout.rs
parent0e84605df21a22b5f5519eef28f80c68d14ea346 (diff)
parent460aaa06b271685ad56732ebfbc45054223b990d (diff)
Auto merge of #1137 - fitzgen:divide-by-zero-in-struct-layout, r=emilio
Divide by zero in struct layout See commit messages for details. r? @emilio or @pepyakin
Diffstat (limited to 'src/codegen/struct_layout.rs')
-rw-r--r--src/codegen/struct_layout.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs
index c3c781cb..ca46947d 100644
--- a/src/codegen/struct_layout.rs
+++ b/src/codegen/struct_layout.rs
@@ -335,9 +335,12 @@ impl<'a> StructLayoutTracker<'a> {
new_field_layout
);
+ // Avoid divide-by-zero errors if align is 0.
+ let align = cmp::max(1, layout.align);
+
if self.last_field_was_bitfield &&
- new_field_layout.align <= layout.size % layout.align &&
- new_field_layout.size <= layout.size % layout.align
+ new_field_layout.align <= layout.size % align &&
+ new_field_layout.size <= layout.size % align
{
// The new field will be coalesced into some of the remaining bits.
//