Skip to content

Commit

Permalink
use calloc instead of malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarning committed Mar 24, 2024
1 parent 4d4abae commit fb9b01c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ bool decode_msg(struct Message *msg, const uint8_t *buffer, size_t size)
// parse questions
uint32_t qcount = msg->qdCount;
for (i = 0; i < qcount; i += 1) {
struct Question *q = malloc(sizeof(struct Question));
struct Question *q = calloc(1, sizeof(struct Question));

q->qName = decode_domain_name(&buffer, size);
q->qType = get16bits(&buffer);
Expand Down Expand Up @@ -476,8 +476,7 @@ void resolve_query(struct Message *msg)
// for every question append resource records
q = msg->questions;
while (q) {
rr = malloc(sizeof(struct ResourceRecord));
memset(rr, 0, sizeof(struct ResourceRecord));
rr = calloc(1, sizeof(struct ResourceRecord));

rr->name = strdup(q->qName);
rr->type = q->qType;
Expand Down

0 comments on commit fb9b01c

Please sign in to comment.