From 09cb83569dd15dcd42cdf1d848bfe97bd3bad3c8 Mon Sep 17 00:00:00 2001 From: Nathan Hwang Date: Mon, 8 Oct 2012 01:14:25 -0400 Subject: [PATCH] Fixed tests, cleaned up a bit --- c/reconf | 3 +++ c/src/base92.c | 13 +++---------- c/tests/binary_string.c | 3 --- c/tests/hello_world.c | 1 - c/tests/lengths.c | 4 ---- c/tests/utils.h | 3 --- 6 files changed, 6 insertions(+), 21 deletions(-) diff --git a/c/reconf b/c/reconf index a362f98..3cf0a7c 100755 --- a/c/reconf +++ b/c/reconf @@ -1,4 +1,7 @@ #!/bin/sh +echo "### Running make clean..." +make clean +make dist-clean echo "### Running aclocal..." aclocal echo "### Running autoconf..." diff --git a/c/src/base92.c b/c/src/base92.c index da7d814..f378c33 100644 --- a/c/src/base92.c +++ b/c/src/base92.c @@ -6,8 +6,6 @@ #include -#include - unsigned char ENCODE_MAPPING[256] = (unsigned char[]){ 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, @@ -104,7 +102,6 @@ unsigned char* base92encode(unsigned char* str, int len) { wssize += 8; if (wssize >= 13) { tmp = (workspace >> (wssize - 13)) & 8191; - // printf("bd: %d\n", tmp); c = base92chr_encode(tmp / 91); if (c == 0) { // do something, illegal character @@ -171,17 +168,13 @@ unsigned char* base92decode(unsigned char* str, int* len) { return res; } // calculate size - *len = ((size/2 * 13) + (size % 2) * 6) % 8; - if (*len == 0) { - *len = ((size/2 * 13) + (size % 2) * 6) / 8; - } else { - *len = ((size/2 * 13) + (size % 2) * 6) / 8 + 1; - } + *len = ((size/2 * 13) + (size%2 * 6)) / 8; res = (unsigned char *)malloc(sizeof(char) * (*len)); // handle pairs of chars workspace = 0; wssize = 0; - for (i = 0; i < size; i += 2) { + j = 0; + for (i = 0; i + 1 < size; i += 2) { b1 = base92chr_decode(str[i]); b2 = base92chr_decode(str[i+1]); workspace = (workspace << 13) | (b1 * 91 + b2); diff --git a/c/tests/binary_string.c b/c/tests/binary_string.c index d1aef4f..c7345b5 100644 --- a/c/tests/binary_string.c +++ b/c/tests/binary_string.c @@ -31,12 +31,9 @@ int main() { str[14] = 195; str[15] = 0; - printf("MU"); if(strcmp(base92encode(str, 15), "c)L#O2K}%8Vo_OM3kB:") != 0) exit(1); - printf("MU"); s = base92decode("c)L#O2K}%8Vo_OM3kB:", &i); - printf("MUMU"); if(strcmp(stringify(s, i), str) != 0) exit(1); return 0; diff --git a/c/tests/hello_world.c b/c/tests/hello_world.c index 09d32f9..1159eb0 100644 --- a/c/tests/hello_world.c +++ b/c/tests/hello_world.c @@ -13,7 +13,6 @@ int main() { if(strcmp(base92encode("hello world", 11), "Fc_$aOTdKnsM*k") != 0) exit(1); s = base92decode("Fc_$aOTdKnsM*k", &i); - printf("%s\n", s); if(strcmp(stringify(s, i), "hello world") != 0) exit(1); return 0; diff --git a/c/tests/lengths.c b/c/tests/lengths.c index 50deb6e..9d25925 100644 --- a/c/tests/lengths.c +++ b/c/tests/lengths.c @@ -33,15 +33,11 @@ int main() { str[0] = 0; for(i = 0; i < LEN; i++) { - printf("MU %d\n", i); str[i] = 'a'; str[i+1] = 0; - printf("s1: %s\n", base92encode(str, i+1)); - printf("s2: %s\n", strs[i]); if(strcmp(base92encode(str, i+1), strs[i]) != 0) exit(1); s = base92decode(strs[i], &j); - printf("s: %s\n", stringify(s, j)); if(strcmp(stringify(s, j), str) != 0) exit(1); } diff --git a/c/tests/utils.h b/c/tests/utils.h index e5c5bcf..749237a 100644 --- a/c/tests/utils.h +++ b/c/tests/utils.h @@ -5,16 +5,13 @@ // - Nathan Hwang (thenoviceoof) #include -#include unsigned char *stringify(char *str, int i) { int j; unsigned char *s; - printf("i: %d\n", i); s = (unsigned char*)malloc(sizeof(char) * i + 1); for (j = 0; j < i; j++) { - printf("j: %d\n", j); s[j] = str[j]; } s[j+1] = 0;