From c479906dd6d429d695f393a97b1061f9ff9cba8c Mon Sep 17 00:00:00 2001
From: Michael Tuexen <tuexen@fh-muenster.de>
Date: Sat, 7 Oct 2017 14:35:14 +0200
Subject: [PATCH] Fix CID 187207 and CID 187216.

---
 gtests/net/packetdrill/run_packet.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/gtests/net/packetdrill/run_packet.c b/gtests/net/packetdrill/run_packet.c
index fc20dcbe..e1bd279f 100644
--- a/gtests/net/packetdrill/run_packet.c
+++ b/gtests/net/packetdrill/run_packet.c
@@ -109,13 +109,12 @@ static void add_packet_dump(char **error, const char *type,
 		char *old_error = *error;
 		char *dump = NULL, *dump_error = NULL;
 
-		packet_to_string(packet, format,
-				 &dump, &dump_error);
-		asprintf(error, "%s\n%s packet: %9.6f %s%s%s",
-			 old_error, type, usecs_to_secs(time_usecs), dump,
-			 dump_error ? "\n" : "",
-			 dump_error ? dump_error : "");
-
+		if (packet_to_string(packet, format, &dump, &dump_error) == STATUS_OK) {
+			asprintf(error, "%s\n%s packet: %9.6f %s%s%s",
+				 old_error, type, usecs_to_secs(time_usecs), dump,
+				 dump_error ? "\n" : "",
+				 dump_error ? dump_error : "");
+		}
 		free(dump);
 		free(dump_error);
 		free(old_error);
@@ -129,14 +128,12 @@ static void verbose_packet_dump(struct state *state, const char *type,
 	if (state->config->verbose) {
 		char *dump = NULL, *dump_error = NULL;
 
-		packet_to_string(live_packet, DUMP_SHORT,
-				 &dump, &dump_error);
-
-		printf("%s packet: %9.6f %s%s%s\n",
-		       type, usecs_to_secs(time_usecs), dump,
-		       dump_error ? "\n" : "",
-		       dump_error ? dump_error : "");
-
+		if (packet_to_string(live_packet, DUMP_SHORT,  &dump, &dump_error) == STATUS_OK) {
+			printf("%s packet: %9.6f %s%s%s\n",
+			       type, usecs_to_secs(time_usecs), dump,
+			       dump_error ? "\n" : "",
+			       dump_error ? dump_error : "");
+		}
 		free(dump);
 		free(dump_error);
 	}
-- 
GitLab