From d6877b995c2a52cbfd365f639d1c34c2026428d7 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 17 Apr 2017 14:36:16 -0500 Subject: [PATCH] Fixed initialization bug --- multiaddr.c | 2 +- test_multiaddr.h | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/multiaddr.c b/multiaddr.c index aad41eb..394a223 100644 --- a/multiaddr.c +++ b/multiaddr.c @@ -175,7 +175,7 @@ char* multiaddress_get_peer_id(const struct MultiAddress* in) { if (str_len > 0) { result = malloc(str_len + 1); if (result != NULL) { - memset(result, 0, str_len); + memset(result, 0, str_len + 1); memcpy(result, ptr, str_len); } } diff --git a/test_multiaddr.h b/test_multiaddr.h index 3751e33..f98eff6 100644 --- a/test_multiaddr.h +++ b/test_multiaddr.h @@ -184,8 +184,8 @@ int test_multiaddr_peer_id() { } int test_multiaddr_get_peer_id() { - char* orig_address = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"; - char full_string[255]; + const char* orig_address = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"; + char full_string[255] = ""; char* result = NULL; int retVal = 0; struct MultiAddress *addr = NULL; @@ -196,7 +196,10 @@ int test_multiaddr_get_peer_id() { result = multiaddress_get_peer_id(addr); - if (result == NULL || strcmp(result, orig_address) != 0) + if (result == NULL) + goto exit; + + if (strcmp(orig_address, result) != 0) goto exit; retVal = 1;