valgrind false positives on gcc-generated string routines
Bug #852760 reported by
Chris Bainbridge
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Valgrind |
New
|
Medium
|
|||
valgrind (ALT Linux) |
New
|
Medium
|
|||
valgrind (Fedora) |
Won't Fix
|
Medium
|
|||
valgrind (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
char *a = malloc(1);
a[0] = '\0';
printf("%lu\n", (unsigned long)strlen(a));
}
Compile with "gcc -O2" and run valgrind.
==5977== Invalid read of size 4
==5977== at 0x400494: main (x.c:9)
==5977== Address 0x51ce040 is 0 bytes inside a block of size 1 alloc'd
==5977== at 0x4C28F9F: malloc (vg_replace_
==5977== by 0x40048D: main (x.c:7)
tags: | added: oneiric |
Changed in valgrind (ALT Linux): | |
importance: | Unknown → Medium |
status: | Unknown → New |
Changed in valgrind: | |
importance: | Unknown → Medium |
status: | Unknown → New |
Changed in valgrind (Fedora): | |
importance: | Unknown → Medium |
status: | Unknown → Won't Fix |
To post a comment you must log in.
This bug report relates to two (closed invalid) bug reports in gcc bugzilla.
http:// gcc.gnu. org/bugzilla/ show_bug. cgi?id= 47522 gcc.gnu. org/bugzilla/ show_bug. cgi?id= 44183
http://
PR47522 includes a runable example in the first comment.
the issue appears to be that vectorization can result in code that loads elements beyond the last element of an allocated array. However, these loads will only happen for unaligned data, where access to the last+1 element can't trigger a page fault or other side effects (according to my interpretation of comments by gcc developers) and are never used. As such, this is considered valid.
Since this kind of code will be produced increasingly by gcc, especially for numerical codes (whenever vectorization triggers, essentially) it would be great to have this somehow dealt with in valgrind.