[sword-devel] SWBuf potential problem
Troy A. Griffitts
scribe at crosswire.org
Fri Jun 10 11:39:42 MST 2005
Hey Daniel,
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
do not.
Daniel Glassey wrote:
> Hi,
> 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.
>
> Regards,
> Daniel
>
>
> ------------------------------------------------------------------------
>
> Index: include/swbuf.h
> ===================================================================
> --- 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
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
More information about the sword-devel
mailing list