Frage

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

War es hilfreich?

Lösung

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

-

Use unsigned char instead

Andere Tipps

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

const unsigned char * bytes = (const unsigned char *)[imagedata bytes];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top