From 86d3cd422ebac3c139665eab88857f84421e3507 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 17 Jul 2017 15:11:08 -0500 Subject: [PATCH] Fixed memory leak and most compiler warnings --- include/multiaddr/base58.h | 2 +- multiaddr.c | 2 +- protoutils.c | 13 +++++++------ test_multiaddr.h | 14 +++++++------- varhexutils.c | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/multiaddr/base58.h b/include/multiaddr/base58.h index 1b10a7c..9fbe418 100644 --- a/include/multiaddr/base58.h +++ b/include/multiaddr/base58.h @@ -9,7 +9,7 @@ * @param binary_data_size the size of the results buffer * @returns true(1) on success */ -int multiaddr_encoding_base58_decode(const unsigned char* base58, size_t base58_size, unsigned char** binary_data, size_t *binary_data_size); +int multiaddr_encoding_base58_decode(const char* base58, size_t base58_size, unsigned char** binary_data, size_t *binary_data_size); /** * encode an array of bytes into a base58 string diff --git a/multiaddr.c b/multiaddr.c index 023e06b..45e3b1c 100644 --- a/multiaddr.c +++ b/multiaddr.c @@ -53,7 +53,7 @@ struct MultiAddress* multiaddress_new_from_bytes(const uint8_t* byteaddress, int } out->bsize = size; memcpy(out->bytes, byteaddress, size); - if(!bytes_to_string(&out->string,byteaddress,size)==1) + if(!bytes_to_string(&out->string,byteaddress,size)) { multiaddress_free(out); return NULL; diff --git a/protoutils.c b/protoutils.c index d282a90..7117265 100644 --- a/protoutils.c +++ b/protoutils.c @@ -172,7 +172,7 @@ int is_valid_ipv6(char *str) { str++; - if(ishexdigit(*str)||*str==0&&hncountname); strcat(results, "/"); - strcat(results, b58); + strcat(results, (char*)b58); } } strcat(results, "/"); @@ -684,7 +685,7 @@ int string_to_bytes(uint8_t** finalbytes, size_t* realbbsize, const char* strx, { char* s_to_b = NULL; int s_to_b_size = 0; - if(address_string_to_bytes(protx, wp,strlen(wp), &s_to_b, &s_to_b_size) == "ERR") + if( strcmp(address_string_to_bytes(protx, wp,strlen(wp), &s_to_b, &s_to_b_size), "ERR") == 0) { malf = 1; } diff --git a/test_multiaddr.h b/test_multiaddr.h index d8b7096..7c5c134 100644 --- a/test_multiaddr.h +++ b/test_multiaddr.h @@ -41,7 +41,7 @@ int test_full() { printf("INITIAL: %s\n",addrstr); struct MultiAddress* a; a= multiaddress_new_from_string(addrstr); - unsigned char* tmp = Var_To_Hex(a->bytes, a->bsize); + unsigned char* tmp = Var_To_Hex((char*)a->bytes, a->bsize); printf("TEST BYTES: %s\n", tmp); free(tmp); @@ -50,19 +50,19 @@ int test_full() { printf("A STRING:%s\n",a->string); multiaddress_encapsulate(a,"/udp/3333/"); printf("A STRING ENCAPSULATED:%s\n",a->string); - tmp = Var_To_Hex(a->bytes, a->bsize); + tmp = Var_To_Hex((char*)a->bytes, a->bsize); printf("TEST BYTES: %s\n", tmp); free(tmp); multiaddress_decapsulate(a,"udp"); printf("A STRING DECAPSULATED UDP:%s\n",a->string); - tmp = Var_To_Hex(a->bytes, a->bsize); + tmp = Var_To_Hex((char*)a->bytes, a->bsize); printf("TEST BYTES: %s\n", tmp); free(tmp); multiaddress_encapsulate(a,"/udp/3333/"); printf("A STRING ENCAPSULATED UDP: %s\n",a->string); multiaddress_encapsulate(a,"/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"); printf("A STRING ENCAPSULATED IPFS:%s\n",a->string); - tmp = Var_To_Hex(a->bytes, a->bsize); + tmp = Var_To_Hex((char*)a->bytes, a->bsize); printf("TEST BYTES: %s\n", tmp); free(tmp); printf("TEST BYTE SIZE: %lu\n",a->bsize); @@ -153,7 +153,7 @@ int test_multiaddr_peer_id() { // switch to bytes and back again to verify the peer id follows... // 1. display the original bytes - result = Var_To_Hex(addr->bytes, addr->bsize); + result = (char*)Var_To_Hex((char*)addr->bytes, addr->bsize); fprintf(stderr, "Original Bytes: %s\n", result); free(result); result = NULL; @@ -161,13 +161,13 @@ int test_multiaddr_peer_id() { // make a new MultiAddress from bytes bytes = malloc(addr->bsize); memcpy(bytes, addr->bytes, addr->bsize); - addr2 = multiaddress_new_from_bytes(bytes, addr->bsize); + addr2 = multiaddress_new_from_bytes((unsigned char*)bytes, addr->bsize); free(bytes); bytes = NULL; // 2. Display the resultant bytes - result = Var_To_Hex(addr2->bytes, addr2->bsize); + result = Var_To_Hex((char*)addr2->bytes, addr2->bsize); fprintf(stderr, "New Bytes: %s\n", result); free(result); result = NULL; diff --git a/varhexutils.c b/varhexutils.c index dab4cfa..1915e0e 100644 --- a/varhexutils.c +++ b/varhexutils.c @@ -182,7 +182,7 @@ void convert2(char * convert_result2, uint8_t * bufhx) { uint8_t * buf = NULL; buf = bufhx; - char conv_proc[3]="\0"; + char conv_proc[4]="\0"; conv_proc[3] = '\0'; bzero(conv_proc, 3); int i; @@ -237,7 +237,7 @@ uint32_t HexVar_To_Num_32(char theHEXstring[]) //HEXIFIED VAR TO UINT32_T char codo[800] = "\0"; bzero(codo,800); strcpy(codo, theHEXstring); - char code[3] = "\0"; + char code[4] = "\0"; bzero(code,3); code[3] = '\0'; int x = 0;