我一直在用我最近编写的 C 程序尝试Splint,并试图理解和删除它给出的警告。我理解但不明白如何删除它来自以下代码片段:
static MyType_t *findById(const int id)
{
int i;
for (i = 0; i < MY_ARR_SIZE; i++) {
if (my_arr[i].id == NOT_SET) {
/* Items are sorted so that items with
NOT_SET as ID are at the end of the array */
break;
}
if (my_arr[i].id == id) {
return &(my_arr[i]);
}
}
return NULL;
}
Splint 对函数可以返回 NULL 感到不高兴,但在这种情况下,它非常有意义。
我尝试使用 / @nullwhenfalse@ / 但它似乎只有在函数返回 true/false 并且还尝试更改代码以使用 retVal 并尝试 / @null@ / 和 / @relnull@ / 的情况下才有效声明,但这些什么也没做。
(顺便说一句,这张桌子只有 20 个大 atm,所以没有必要使用聪明的搜索算法。)