2021-12-10

Tech Programing

程式人小天地

iOS getBytes EXC_BAD_ACCESS when data over 5M

1 min read


this is my code.
When I run this test, the data is 5M and crashes on the second fetch, or if the file is larger, it crashes on the first fetch.

- (void)testExample {
    
    NSData *data = [NSData dataWithContentsOfFile:@"/Users/xxx/Downloads/Clock41_res"];
    
    unsigned long length = data.length;
    unsigned long dataLength = data.length;
    
    uint8_t buff[length];
    [data getBytes:&buff length:dataLength];
    
    uint8_t buff1[length];
    [data getBytes:&buff1 length:dataLength];
    
    uint8_t buff2[length];
    [data getBytes:&buff2 length:dataLength];
    
}

the crash image



Source link

資料來源:Stackoverflow

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *