Sterpu Mihai
Sterpu Mihai

Reputation: 618

confused about address sanitizer limits

So I'm playing around in VS2022 with /fsanitize=address but I fail to understand how is this useful if it only catches only a small ammount of out of bounds accesses. For instance, this simple program works fine:

int main()
{
  unsigned char arr[2] = { 0xAA, 0xAB };
  arr[255] = 4;
}

Is there something I'm missing? I see that small indexes like arr[2] do trigger address sanitizer errors. Is there a way to configure the limits of the address sanitizer?

Context: I discovered a bug in my C program where I would index an array using a variable which is wrongly reset to 0xFF under certain circumstances but none of my ~300 tests detect this. I thought the address sanitizer would detect it but it seems I'm wrong.

Upvotes: 2

Views: 85

Answers (1)

ikegami
ikegami

Reputation: 386461

how is this useful if it only catches only a small ammount of out of bounds accesses

First of all, catching even a small amount of errors is useful.

Secondly, it catches far more than a small amount of errors. It's common to accidentally dereference one beyond what's valid. NULL dereferences is another huge source of invalid dereferences, and those are also caught (by gcc's address sanitizer if not VS's).

This is why an address sanitizer provides a lot of value as a debugging tool.

Upvotes: 2

Related Questions