Bug fixes

This commit is contained in:
John Jones 2017-02-20 17:45:48 -05:00
parent 4e281ddd08
commit 0b8789ebbc
4 changed files with 33 additions and 13 deletions

View file

@ -72,7 +72,7 @@ struct MultiAddress* multiaddress_new_from_string(const char* straddress)//Const
}
strcpy(out->string, straddress);
if (string_to_bytes(&out->bytes, &out->bsize, out->string, strlen(out->string)) == 0 )
if (string_to_bytes(&(out->bytes), &out->bsize, out->string, strlen(out->string)) == 0 )
{
multiaddress_free(out);
return NULL;

View file

@ -42,7 +42,25 @@ int test_full() {
return 1;
}
int test_hex_to_val() {
return 0;
int test_hex_to_var() {
size_t d;
unsigned char* result = Hex_To_Var("04", &d);
if (d != 1)
return 0;
if (result[0] != 4)
return 0;
if (result != NULL)
free(result);
return 1;
}
int test_int_to_hex() {
int val = 2555351;
char* result = Int_To_Hex(val);
int retVal = Hex_To_Int(result);
if (retVal != val)
return 0;
return 1;
}

View file

@ -4,12 +4,16 @@
const char* names[] = {
"test_new_from_string",
"test_full"
"test_full",
"test_hex_to_var",
"test_int_to_hex"
};
int (*funcs[])(void) = {
test_new_from_string,
test_full
test_full,
test_hex_to_var,
test_int_to_hex
};
int testit(const char* name, int (*func)(void)) {

View file

@ -132,17 +132,15 @@ unsigned char* Hex_To_Var(const char* incoming, size_t* num_bytes) //HEX TO VAR[
retVal = (unsigned char*)malloc(*num_bytes);
char code[3];
code[3]='\0';
int i=0;
for(i=0; i < incoming_size; i += 2)
code[2]='\0';
int pos = 0;
for(int i=0; i < incoming_size; i += 2)
{
code[0] = incoming[i];
code[1] = incoming[i+1];
char *ck = NULL;
uint64_t lu = 0;
lu=strtoul(code, &ck, 16);
retVal[i] = lu;
i++;
uint64_t lu = strtol(code, NULL, 16);
retVal[pos] = (unsigned int)lu;
pos++;
}
return retVal;
}