Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rustc: fix size computation of structs for the FFI

It didn't take alignment into account.

Fixes #3656.
  • Loading branch information...
commit 25096a212a9ccaa0d181630af5971532c3472182 1 parent 0d8f447
@Blei Blei authored
View
7 src/rustc/middle/trans/foreign.rs
@@ -112,9 +112,10 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
Float => 4,
Double => 8,
Struct => {
- do vec::foldl(0, struct_tys(ty)) |s, t| {
- s + ty_size(*t)
- }
+ let size = do vec::foldl(0, struct_tys(ty)) |s, t| {
+ align(s, *t) + ty_size(*t)
+ };
+ align(size, ty)
}
Array => {
let len = llvm::LLVMGetArrayLength(ty) as uint;
View
20 src/test/run-pass/issue-3656.rs
@@ -0,0 +1,20 @@
+// Issue #3656
+// Incorrect struct size computation in the FFI, because of not taking
+// the alignment of elements into account.
+
+use libc::*;
+
+struct KEYGEN {
+ hash_algorithm: [c_uint]/2,
+ count: uint32_t,
+ salt: *c_void,
+ salt_size: uint32_t,
+}
+
+extern {
+ // Bogus signature, just need to test if it compiles.
+ pub fn malloc(++data: KEYGEN);
+}
+
+fn main() {
+}
Please sign in to comment.
Something went wrong with that request. Please try again.