在XCode5
,我有这个代码
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 }
在第6行和第8行,它会收到警告
Comparison of constant 137 with expression of type 'const char' is always true
和
Comparison of constant 130 with expression of type 'const char' is always true
怎么解决这个问题?顺便说一下,我从上面的某个地方得到了上面的代码,所以我打开任何其他选项来检查有效的png
char从-128到127.所以它不能超过0x7f.
-
请改用unsigned char