From: Erik Rozendaal Date: Wed, 15 Dec 2004 08:50:30 +0000 (+0000) Subject: rr.c: (ldns_rr_push_rd_field) Check result of XREALLOC and return false on X-Git-Tag: release-0.50~687 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b3c420fe1abd2eaac0d3f86246e11764f735d0f;p=thirdparty%2Fldns.git rr.c: (ldns_rr_push_rd_field) Check result of XREALLOC and return false on failure. --- diff --git a/ldns/rr.h b/ldns/rr.h index 0969af98..de2a29eb 100644 --- a/ldns/rr.h +++ b/ldns/rr.h @@ -14,8 +14,9 @@ #ifndef _LDNS_RR_H #define _LDNS_RR_H -#include "ldns/rdata.h" -#include "ldns/rr.h" +#include +#include +#include /* the different RR types */ /** a host address */ @@ -164,7 +165,7 @@ void ldns_rr_set_owner(t_rr *, uint8_t *); void ldns_rr_set_ttl(t_rr *, uint16_t); void ldns_rr_set_rd_count(t_rr *, uint16_t); void ldns_rr_set_class(t_rr *, t_class); -void ldns_rr_push_rd_field(t_rr *, t_rdata_field *); +bool ldns_rr_push_rd_field(t_rr *, t_rdata_field *); uint8_t *ldns_rr_owner(t_rr *); uint8_t ldns_rr_ttl(t_rr *); uint16_t ldns_rr_rd_count(t_rr *); diff --git a/rr.c b/rr.c index 454b0b48..a9b9364e 100644 --- a/rr.c +++ b/rr.c @@ -73,18 +73,23 @@ ldns_rr_set_class(t_rr *rr, t_class klass) * set rd_field member in the rr, it will be * placed in the next available spot */ -void +bool ldns_rr_push_rd_field(t_rr *rr, t_rdata_field *f) { uint16_t rd_count; - + t_rdata_field **rdata_fields; + rd_count = ldns_rr_rd_count(rr); /* grow the array */ - rr->_rdata_fields = XREALLOC( + rdata_fields = XREALLOC( rr->_rdata_fields, t_rdata_field *, rd_count + 1); - + if (!rdata_fields) { + return false; + } + /* add the new member */ + rr->_rdata_fields = rdata_fields; rr->_rdata_fields[rd_count] = f; ldns_rr_set_rd_count(rr, rd_count + 1);