iOS数组count操作(NSUInteger)的安全性
来源:互联网 发布:java电信计费系统 编辑:程序博客网 时间:2024/06/10 06:19
- 从一个隐蔽的bug说起
- NSUInteger转成int
从一个隐蔽的bug说起
int i = 0; for(; i < [emptyArr count] - 1;){ //条件成立,数组越界 id obj = [emptyArr objectAtIndex:i]; }
由于数组count方法返回值类型是NSUInteger,当数组的size为0的时候,一个NSUInteger类型的0减去1结果还是NSUInteger类型,所以结果不是-1而是一个随机的正整数。
NSUInteger转成int
int i = 0; for(; i < (int)[emptyArr count] - 1;){ id obj = [emptyArr objectAtIndex:i]; }
当数组为空时,(int)[emptyArr count] - 1结果是-1,不会进入循环.
0 0
- iOS数组count操作(NSUInteger)的安全性
- iOS开发之int,NSInteger,NSUInteger,NSNumber的使用
- iOS开发之int,NSInteger,NSUInteger,NSNumber的使用
- iOS开发之int,NSInteger,NSUInteger,NSNumber的使用
- iOS Unknown type name NSUInteger问题的解决方案
- 【iOS】_int、NSInteger、NSUInteger、NSNumber的区别和联系
- iOS开发之int,NSInteger,NSUInteger,NSNumber的使用
- iOS开发之int,NSInteger,NSUInteger,NSNumber的使用
- iOS开发之int,NSInteger,NSUInteger,NSNumber的使用
- iOS程序的安全性
- IOS int,NSInteger,NSUInteger,NSNumber
- iOS开发 ☞ NSInteger、NSUInteger
- iOS数组常用的操作
- ios可变数组的操作
- iOS:应用程序的线程安全性
- iOS:应用程序的线程安全性
- iOS:应用程序的线程安全性
- iOS:应用程序的线程安全性
- mysql常用语句
- Java任意时间获得该时间所在周周一
- Maven详解之仓库------本地仓库、远程仓库
- 关于PATHINFO的重写规则解析
- ios後臺播放音樂
- iOS数组count操作(NSUInteger)的安全性
- Microsoft COM+组件接口的方法的重载问题。
- Codeforces Round #312 (Div. 2) C. Amr and Chemistry(技巧)
- java AJAX实现级联下拉框
- Linux虚拟机ftp客户端与Windows ftp服务器建立连接的方法
- 启动tomcat提示内存不足
- Android使用Ant自动编译签名打包详解
- Error pulling origin: error: The following untracked working tree files would be overwritten by
- Jlink FL2440 裸机开发(一) 点亮LED和按键控制