|
From: Nicholas N. <nj...@cs...> - 2008-06-18 01:19:57
|
On Tue, 17 Jun 2008, Alan Jenkins wrote: > The invalid read is caused by strlen() is reading past the end of a > malloc()ed string. For efficiency it is reading the string 4 bytes at a > time. valgrind reports this as an error. > > I believe this is acceptable *if the reads are guaranteed to be > aligned*. In this case they are, because the string is a variable > length array at the end of a C structure, and the previous field is a > pointer. The string will start on an aligned address, so the read which > includes the terminator will also be aligned. There's no chance of it > crossing a page boundary and provoking a segfault. Valgrind tries to replace strlen with its own, less-optimised version, for exactly this reason. Sometimes it doesn't work, eg. if your libc.so is stripped (IIRC). As for "acceptable"... there's "acceptable according to the C standard" and "acceptable because it works on pretty much all modern machines", and those two aren't quite the same. Valgrind/Memcheck tries to find a happy medium between those two, and --partial-loads-ok=yes is one example where you get to choose what behaviour you want. It's surprising that --partial-loads-ok=yes isn't working, though. Nick |