Fixed memory leak and most compiler warnings

This commit is contained in:
John Jones 2017-07-17 15:11:08 -05:00
parent 58a6240af9
commit 86d3cd422e
5 changed files with 18 additions and 17 deletions

View file

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

View file

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

View file

@ -172,7 +172,7 @@ int is_valid_ipv6(char *str)
{
str++;
if(ishexdigit(*str)||*str==0&&hncount<MAX_HEX_NUMBER_COUNT)
if(ishexdigit(*str) || (*str==0 && hncount < MAX_HEX_NUMBER_COUNT ))
{
packed=1;
hncount++;
@ -299,6 +299,7 @@ char * int2ip(int inputintip)
* @param results where to put the resultant string
* @param in_bytes the bytes to unserialize
* @param in_bytes_size the length of the bytes array
* @returns 0 on error, otherwise 1
*/
int bytes_to_string(char** buffer, const uint8_t* in_bytes, int in_bytes_size)
{
@ -314,7 +315,7 @@ int bytes_to_string(char** buffer, const uint8_t* in_bytes, int in_bytes_size)
// set up variables
load_protocols(&head);
memset(hex, 0, (in_bytes_size * 2) + 1);
char* tmp = Var_To_Hex(in_bytes, size);
char* tmp = (char*)Var_To_Hex((char*)in_bytes, size);
memcpy(hex, tmp, in_bytes_size * 2);
free(tmp);
pid[2] = 0;
@ -391,8 +392,8 @@ int bytes_to_string(char** buffer, const uint8_t* in_bytes, int in_bytes_size)
memcpy(IPFS_ADDR, &hex[lastpos], addrsize);
// convert the address from hex values to a binary array
size_t num_bytes = 0;
unsigned char* addrbuf = Hex_To_Var(IPFS_ADDR, &num_bytes);
size_t b58_size = strlen(IPFS_ADDR);
unsigned char* addrbuf = Hex_To_Var((char*)IPFS_ADDR, &num_bytes);
size_t b58_size = strlen((char*)IPFS_ADDR);
unsigned char b58[b58_size];
memset(b58, 0, b58_size);
unsigned char *ptr_b58 = b58;
@ -407,7 +408,7 @@ int bytes_to_string(char** buffer, const uint8_t* in_bytes, int in_bytes_size)
strcat(results, "/");
strcat(results, protocol->name);
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;
}

View file

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

View file

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