Klocwork は次のエラーを報告します:-
「ABR – バッファ オーバーフロー、'oidsp' の配列インデックスが範囲外の可能性があります。サイズ 64 の配列 'oidsp' は、インデックス値 -2..-1 を使用する可能性があります。」
この行の場合:-
if (check_index_lower_legality (len,-1))
{
oidsp[len-1] = specProb;
}
check_index_lower_legality が次の場合:-
bool check_index_lower_legality (int index, int offset)
/**
* This function checks that the index with the offset isn't
* below zero.
* If it is - returns 0 ;
* If isn't - returns 1 ;
**/
{
if ( (index + offset )<0) {
return 0;
}
return 1 ;
}
ただし、次の場合はバグはありませんcheck_index_lower_legality
:- (ちなみに、これは間違った答えです。-2 または -1 のオフセット値については、実行時に実際のエラーが発生します。
bool check_index_lower_legality (int index, int offset)
/**
* This function checks that the index with the offset isn't
* below zero.
* If it is - returns 0 ;
* If isn't - returns 1 ;
**/
{
if (index <=0) {
return 0;
}
return 1;
}
何か案は?