分析仪无法确定位置
The analyzer is unable to determine the position
我从 PVS Studio 收到以下错误 V669 "fetch_mask"参数是非常量引用。分析器无法确定修改此参数的位置。该函数可能包含错误。
这是一行:
XXH64_state_t* hash_state, uint32_t& fetch_mask
我正在计算错误是 &不是我修复它fetch_mask的一部分:
XXH64_state_t* hash_state, uint32_t &fetch_mask
错误消失了。但是,travis.cl 测试说我需要重新格式化并失败。
我认为发现了有问题的原始代码。
void TextureCache::HashTextureBindings(
XXH64_state_t* hash_state, uint32_t& fetch_mask,
const std::vector<Shader::TextureBinding>& bindings) {
for (auto& binding : bindings) {
uint32_t fetch_bit = 1 << binding.fetch_constant;
if (fetch_mask & fetch_bit) {
void HashTextureBindings(XXH64_state_t* hash_state, uint32_t& fetch_mask,
const std::vector<Shader::TextureBinding>& bindings);
我删除了 &,因为我认为它应该是uint32_t fetch_mask而不是 uint32_t&fetch_mask
据我了解,我们正在谈论这段代码。我将编写一个函数的整个主体:
void TextureCache::HashTextureBindings(
XXH64_state_t* hash_state, uint32_t& fetch_mask,
const std::vector<Shader::TextureBinding>& bindings) {
for (auto& binding : bindings) {
uint32_t fetch_bit = 1 << binding.fetch_constant;
if (fetch_mask & fetch_bit) {
// We've covered this binding.
continue;
}
auto& regs = *register_file_;
int r = XE_GPU_REG_SHADER_CONSTANT_FETCH_00_0 + binding.fetch_constant * 6;
auto group =
reinterpret_cast<const xenos::xe_gpu_fetch_group_t*>(®s.values[r]);
auto& fetch = group->texture_fetch;
XXH64_update(hash_state, &fetch, sizeof(fetch));
}
}
如您所见,变量fetch_mask仅用于读取表达式if (fetch_mask & fetch_bit(。通过引用传递整数变量而不修改它是很奇怪的。这通常表明代码包含错误。是的,这并不总是一个错误,但应该仔细验证此代码。
对于PVS-Studio分析仪,无论是写入uint32_t&fetch_mask还是uint32_t&fetch_mask都无关紧要。无论如何,它会发出 警告 .
可能,这里没有错误。您可以通过删除链接来消除警告,就像您所做的那样。另一种选择是使用抑制误报的机制之一。
该错误指示您正在将对变量的非常量引用传递到函数中,但 PVS-Studio 无法查看该变量是否实际被修改。通过引用传递参数的目的是,函数可以修改原始值。如果函数不修改通过引用传递的值,则应const
该引用(即uint32_t const& fetch_mask
(。
按值传递变量是另一种表达方式,即函数不会修改原始值(尽管我也更喜欢通过 const 值传递,这样它就不会被意外分配(。对于整型数据类型,通常通过 (const( 值传递它们。
诊断本质上是质疑预期目的和代码是否匹配。代码的目的是,通过fetch_mask
形式参数传递的变量可以修改,但实现不会尝试这样做(除非它以 PVS-Studio 看不到的方式这样做,例如通过别名(。
作为参考,以下是 V669 的官方文档:
分析器检测到参数正在通过引用传递到函数中,但未在函数体内修改。这可能表示由印刷错误等引起的错误。
- 初始值设定项无法确定 C++ 中字符串的大小
- CMake无法确定目标的链接器语言:fileloader
- SFML 鼠标获取位置无法正常工作
- 无法确定为什么函数调用中从 char* 到 char 的无效转换
- 分析仪无法确定位置
- "无法确定要运行哪个"make"命令.检查构建配置中的"make"步骤
- CMake 错误:无法确定目标的链接语言
- 添加 DIV/0 异常处理。我做错了什么,但无法确定在哪里
- 无法确定未解决的外部错误来自何处
- 无法确定 IDE 在 C++ 中说出未声明标识符的原因
- 无法确定正确的返回类型
- 为什么在C 中的堆中的垃圾位置无法重新分配
- Xalanc转换错误:无法确定文件的基本路径名(,第0,第0列)
- 无法确定打印113383后代码停止的原因
- 将utf8编码的字符串转换为本地8位编码的字符串,并将无法确定的字符替换为空白
- 运行时错误,无法确定原因
- 类定义中的分段错误无法确定在哪里
- 究竟为什么编译器在运行时之前无法确定变量的真实类型?
- std::bind() 错误:无法确定重载函数"boost::asio::io_service::run"的哪个实例
- Visual Studio 无法确定全局变量的类型