diff options
author | Jfreegman <Jfreegman@gmail.com> | 2013-08-08 04:51:58 -0400 |
---|---|---|
committer | Jfreegman <Jfreegman@gmail.com> | 2013-08-08 04:51:58 -0400 |
commit | 6f98fc47b02d70c2e2eb50d4bdc942286950cda5 (patch) | |
tree | 59937d1b442185aa7c0c8401258fd9e3b9453df2 /testing/toxic | |
parent | 225f74e844299c405b744a9d03f4fcc0430b430a (diff) |
fix magic numbers
Diffstat (limited to 'testing/toxic')
-rw-r--r-- | testing/toxic/chat.c | 6 | ||||
-rw-r--r-- | testing/toxic/main.c | 2 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 24 | ||||
-rw-r--r-- | testing/toxic/windows.h | 4 |
4 files changed, 19 insertions, 17 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 28c5de6c..56dfb050 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | typedef struct { | 17 | typedef struct { |
18 | int friendnum; | 18 | int friendnum; |
19 | char line[256]; | 19 | char line[MAX_STR_SIZE]; |
20 | size_t pos; | 20 | size_t pos; |
21 | WINDOW* history; | 21 | WINDOW* history; |
22 | WINDOW* linewin; | 22 | WINDOW* linewin; |
@@ -178,9 +178,9 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | else if (!strcmp(cmd, "/myid")) { | 180 | else if (!strcmp(cmd, "/myid")) { |
181 | char id[32*2 + 1] = {0}; | 181 | char id[KEY_SIZE_BYTES*2+1] = {0}; |
182 | int i; | 182 | int i; |
183 | for (i = 0; i < 32; i++) { | 183 | for (i = 0; i < KEY_SIZE_BYTES; i++) { |
184 | char xx[3]; | 184 | char xx[3]; |
185 | snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); | 185 | snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); |
186 | strcat(id, xx); | 186 | strcat(id, xx); |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index b2310c80..d1519556 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -37,7 +37,7 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
37 | wprintw(prompt->window, "\nFriend request from:\n"); | 37 | wprintw(prompt->window, "\nFriend request from:\n"); |
38 | 38 | ||
39 | int i; | 39 | int i; |
40 | for (i = 0; i < 32; ++i) { | 40 | for (i = 0; i < KEY_SIZE_BYTES; ++i) { |
41 | wprintw(prompt->window, "%02x", public_key[i] & 0xff); | 41 | wprintw(prompt->window, "%02x", public_key[i] & 0xff); |
42 | } | 42 | } |
43 | 43 | ||
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 661d881f..08874a9a 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -12,12 +12,12 @@ | |||
12 | 12 | ||
13 | #include "windows.h" | 13 | #include "windows.h" |
14 | 14 | ||
15 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; // XXX | 15 | uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX |
16 | uint8_t num_requests=0; // XXX | 16 | uint8_t num_requests=0; // XXX |
17 | 17 | ||
18 | extern void on_friendadded(int friendnumber); | 18 | extern void on_friendadded(int friendnumber); |
19 | static void print_usage(ToxWindow *self); | 19 | static void print_usage(ToxWindow *self); |
20 | static char prompt_buf[256] = {0}; | 20 | static char prompt_buf[MAX_STR_SIZE] = {0}; |
21 | static int prompt_buf_pos = 0; | 21 | static int prompt_buf_pos = 0; |
22 | 22 | ||
23 | // XXX: | 23 | // XXX: |
@@ -43,7 +43,7 @@ unsigned char *hex_string_to_bin(char hex_string[]) | |||
43 | static void execute(ToxWindow *self, char *u_cmd) | 43 | static void execute(ToxWindow *self, char *u_cmd) |
44 | { | 44 | { |
45 | int newlines = 0; | 45 | int newlines = 0; |
46 | char cmd[256] = {0}; | 46 | char cmd[MAX_STR_SIZE] = {0}; |
47 | int i; | 47 | int i; |
48 | for (i = 0; i < strlen(prompt_buf); ++i) { | 48 | for (i = 0; i < strlen(prompt_buf); ++i) { |
49 | if (u_cmd[i] == '\n') | 49 | if (u_cmd[i] == '\n') |
@@ -53,9 +53,9 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
53 | } | 53 | } |
54 | 54 | ||
55 | int leading_spc = 0; | 55 | int leading_spc = 0; |
56 | for (i = 0; i < 256 && isspace(cmd[i]); ++i) | 56 | for (i = 0; i < MAX_STR_SIZE && isspace(cmd[i]); ++i) |
57 | leading_spc++; | 57 | leading_spc++; |
58 | memmove(cmd, cmd + leading_spc, 256 - leading_spc); | 58 | memmove(cmd, cmd + leading_spc, MAX_STR_SIZE - leading_spc); |
59 | 59 | ||
60 | int cmd_end = strlen(cmd); | 60 | int cmd_end = strlen(cmd); |
61 | while (cmd_end > 0 && cmd_end--) | 61 | while (cmd_end > 0 && cmd_end--) |
@@ -109,7 +109,7 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
109 | } | 109 | } |
110 | 110 | ||
111 | dht.port = htons(atoi(port)); | 111 | dht.port = htons(atoi(port)); |
112 | uint32_t resolved_address = resolve_addr(ip); | 112 | uintKEY_SIZE_BYTES_t resolved_address = resolve_addr(ip); |
113 | if (resolved_address == 0) { | 113 | if (resolved_address == 0) { |
114 | return; | 114 | return; |
115 | } | 115 | } |
@@ -121,9 +121,9 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
121 | } | 121 | } |
122 | 122 | ||
123 | else if (!strncmp(cmd, "add ", strlen("add "))) { | 123 | else if (!strncmp(cmd, "add ", strlen("add "))) { |
124 | uint8_t id_bin[32]; | 124 | uint8_t id_bin[KEY_SIZE_BYTES]; |
125 | char xx[3]; | 125 | char xx[3]; |
126 | uint32_t x; | 126 | uintKEY_SIZE_BYTES_t x; |
127 | char *id = strchr(cmd, ' '); | 127 | char *id = strchr(cmd, ' '); |
128 | if (id == NULL) { | 128 | if (id == NULL) { |
129 | wprintw(self->window, "Invalid syntax.\n"); | 129 | wprintw(self->window, "Invalid syntax.\n"); |
@@ -136,12 +136,12 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
136 | msg++; | 136 | msg++; |
137 | } | 137 | } |
138 | else msg = ""; | 138 | else msg = ""; |
139 | if (strlen(id) != 2*32) { | 139 | if (strlen(id) != 2*KEY_SIZE_BYTES) { |
140 | wprintw(self->window, "Invalid ID length.\n"); | 140 | wprintw(self->window, "Invalid ID length.\n"); |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | int i; | 143 | int i; |
144 | for (i = 0; i < 32; ++i) { | 144 | for (i = 0; i < KEY_SIZE_BYTES; ++i) { |
145 | xx[0] = id[2*i]; | 145 | xx[0] = id[2*i]; |
146 | xx[1] = id[2*i+1]; | 146 | xx[1] = id[2*i+1]; |
147 | xx[2] = '\0'; | 147 | xx[2] = '\0'; |
@@ -251,9 +251,9 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
251 | } | 251 | } |
252 | 252 | ||
253 | else if (!strcmp(cmd, "myid")) { | 253 | else if (!strcmp(cmd, "myid")) { |
254 | char id[32*2 + 1] = {0}; | 254 | char id[KEY_SIZE_BYTES*2 + 1] = {0}; |
255 | size_t i; | 255 | size_t i; |
256 | for (i = 0; i < 32; ++i) { | 256 | for (i = 0; i < KEY_SIZE_BYTES; ++i) { |
257 | char xx[3]; | 257 | char xx[3]; |
258 | snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); | 258 | snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); |
259 | strcat(id, xx); | 259 | strcat(id, xx); |
diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index cb45614d..287e534a 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h | |||
@@ -5,7 +5,9 @@ | |||
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #define TOXWINDOWS_MAX_NUM 32 | 6 | #define TOXWINDOWS_MAX_NUM 32 |
7 | #define MAX_FRIENDS_NUM 100 | 7 | #define MAX_FRIENDS_NUM 100 |
8 | 8 | #define MAX_STR_SIZE 256 | |
9 | #define KEY_SIZE_BYTES 32 | ||
10 | |||
9 | /* number of permanent default windows */ | 11 | /* number of permanent default windows */ |
10 | #define N_DEFAULT_WINS 2 | 12 | #define N_DEFAULT_WINS 2 |
11 | 13 | ||