Fixed initialization bug

This commit is contained in:
John Jones 2017-04-17 14:36:16 -05:00
parent 603ed1d72f
commit d6877b995c
2 changed files with 7 additions and 4 deletions

View file

@ -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);
}
}

View file

@ -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;