2017-02-10 10 views
0
.... 
wstring wstrFirst; 
INFO_t* pstInfo = NULL; 
INFO_MAP::const_iterator itrReqInfoEnd = RequestedInfoMap_i.end(); 
for(INFO_MAP::const_iterator itrReqInfo = RequestedInfoMap_i.begin(); 
    itrReqInfo != itrReqInfoEnd; 
    ++itrReqInfo) 
{ 
    wstrFirst = itrReqInfo->first; 
    pstInfo = itrReqInfo->second; 
    ... 

上記のコードスニペットを参照してください。 私はこれについてCODESONAR(静的解析ツール)を実行しています。stl :: mapイテレータ使用のCODESONARのバッファオーバーランコメント

(ハイライトされたコードがpstInfo = itrReqInfo->second;意味ここでは)それは偽陽性です

This code reads past the end of the buffer pointed to by itrReqInfo->.

. itrReqInfo-> evaluates to &wstrFirst._Bx.

. The first byte read is at offset 48 from the beginning of the buffer pointed to by itrReqInfo->, whose capacity is 48 bytes.

. The offset exceeds the capacity.

. The overrun occurs in stack memory. The issue can occur if the highlighted code executes.

: 私の問題は、最後の行(pstInfo = itrReqInfo->second;)で、CODESONARは次のエラーを示し、ということでしょうか?そうでない場合は、どうすれば修正できますか? itrReqInfo以来

+0

だから何が起こるでしょうか?大丈夫ですか? Valgrindはそれについて何を言いますか? – Kupto

+0

コードは正常に動作しています。 – krishnakumartg

答えて

0

const_iteratorあるとforだけで、何がバッファの制限を超えて読みすることができますどのように表示されていない最初から最後までmapを通してそれを歩いています。しかし、確かに知るためには、このエラーのより完全な例を見る必要があります。

0

私はcodesonarで報告された同様の問題がありました。私は 'const reference'を使って修正しました。

私はこのような何かをしようと、あなたの場合、あなたがハイライトされたコードを実行すると...

wstring wstrFirst; 
INFO_MAP::const_iterator itrReqInfoEnd = RequestedInfoMap_i.end(); 
for(INFO_MAP::const_iterator itrReqInfo = RequestedInfoMap_i.begin(); 
    itrReqInfo != itrReqInfoEnd; 
    ++itrReqInfo) 
{ 
    wstrFirst = itrReqInfo->first; 
    const INFO_t& pstInfo = itrReqInfo->second; 
関連する問題