次の方法で共有


警告 C28220

注釈 'annotation' に必要な整数式

この警告は、整数式が注釈パラメーターとして予期されたが、代わりに互換性のない型が使用された場合を示します。 これは、現在のシナリオに適合しない SAL 注釈マクロを使用しようとしたことが原因で発生する可能性があります。

#include <sal.h>

// Oops, the _In_reads_ annotation takes an integer type but is being passed a pointer
void f(_In_reads_(last) const int *buffer, const int *last)
{
  for(; buffer < last; ++buffer)
  {
    //...
  }
}

この例では、開発者の意図は、要素までlast読み取ることをbuffer示すものでした。 注釈は _In_reads_ 、要素数のバッファー サイズを示すために使用されるため、シナリオを修正しません。 正しい注釈は、 _In_reads_to_ptr_ポインターを持つバッファーの末尾を示します。

使用されている注釈に相当する _to_ptr_ がない場合は、last ポインターを注釈内の (buffer - size) を持つサイズ値に変換することで、警告に対処できます。

#include <sal.h>

void f(_In_reads_to_ptr_(last) const int *buffer, const int *last)
{
  for(; buffer < last; ++buffer)
  {
    //...
  }
}