Our realloc(3) and reallocf(3) can handle NULL, which turns it into a
malloc(3) call, so don't test if a pointer is NULL. Obtained from: OpenBSD (in spirit)
This commit is contained in:
parent
1b605ed6f8
commit
02654885c3
@ -92,7 +92,7 @@ __ovfl_get(BTREE *t, void *p, size_t *ssz, void **buf, size_t *bufsz)
|
||||
#endif
|
||||
/* Make the buffer bigger as necessary. */
|
||||
if (*bufsz < sz) {
|
||||
*buf = (char *)(*buf == NULL ? malloc(sz) : reallocf(*buf, sz));
|
||||
*buf = reallocf(*buf, sz);
|
||||
if (*buf == NULL)
|
||||
return (RET_ERROR);
|
||||
*bufsz = sz;
|
||||
|
@ -84,8 +84,7 @@ __bt_ret(BTREE *t, EPG *e, DBT *key, DBT *rkey, DBT *data, DBT *rdata, int copy)
|
||||
key->data = rkey->data;
|
||||
} else if (copy || F_ISSET(t, B_DB_LOCK)) {
|
||||
if (bl->ksize > rkey->size) {
|
||||
p = (void *)(rkey->data == NULL ?
|
||||
malloc(bl->ksize) : realloc(rkey->data, bl->ksize));
|
||||
p = realloc(rkey->data, bl->ksize);
|
||||
if (p == NULL)
|
||||
return (RET_ERROR);
|
||||
rkey->data = p;
|
||||
@ -111,9 +110,7 @@ __bt_ret(BTREE *t, EPG *e, DBT *key, DBT *rkey, DBT *data, DBT *rdata, int copy)
|
||||
} else if (copy || F_ISSET(t, B_DB_LOCK)) {
|
||||
/* Use +1 in case the first record retrieved is 0 length. */
|
||||
if (bl->dsize + 1 > rdata->size) {
|
||||
p = (void *)(rdata->data == NULL ?
|
||||
malloc(bl->dsize + 1) :
|
||||
realloc(rdata->data, bl->dsize + 1));
|
||||
p = realloc(rdata->data, bl->dsize + 1);
|
||||
if (p == NULL)
|
||||
return (RET_ERROR);
|
||||
rdata->data = p;
|
||||
|
@ -122,9 +122,7 @@ __rec_fpipe(BTREE *t, recno_t top)
|
||||
u_char *p;
|
||||
|
||||
if (t->bt_rdata.size < t->bt_reclen) {
|
||||
t->bt_rdata.data = t->bt_rdata.data == NULL ?
|
||||
malloc(t->bt_reclen) :
|
||||
reallocf(t->bt_rdata.data, t->bt_reclen);
|
||||
t->bt_rdata.data = reallocf(t->bt_rdata.data, t->bt_reclen);
|
||||
if (t->bt_rdata.data == NULL)
|
||||
return (RET_ERROR);
|
||||
t->bt_rdata.size = t->bt_reclen;
|
||||
@ -193,9 +191,7 @@ __rec_vpipe(BTREE *t, recno_t top)
|
||||
if (sz == 0) {
|
||||
len = p - (u_char *)t->bt_rdata.data;
|
||||
t->bt_rdata.size += (sz = 256);
|
||||
t->bt_rdata.data = t->bt_rdata.data == NULL ?
|
||||
malloc(t->bt_rdata.size) :
|
||||
reallocf(t->bt_rdata.data, t->bt_rdata.size);
|
||||
t->bt_rdata.data = reallocf(t->bt_rdata.data, t->bt_rdata.size);
|
||||
if (t->bt_rdata.data == NULL)
|
||||
return (RET_ERROR);
|
||||
p = (u_char *)t->bt_rdata.data + len;
|
||||
@ -230,9 +226,7 @@ __rec_fmap(BTREE *t, recno_t top)
|
||||
size_t len;
|
||||
|
||||
if (t->bt_rdata.size < t->bt_reclen) {
|
||||
t->bt_rdata.data = t->bt_rdata.data == NULL ?
|
||||
malloc(t->bt_reclen) :
|
||||
reallocf(t->bt_rdata.data, t->bt_reclen);
|
||||
t->bt_rdata.data = reallocf(t->bt_rdata.data, t->bt_reclen);
|
||||
if (t->bt_rdata.data == NULL)
|
||||
return (RET_ERROR);
|
||||
t->bt_rdata.size = t->bt_reclen;
|
||||
|
@ -67,9 +67,7 @@ __rec_ret(BTREE *t, EPG *e, recno_t nrec, DBT *key, DBT *data)
|
||||
|
||||
/* We have to copy the key, it's not on the page. */
|
||||
if (sizeof(recno_t) > t->bt_rkey.size) {
|
||||
p = (void *)(t->bt_rkey.data == NULL ?
|
||||
malloc(sizeof(recno_t)) :
|
||||
realloc(t->bt_rkey.data, sizeof(recno_t)));
|
||||
p = realloc(t->bt_rkey.data, sizeof(recno_t));
|
||||
if (p == NULL)
|
||||
return (RET_ERROR);
|
||||
t->bt_rkey.data = p;
|
||||
@ -97,9 +95,7 @@ __rec_ret(BTREE *t, EPG *e, recno_t nrec, DBT *key, DBT *data)
|
||||
} else if (F_ISSET(t, B_DB_LOCK)) {
|
||||
/* Use +1 in case the first record retrieved is 0 length. */
|
||||
if (rl->dsize + 1 > t->bt_rdata.size) {
|
||||
p = (void *)(t->bt_rdata.data == NULL ?
|
||||
malloc(rl->dsize + 1) :
|
||||
realloc(t->bt_rdata.data, rl->dsize + 1));
|
||||
p = realloc(t->bt_rdata.data, rl->dsize + 1);
|
||||
if (p == NULL)
|
||||
return (RET_ERROR);
|
||||
t->bt_rdata.data = p;
|
||||
|
Loading…
Reference in New Issue
Block a user