Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Codewarrior Windows > Re: writing to ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 244 of 318
Post > Topic >>

Re: writing to a non-open file crashes

by Howard Hinnant <hinnant@[EMAIL PROTECTED] > Jan 18, 2005 at 07:36 PM

In article <1106055734.834784.209340@[EMAIL PROTECTED]
>,
 "SiamGod" <ed.woods@[EMAIL PROTECTED]
> 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 
<msl_bufferedbuf>.  You can patch it by opening that file (under 
MSL_C++/MSL_Common/Include/) and search for the member function:

bufferedbuf<charT, traits>::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 <class charT, class traits>
_STD::basic_streambuf<charT,traits>*
bufferedbuf<charT, traits>::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




 5 Posts in Topic:
writing to a non-open file crashes
"SiamGod" <e  2005-01-17 13:07:56 
Re: writing to a non-open file crashes
Howard Hinnant <hinnan  2005-01-17 21:58:56 
Re: writing to a non-open file crashes
"SiamGod" <e  2005-01-18 05:42:14 
Re: writing to a non-open file crashes
Howard Hinnant <hinnan  2005-01-18 19:36:36 
Re: writing to a non-open file crashes
"SiamGod" <e  2005-01-18 14:10:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 2:16:38 CDT 2008.