From da3ae8fc9584f371bdea72aa75d4e9700f06bb0c Mon Sep 17 00:00:00 2001 From: Mikkel Nygaard Ravn Date: Thu, 15 Jun 2017 21:22:18 -0700 Subject: [PATCH] Add alignment padding to floats in std codec (flutter/engine#3780) --- .../darwin/ios/framework/Source/FlutterStandardCodec.mm | 2 ++ .../framework/Source/flutter_standard_codec_unittest.mm | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm index f6222760e67..11048533ee2 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm @@ -275,6 +275,7 @@ using namespace shell; } else if (strcmp(type, @encode(double)) == 0 || strcmp(type, @encode(float)) == 0) { Float64 f = number.doubleValue; [self writeByte:FlutterStandardFieldFloat64]; + [self writeAlignment:8]; [_data appendBytes:(UInt8*)&f length:8]; } else if (strcmp(type, @encode(unsigned long)) == 0 || strcmp(type, @encode(signed long long)) == 0 || @@ -430,6 +431,7 @@ using namespace shell; } case FlutterStandardFieldFloat64: { Float64 value; + [self readAlignment:8]; [self readBytes:&value length:8]; return [NSNumber numberWithDouble:value]; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm index f9c54c3d6a9..321bb1745db 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm @@ -103,13 +103,13 @@ TEST(FlutterStandardCodec, CanEncodeAndDecodeBigInteger) { } TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat32) { - char bytes[9] = {0x06, 0x00, 0x00, 0x00, 0x60, 0xfb, 0x21, 0x09, 0x40}; - checkEncodeDecode(@3.1415927f, [NSData dataWithBytes:bytes length:9]); + char bytes[16] = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xfb, 0x21, 0x09, 0x40}; + checkEncodeDecode(@3.1415927f, [NSData dataWithBytes:bytes length:16]); } TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat64) { - char bytes[9] = {0x06, 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40}; - checkEncodeDecode(@3.14159265358979311599796346854, [NSData dataWithBytes:bytes length:9]); + char bytes[16] = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40}; + checkEncodeDecode(@3.14159265358979311599796346854, [NSData dataWithBytes:bytes length:16]); } TEST(FlutterStandardCodec, CanEncodeAndDecodeString) {