文章

Swift 数字累加溢出报错排查

今天测试 ios直播SDK 的稳定性,连续推流5个小时以上的时候,程序停止,并且Xcode报了以下错误:

1
2
warning: could not load any Objective-C class information from the dyld shared cache. 
This will significantly reduce the quality of type information available.

并不能看出比较明显的错误,退出时Xcode 停到这一句

1
self.totalOutputBytes += retLen

self.totalOutputBytes 为Int类型,此时值为0x 7F FF 62 8E,再次去加 retLen,self.totalOutputBytes 会被写满溢出了,Xcode就会报此错误。 为了验证想法,之后定义了UInt8 类型变量,让他不断累加,果然最后也会累加溢出报此错误。

本文由作者按照 CC BY 4.0 进行授权
PixPark_WeChat