Skip to content

Instantly share code, notes, and snippets.

@dmaclach dmaclach/MisalignedRead.m
Last active Sep 20, 2019

What would you like to do?
Compile this with Xcode 11 "release" and it will crash on ARMv7 due to misaligned read. Use a "single view" iOS App as your template, and replace AppDelegate.m with this code.
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
__attribute__((noinline)) double GPBCodedInputStreamReadDouble(uint8_t *buf) {
int64_t value = OSReadLittleInt64(buf, 0);
double result;
memcpy(&result, &value, sizeof(result));
return result;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
double data[3] = {1, 2};
uint8_t *bytes = ((uint8_t*)(data)) + 1;
double a = GPBCodedInputStreamReadDouble(bytes);
NSLog(@"%f", a);
return YES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.