문제

In XCode5, i have this code

1  - (BOOL)checkValidPNGImage{

2        NSData *imagedata = [NSData dataWithContentsOfFile:self.imageFullPath];
3        if ([imagedata length] < 4)
4            return NO;    
5         const char * bytes = (const char *)[imagedata bytes];    
6         if (bytes[0] != 0x89 || bytes[1] != 0x50)
7             return NO;
8         if (bytes[[imagedata length] - 2] != 0x60 ||
9             bytes[[imagedata length] - 1] != 0x82)
10            return NO;
11    return YES;
12 }

in line 6 and line 8 it get warning

Comparison of constant 137 with expression of type 'const char' is always true

and

Comparison of constant 130 with expression of type 'const char' is always true

how to fix this? btw i got the code above from somewhere i forgot, so i open for any other alternative to check valid png

도움이 되었습니까?

해결책

char is from -128 to 127. So it can't exceed 0x7f.

-

Use unsigned char instead

다른 팁

Use this instead of const char * bytes = (const char *)[imagedata bytes];

const unsigned char * bytes = (const unsigned char *)[imagedata bytes];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top