[sword-devel] SWBuf potential problem
dmsmith555 at yahoo.com
Fri Jun 10 12:55:58 MST 2005
It has been a long time since I have coded in C++ but I seem to remember
that a program can set a global memory error handler. Then this error
can do something marginally appropriate for the problem. In our
situation, we used it to try to log a short static message and exit the
When we had this in place we never checked the return of any object
Daniel Glassey wrote:
>On 10/06/05, Troy A. Griffitts <scribe at crosswire.org> wrote:
>> Thanks for the catch, but we don't check for successful memory
>>allocation anywhere in the engine. I'm not sure what we'd do if we ran
>>out of memory. Gracefully degradating from such a state is a complex
>>problem. Also, our engine doesn't use try/catch/throw error handling,
>>so throwing anything would cross a consistency line. Note: not debating
>>that we SHOULDN'T use exception error handling, only that we currently
>Fair enough to not throw as long as it does something. It is one thing
>to not check and another thing to allow someone to overwrite bits of
>memory that they shouldn't.
>The *end = 0; is a _really_ bad idea if you aren't certain that that
>memory has been allocated.
>>Daniel Glassey wrote:
>>>While encountering other problems on my machine I've found a potential
>>>problem with SWBuf::assureSize.
>>>It reallocs or mallocs the buffer but doesn't check that that has
>>>succeeded before setting the 'end' of the buffer to 0.
>>>Patch attached that does a check. Thought I'd just check before checking it in.
>>>--- include/swbuf.h (revision 1827)
>>>+++ include/swbuf.h (working copy)
>>>@@ -58,6 +58,7 @@
>>> long size = (end - buf);
>>> checkSize += 128;
>>> buf = (char *)((allocSize) ? realloc(buf, checkSize) : malloc(checkSize));
>>>+ if (!buf) throw("Failed to extend SWBuf buffer");
>>> allocSize = checkSize;
>>> end = (buf + size);
>>> *end = 0;
>sword-devel mailing list: sword-devel at crosswire.org
>Instructions to unsubscribe/change your settings at above page
More information about the sword-devel