Changeset: ca927b53bdfe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ca927b53bdfe
Modified Files:
        clients/src/mapilib/Mapi.mx
Branch: Oct2010
Log Message:

use at least assert() to check whether malloc() & realloc() succeeded
(when assertions are enabled)

mallocs can fail also for small sizes, and to prevent segfault, we should
always check whether a malloc succeeded or not, and properly handle the case
(error/exception) that is does not.
Here and for now, I just resorted to what's elswhere done in similar or
related code: use at least assert().
We should consider checking all malloc's properly, though ...


diffs (19 lines):

diff -r 5d5609708cc4 -r ca927b53bdfe clients/src/mapilib/Mapi.mx
--- a/clients/src/mapilib/Mapi.mx       Sat Dec 25 10:27:35 2010 +0100
+++ b/clients/src/mapilib/Mapi.mx       Sat Dec 25 10:35:45 2010 +0100
@@ -4394,6 +4394,7 @@
                if (sz > 512)
                        sz = 512;
                hdl->query = malloc(sz + 1);
+               assert(hdl->query);
                hdl->query[0] = '\0';
                strncpy(hdl->query, query, sz);
                hdl->query[sz] = '\0';
@@ -4403,6 +4404,7 @@
                        if (size < sz)
                                sz = size;
                        hdl->query = realloc(hdl->query, ln + sz + 1);
+                       assert(hdl->query);
                        strncat(hdl->query, query, sz);
                }
        }
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to