XCode,在此检查有效的png代码中修复始终为true的警告

 闻人特荷焦黄01965 发布于 2023-02-06 10:08

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

1 个回答
  • char从-128到127.所以它不能超过0x7f.

    -

    请改用unsigned char

    2023-02-06 10:12 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有