Discover は多数のメモリーアクセスエラー、およびエラーである可能性のあるアクセスに関する警告を検出および報告します。
Discover は次のメモリーアクセスエラーを検出します。
ABR: 配列範囲外からの読み取り (beyond array bounds read)
ABW: 配列範囲外への書き込み (beyond array bounds write)
BFM:不正なメモリーブロックの解放 (freeing the wrong memory block)
BRP:不正な realloc アドレスパラメータ (bad realloc address parameter)
CGB:破壊された配列ガードブロック (corrupted array guard block)
DFM: メモリーの二重解放 (double freeing memory)
FMR: 解放されたメモリーからの読み取り (freed memory read)
FMW: 解放されたメモリーへの書き込み (freed memory write)
FRP: 解放された realloc パラメータ (freed realloc parameter)
IMR: 無効なメモリーからの読み取り (invalid memory read)
IMW: 無効なメモリーへの書き込み (invalid memory write)
PIR: 部分的に初期化された領域からの読み取り (partially initialized read)
SBR: スタックフレームの範囲外からの読み取り (beyond stack frame bounds read)
SBW: スタックフレームの範囲外への書き込み (beyond stack frame bounds write)
UAR: 非割り当てメモリーからの読み取り (unallocated memory read)
UAW: 非割り当てメモリーへの書き込み (unallocated memory write)
UMR: 非初期化メモリーからの読み取り (unitialized memory read)
次のセクションに、これらのエラーの一部を生成する簡単なサンプルプログラムを一覧表示します。
#include <stdio.h>
#include <stdlib.h>
int main()
{
// ABR: reading memory beyond array bounds at address 0x%1x (%d byte%s)"
int *a = (int*) malloc(sizeof(int[5]));
printf("a[5] = %d\n",a[5]);
)
|
#include <stdlib.h>
int main()
{
// ABW: writing to memory beyond array bounds
int *a = (int*) malloc(sizeof(int[5]));
a[5] = 5;
}
|
#include <stdlib.h>
int main()
{
// BFM: freeing wrong memory block
int *p = (int*) malloc(sizeof(int));
free(p+1);
}
|
#include <stdlib.h>
int main()
{
// BRP is "bad address parameter for realloc 0x%1x"
int *p = (int*) realloc(0,sizeof(int));
int *q = (int*) realloc(p+20,sizeof(int[2]));
}
|
#include <stdlib.h>
int main()
{
// DFM is "double freeing memory"
int *p = (int*) malloc(sizeof(int));
free(p);
free(p);'
}
|
#includ <stdio.h>
#include <stdlib.h>
int main()
{
// FMR is "reading from freed memory at address 0x%1x (%d byte%s)"
int *p = (int*) malloc(sizeof(int));
free(p);
printf("p = 0x%h\n",p);
}
|
#include <stdlib.h>
int main()
{
// FMW is "writing to freed memory at address 0x%1x (%d byte%s)"
int *p = (int*) malloc(sizeof(int));
free(p);
*p = 1;
}
|
#include <stdlib.h>
int main()
{
// FRP: freed pointer passed to realloc
int *p = (int*) malloc(sizeof(int));
free(0);
int *q = (int*) realloc(p,sizeof(int[2]));
}
|
#include <stdlib.h>
int main()
{
// IMR: read from invalid memory address
int *p = 0;
int i = *p; // generates Signal 11...
}
|
#include <stdlib.h>
int main()
{
// IMW: write to invalide memory address
int *p = 0;
*p = 1; // generates Signal 11...
}
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
// PIR: accessing partially initialized data
int *p = (int*) malloc(sizeof(int));
*((char*)p) = 'c';
printf("*(p = %d\n",*(p+1));
}
|
#include <stdio.h>
#include <stdlib>
int main()
{
// UAR is "reading from unallocated memory"
int *p = (int*) malloc(sizeof(int));
printf("*(p+1) = %d\n",*(p+1));
}
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
// UAW is "writing to unallocated memory"
int *p = (int*) malloc(sizeof(int));
*(p+1) = 1;
}
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
// UMR is "accessing uninitialized data from address 0x%1x (A%d byte%s)"
int *p = (int*) malloc(sizeof(int));
printf("*p = %d\n",*p);
}
|
Discover は次のメモリーアクセスの警告を報告します。
AZS: 0 サイズの割り当て (allocating zero size)
NAR: 注釈の付かない領域からの読み取り (non-annotated read)
NAW: 注釈の付かない領域への書き込み (non-annotated write)
SMR: 投機的メモリーからの読み取り (speculative memory read)
SMW: 投機的メモリーへの書き込み (speculative memory write)
UFR: 不明なスタックフレームからの読み取り (unknown stack frame read)
UFW: 不明なスタックフレームへの書き込み (unknown stack frame write)
USR: 読み取り中の不明ステータス (unknown status while reading)
USW: 書き込み中の不明なステータス (unknown status while writing)
次のセクションは、AZS 警告を生成する簡単なプログラム例を一覧表示します。
#include <stdlib.h>
int main()
{
// AZS: allocating zero size memory block
int *p = malloc();
}
|