incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: design of testuite exceptions (was: Re: svn commit: r418319 - /incubator/stdcxx/trunk/tests/strings/21.string.io.cpp)
Date Mon, 17 Jul 2006 20:14:36 GMT
Farid Zaripov wrote:
>  
> 
> 
>>-----Original Message-----
>>From: Martin Sebor [mailto:sebor@roguewave.com] 
>>Sent: Sunday, July 16, 2006 11:46 PM
>>To: stdcxx-dev@incubator.apache.org
>>Subject: Re: design of testuite exceptions (was: Re: svn 
>>commit: r418319 - 
>>/incubator/stdcxx/trunk/tests/strings/21.string.io.cpp)
>>
>>PS One thing to look into is formatting the text of the 
>>exception's what string directly into the what_ buffer 
>>instead dynamically allocating it only to free it later.
> 
> 
>>I believe rw_asnprintf has the ability to use the provided 
>>buffer if it's large enough.
> 
> 
>   Unfortunately, rw_asnprintf cannot use buffer with automatic or static
> storage.
> rw_asnprintf calls rw_vasnprintf which calls _rw_bufcat. If the buffer
> size is too small
> the _rw_bufcat allocates the memory using malloc() and unconditionally
> calls free() for
> the old buffer.

_rw_bufcat() is supposed to fail when the requested amount of memory
exceeds the maximum (Buffer::maxsize). When the format string starts
with the %{*} directive, maxsize is set to the value of the first
argument in the argument list. So some of the pieces necessary to
make this possible are in place, but not all of them. In addition,
the code that is there is buggy and needs to be fixed to make the
feature usable. The bottom line is that something like
rw_snprintf (buffer, size, "...", ...) should do what we want. Let
me look into it.

> Moreover the _rw_bufcat allocates the memory including
> the guard block
> (printf.cpp line 425) and even if the initial buffer was allocated using
> malloc()
> RW_ASSERT (printf.cpp line 461) will terminate the execution in the
> debug
> configurations.

Yes, but this won't happen once I fix the bugs.

Martin

Mime
View raw message