knowledge-database (beta)

Current group: codewarrior.windows

writing to a non-open file crashes

writing to a non-open file crashes  
SiamGod
 Re: writing to a non-open file crashes  
SiamGod
 Re: writing to a non-open file crashes  
Howard Hinnant
 Re: writing to a non-open file crashes  
SiamGod
 Re: writing to a non-open file crashes  
Howard Hinnant
From:SiamGod
Subject:writing to a non-open file crashes
Date:17 Jan 2005 13:07:56 -0800
In CW9.3 under Win, the following code crashes:

int main()
{
ofstream Test;
Test << " ASDF asdf" << endl;
}

The same code does nothing on 8.3 , linux, .net and so on. Is 9.3
buggy?

Ed
From:SiamGod
Subject:Re: writing to a non-open file crashes
Date:18 Jan 2005 05:42:14 -0800
I put in
check(Metrowerks::msl_settings());
nothing happened.

I tried
Test << " asdf" << 1;

no problem

Test << endl;
crashes with a call stack . The last function was bufferedbuf(...)::
write_buf()
on the line right after the while()
count = write_chars(uncbeg_, uncnxt_ - uncbeg_)

when I step into write_chars it calls fread(buf,1, n, file_)
and file_ is NULL. Stepping into the assembly, i get to a point where
it calls
ntdll.dll and crashes.

I hope this is enough locate the problem.

Ed
From:Howard Hinnant
Subject:Re: writing to a non-open file crashes
Date:Tue, 18 Jan 2005 19:36:36 GMT
In article <1106055734.834784.209340@z14g2000cwz.googlegroups.com>,
"SiamGod" wrote:

> I put in
> check(Metrowerks::msl_settings());
> nothing happened.
>
> I tried
> Test << " asdf" << 1;
>
> no problem
>
> Test << endl;
> crashes with a call stack . The last function was bufferedbuf(...)::
> write_buf()
> on the line right after the while()
> count = write_chars(uncbeg_, uncnxt_ - uncbeg_)
>
> when I step into write_chars it calls fread(buf,1, n, file_)
> and file_ is NULL. Stepping into the assembly, i get to a point where
> it calls
> ntdll.dll and crashes.
>
> I hope this is enough locate the problem.

Yes, thank you for your aid. I have located the bug in
. You can patch it by opening that file (under
MSL_C++/MSL_Common/Include/) and search for the member function:

bufferedbuf::setbuf(char_type* s, _STD::streamsize n)

The definition puts the stream into write mode mistakenly sometimes and
that is what is happening in your example. Here is the fixed function:

template
_STD::basic_streambuf*
bufferedbuf::setbuf(char_type* s, _STD::streamsize n)
{
bool pa = put_active();
if (sync() < 0)
return 0;
partition_neutral();
if (s == 0)
{
if (owns_buffer_)
delete [] buffer_;
buffer_ = 0;
buffer_size_ = _STD::max(_STD::max(max_length_ * 2 /
sizeof(char_type), (_CSTD::size_t)n), (_CSTD::size_t)minbufsize);
buffer_ = new char_type[buffer_size_];
owns_buffer_ = true;
buffered_ = n != 0;
}
else
{
if (n < max_length_ * 2 / (_STD::streamsize)sizeof(char_type))
return 0;
if (owns_buffer_)
delete [] buffer_;
buffer_ = s;
buffer_size_ = (_CSTD::size_t)n;
owns_buffer_ = false;
buffered_ = true;
}
if (buffered_ && pa)
partition_put();
return this;
}

After applying this patch you should rebuild all of the MSL libraries
which is most easily done with BuildLibraries.x86.mcp found under
(MSL_Build_Projects)/x86/.

Sorry for the bug, and thanks for reporting it and helping to diagnose
it.

-Howard
From:SiamGod
Subject:Re: writing to a non-open file crashes
Date:18 Jan 2005 14:10:55 -0800
I put the patch in and it worked. Boy that build libraries project
builds a lot of stuff!!

Thanks for the quick response.

Ed
From:Howard Hinnant
Subject:Re: writing to a non-open file crashes
Date:Mon, 17 Jan 2005 21:58:56 GMT
In article <1105996076.803882.258250@f14g2000cwb.googlegroups.com>,
"SiamGod" wrote:

> In CW9.3 under Win, the following code crashes:
>
> int main()
> {
> ofstream Test;
> Test << " ASDF asdf" << endl;
> }
>
> The same code does nothing on 8.3 , linux, .net and so on. Is 9.3
> buggy?

Not to the best of my knowledge. I'm not duplicating your symptoms
here. It is possible it that there is an inconsistent setting between
your app and how MSL C++ was compiled. Could you insert the following
as the first statement in main?

check(Metrowerks::msl_settings());

If an assertion fires, the text of the assertion should shed some light
on the situation. If an assertion doesn't fire, then I've guessed wrong
and will continue to try and help. And in that case, it would be
helpful to know if the crash occurs under the << " ASDF asdf" or under
the << endl.

-Howard
   

Copyright © 2006 knowledge-database   -   All rights reserved