Skip to contentSkip to conversation

tools/firewire: nosy-dump: check for allocation failure

PATCH New Stefan Richter 1 participant 1 message Oct 22, 2012 1 message not in the archive Firewire

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 tools/firewire: nosy-dump: check for allocation failure

Behavior of null pointer dereference is undefined in the C language. Portably implement the desired behavior.

---
 tools/firewire/nosy-dump.c |    4 ++++
 1 file changed, 4 insertions(+)
tools/firewire/nosy-dump.c +4 -0
@@ -150,6 +150,8 @@ subaction_create(uint32_t *data, size_t
 
 	/* we put the ack in the subaction struct for easy access. */
 	sa = malloc(sizeof *sa - sizeof sa->packet + length);
+	if (!sa)
+		exit(EXIT_FAILURE);
 	sa->ack = data[length / 4 - 1];
 	sa->length = length;
 	memcpy(&sa->packet, data, length);
@@ -180,6 +182,8 @@ link_transaction_lookup(int request_node
 	}
 
 	t = malloc(sizeof *t);
+	if (!t)
+		exit(EXIT_FAILURE);
 	t->request_node = request_node;
 	t->response_node = response_node;
 	t->tlabel = tlabel;
Signature · 3 lines
Stefan Richter
-=====-===-- =-=- =-==-
http://arcgraph.de/sr/