代码检查:可能的溢出
该检查会报告可能发生溢出的 int 值的算术运算。 溢出意味着计算结果无法放入 int 范围内。
示例
int itemCount = 50_000;
int price = 50_000;
int total = itemCount * price;
乘法结果无法放入 int。
如何修复它
没有针对此检查的专用快速修复。 常见的修复方法包括使用更宽的类型、验证输入范围,或显式声明溢出行为。
int itemCount = 50_000;
int price = 50_000;
long total = (long)itemCount * price;
2026年 5月 8日