`[data getBytes:&buff length:sizeof(buff)]` got wrong bytes


In iOS 16+, when the NSData *data ranges between 0 and 255, the int16_t buff retrieves values not within the range of 0 to 255, but rather 29440 to 29696.

- (void)system:(id)system features:(void (^)(NSArray*))features
{
    [self read:TAPropertyTypeAvailableFeatures system:system handler:^(NSDictionary* data, NSError* error){
        
        NSArray* datas = [data objectForKey:@"value"];
        NSMutableArray* numbers = [[NSMutableArray alloc] init];
        
        for(NSData* data in datas)
        {
            int16_t buff;
            [data getBytes:&buff length:sizeof(buff)];
            NSNumber* number = [NSNumber numberWithInteger:buff];
            [numbers addObject:number];
        }
        
        features(numbers);
    }];
}

When I upgraded my MacBook to 14.1.2 and Xcode to 15.0.1, I encountered an issue with this function that I rebuilt.

In iOS 16+, when the NSData *data ranges between 0 and 255, the int16_t buff retrieves values not within the range of 0 to 255, but rather 29440 to 29696.

However, in iOS 15, it still remains between 0 and 255.

This problem never occurred before. Changing int16_t to int resolves the issue.

What is causing this issue?
Is it possible to continue using int16_t without encountering this problem?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img