|
Boost Users : |
Subject: Re: [Boost-users] [Filesystem] String corruption in path in V3 and Boost 1.44
From: Timothy Madden (terminatorul_at_[hidden])
Date: 2010-09-22 16:42:37
On 22.09.2010 20:36, Will Watts wrote:
> In article<i7db7c$kid$1_at_[hidden]>, Timothy Madden wrote:
>> I do not know about the Filesystem maintainer, but we need a minimal
>> example to reproduce the problem to make our case elsewhere, that is on
>> the bug tracker or on another list.
>
> How about this?
>
> void main() {
> const char * f = "foo";
> char b[5];
> strcpy(b, f);
> fs::path p1(b); // Debugger shows p1.m_pathname.size = 4 after this
> fs::path p2(f); // But p2.m_pathname.size = 3
> cout<< p1<< endl; // prints "foo "
> cout<< p2<< endl; // prints "foo"
> cout<< (p1 == p2)<< endl; // prints 1 - they are supposedly identical
> }
>
> Please can you check that I haven't cocked up the strcpy(), or something
> idiotic! By all means repeat the exercise with wide characters.
>
> This doesn't show a spectacular crash, but I think it shows that something is
> amiss with the C array handling - something to do with the terminating zero
> byte? What do you reckon?
I think that somehow the template constructor for paths takes the entire
array passed as argument and not just the null-terminated string inside
the array, which may be smaller.
I also got a crash with the attached code on Visual Studio 2008.
I have created a track ticket
https://svn.boost.org/trac/boost/ticket/4677, lets hope someone picks it up.
Timothy Madden
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net