diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-26 17:48:12 -0700 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-26 17:48:12 -0700 |
commit | 85b2db2ad2349e86605993f52d199d2797aec2da (patch) | |
tree | 1d8a4af2533a2790cbd9d170c5c4164d2726e46a /testing/DHT_cryptosendfiletest.c | |
parent | e6a33fede62f54b8d925a8d4b986581b3afddc0b (diff) | |
parent | a1b93c397c8776e1bb07e3e01110d0ee5b9d31b9 (diff) |
Merge pull request #112 from KostyaKow/master
took out several strlen() calls out of the loop; replaced int's with siz...
Diffstat (limited to 'testing/DHT_cryptosendfiletest.c')
-rw-r--r-- | testing/DHT_cryptosendfiletest.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/testing/DHT_cryptosendfiletest.c b/testing/DHT_cryptosendfiletest.c index b06ddea5..5c3a0256 100644 --- a/testing/DHT_cryptosendfiletest.c +++ b/testing/DHT_cryptosendfiletest.c | |||
@@ -60,14 +60,15 @@ void printip(IP_Port ip_port) | |||
60 | printf("\nIP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port)); | 60 | printf("\nIP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port)); |
61 | } | 61 | } |
62 | 62 | ||
63 | /* horrible function from one of my first C programs. | 63 | //TODO: rewrite |
64 | *only here because I was too lazy to write a proper one. */ | ||
65 | unsigned char * hex_string_to_bin(char hex_string[]) | 64 | unsigned char * hex_string_to_bin(char hex_string[]) |
66 | { | 65 | { |
67 | unsigned char * val = malloc(strlen(hex_string)); | 66 | size_t len = strlen(hex_string); |
67 | unsigned char * val = malloc(len); | ||
68 | char * pos = hex_string; | 68 | char * pos = hex_string; |
69 | int i=0; | 69 | int i=0; |
70 | while(i < strlen(hex_string)) { | 70 | while(i < len) |
71 | { | ||
71 | sscanf(pos,"%2hhx",&val[i]); | 72 | sscanf(pos,"%2hhx",&val[i]); |
72 | pos+=2; | 73 | pos+=2; |
73 | i++; | 74 | i++; |
@@ -239,4 +240,4 @@ int main(int argc, char *argv[]) | |||
239 | 240 | ||
240 | shutdown_networking(); | 241 | shutdown_networking(); |
241 | return 0; | 242 | return 0; |
242 | } \ No newline at end of file | 243 | } |