[Bug c++/51311] New: bogus array bounds warning
bruck.michael at googlemail dot com
gcc-bugzilla@gcc.gnu.org
Sat Nov 26 12:38:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51311
Bug #: 51311
Summary: bogus array bounds warning
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: bruck.michael@googlemail.com
command line:
arm-elf-g++ -Wall -Werror -O3 -std=gnu++0x -c foo.cpp
error:
foo.cpp: In function 'void bar()':
foo.cpp:23:44: error: array subscript is above array bounds
[-Werror=array-bounds]
The error is triggered by case 0x02, which in reality is not encountered with
in_data.
foo.cpp:
#include <string.h>
char in_data[] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
void bar()
{
size_t in_length = sizeof(in_data) / sizeof(in_data[0]);
size_t pos = 0;
while (pos < in_length)
{
size_t next = pos;
auto fill = [&](size_t data_len) -> bool
{
next = pos + 1 + data_len;
if (next > in_length)
return false;
memset(in_data + pos + 1, 0, data_len);
return true;
};
switch (in_data[pos])
{
case 0x01:
if (!fill(4))
return;
break;
case 0x02:
if (!fill(16))
return;
break;
}
pos = next;
}
}
More information about the Gcc-bugs
mailing list