diff --git a/gtests/net/packetdrill/run_packet.c b/gtests/net/packetdrill/run_packet.c index fc20dcbe2431324b34bf85e1e072b1ab424bfe82..e1bd279f7344eaadde600fce9b0396e701ec6e98 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); }