Skip to content

Commit

Permalink
fix bugs and/or warnings ref #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Denis committed May 27, 2019
1 parent 3e6f1f7 commit af75a4b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
7 changes: 3 additions & 4 deletions lib/cgo/tests/check_cipher.address.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ START_TEST(TestAddressVerify)
{
cipher__PubKey pubkey;
cipher__SecKey seckey;
cipher__PubKey pubkey2;
cipher__SecKey seckey2;
cipher__Address addr;

Expand Down Expand Up @@ -47,7 +46,7 @@ START_TEST(TestAddressString)
cipher__PubKey pk;
cipher__SecKey sk;
cipher__Address addr, addr2, addr3;
GoString str = {buff, 0};
GoString str = {(char*)buff, 0};

GoUint32 err = SKY_cipher_GenerateKeyPair(&pk, &sk);
ck_assert(err == SKY_OK);
Expand All @@ -70,8 +69,8 @@ END_TEST

START_TEST(TestAddressBulk)
{
unsigned char buff[50];
GoSlice slice = {buff, 0, 50};
unsigned char buff2[50];
GoSlice slice = {buff2, 0, 50};
int i;
for (i = 0; i < 1024; ++i) {
GoUint32 err;
Expand Down
21 changes: 6 additions & 15 deletions lib/cgo/tests/check_cipher.crypto.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ START_TEST(TestPubKeyHex)
cipher__PubKey p, p2;
cipher__SecKey sk;
GoString s3, s4;
unsigned char buff[50];
unsigned char buff_s3[50];
GoSlice slice = {buff, 0, 50};
const char buff_s3[50];
unsigned int errorcode;

GoUint32 err = SKY_cipher_GenerateKeyPair(&p, &sk);
Expand All @@ -109,18 +107,16 @@ START_TEST(TestPubKeyHex)
ck_assert(err == SKY_OK);
s3.n = tmp_s3.n;
s3.p = tmp_s3.p;
registerMemCleanup((void*)s3.p);
errorcode = SKY_cipher_PubKeyFromHex(s3, &p2);
ck_assert(errorcode == SKY_OK);
ck_assert(isPubKeyEq(&p, &p2));

unsigned char s4_buff[50];
char s4_buff[sizeof(cipher__PubKey) * 2];
GoString_ tmp_s4 = {s4_buff, 0};
err = SKY_cipher_PubKey_Hex(&p2, &tmp_s4);
ck_assert(err == SKY_OK);
s4.n = s4.n;
s4.p = s4.p;
registerMemCleanup((void*)s4.p);
s4.n = tmp_s4.n;
s4.p = tmp_s4.p;
// // TODO: Translate into cr_assert(eq(type(GoString), s3, s4));
ck_assert(isGoStringEq(s3, s4) == 0);
}
Expand Down Expand Up @@ -186,7 +182,7 @@ START_TEST(TestPubKeyToAddress2)
ck_assert(errorcode == SKY_OK);
SKY_cipher_Address_String(&addr, &addrStr);
unsigned char buff[50];
GoString addrStr_tmp = {buff, 0};
GoString addrStr_tmp = {(const char*)buff, 0};
addrStr_tmp.p = addrStr.p;
addrStr_tmp.n = addrStr.n;
registerMemCleanup((void*)addrStr.p);
Expand Down Expand Up @@ -279,8 +275,6 @@ START_TEST(TestSigHex)
{
unsigned char buff[66];
GoSlice b = {buff, 0, 66};
char strBuff[150],
strBuff2[150];
GoString str = {NULL, 0},
str2 = {NULL, 0};
cipher__Sig s, s2;
Expand All @@ -290,19 +284,16 @@ START_TEST(TestSigHex)
errorcode = SKY_cipher_NewSig(b, &s);

ck_assert(errorcode == SKY_OK);
char buffer[100];
const char buffer[sizeof(s) * 2];
GoString_ tmp_str = {buffer, 0};
SKY_cipher_Sig_Hex(&s, &tmp_str);
str.p = tmp_str.p;
str.n = tmp_str.n;
registerMemCleanup((void*)str.p);
errorcode = SKY_cipher_SigFromHex(str, &s2);

ck_assert(errorcode == SKY_OK);
ck_assert(isU8Eq(s, s2, 65));

char buffer2[100];
GoString_ tmp_str2 = {buffer, 0};
SKY_cipher_Sig_Hex(&s2, &tmp_str);
str2.p = tmp_str.p;
str2.n = tmp_str.n;
Expand Down
2 changes: 0 additions & 2 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ START_TEST(TestSHA256KnownValue)
int i;
for (i = 0; i < 3; ++i) {
GoSlice slice_input;
GoSlice slice_output;

slice_input.data = vals[i].input;
slice_input.len = strlen(vals[i].input);
Expand Down Expand Up @@ -227,7 +226,6 @@ START_TEST(TestSHA256Null)
{
cipher__SHA256 x;
memset(&x, 0, sizeof(cipher__SHA256));
GoUint32 result;
GoUint8 isNull;
ck_assert(SKY_cipher_SHA256_Null(&x, &isNull) == SKY_OK);
ck_assert(isNull);
Expand Down
1 change: 0 additions & 1 deletion lib/cgo/tests/test_main_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
int main(void)
{
int number_failed = 0;
int number_failed_fork = 0;
SRunner *sr = srunner_create(common_check_cipher_hash());
srunner_add_suite(sr, common_check_cipher_address());
srunner_add_suite(sr, common_check_cipher_crypto());
Expand Down
2 changes: 1 addition & 1 deletion lib/cgo/tests/testutils/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void *MEMPOOL[1024 * 256];

GoInt_ isU8Eq(unsigned char p1[], unsigned char p2[], size_t len) {

if (strncmp(p1, p2, len) == 0) {
if (strncmp((const char*)p1, (const char*)p2, len) == 0) {

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cgo/tests/testutils/libsky_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GoInt_ isSigEq(cipher__Sig *sig1, cipher__Sig *sig2) {
}

GoInt_ isSHA256Eq(cipher__SHA256 *sh1, cipher__SHA256 *sh2) {
return (memcmp((void *)sh1, (void *)sh1, sizeof(cipher__SHA256)) == 0);
return (memcmp((void *)sh1, (void *)sh2, sizeof(cipher__SHA256)) == 0);
}

GoInt_ isGoSliceEq(GoSlice *slice1, GoSlice *slice2) {
Expand Down

0 comments on commit af75a4b

Please sign in to comment.