summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-26 17:48:12 -0700
committerirungentoo <irungentoo@gmail.com>2013-07-26 17:48:12 -0700
commit85b2db2ad2349e86605993f52d199d2797aec2da (patch)
tree1d8a4af2533a2790cbd9d170c5c4164d2726e46a /testing/nTox.c
parente6a33fede62f54b8d925a8d4b986581b3afddc0b (diff)
parenta1b93c397c8776e1bb07e3e01110d0ee5b9d31b9 (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/nTox.c')
-rw-r--r--testing/nTox.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index caa7d45c..3a5e9bb3 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -46,12 +46,15 @@ void new_lines(char *line)
46 do_refresh(); 46 do_refresh();
47} 47}
48 48
49//TODO: rewrite
49unsigned char * hex_string_to_bin(char hex_string[]) 50unsigned char * hex_string_to_bin(char hex_string[])
50{ 51{
51 unsigned char * val = malloc(strlen(hex_string)); 52 size_t len = strlen(hex_string);
53 unsigned char * val = malloc(len);
52 char * pos = hex_string; 54 char * pos = hex_string;
53 int i=0; 55 int i=0;
54 while(i < strlen(hex_string)) { 56 while(i < len)
57 {
55 sscanf(pos,"%2hhx",&val[i]); 58 sscanf(pos,"%2hhx",&val[i]);
56 pos+=2; 59 pos+=2;
57 i++; 60 i++;
@@ -80,7 +83,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
80 doMessenger(); 83 doMessenger();
81 } else if (line[1] == 'm') { //message command: /m friendnumber messsage 84 } else if (line[1] == 'm') { //message command: /m friendnumber messsage
82 int i; 85 int i;
83 int len = strlen(line); 86 size_t len = strlen(line);
84 char numstring[len-3]; 87 char numstring[len-3];
85 char message[len-3]; 88 char message[len-3];
86 for (i=0; i<len; i++) { 89 for (i=0; i<len; i++) {
@@ -99,7 +102,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
99 } else if (line[1] == 'n') { 102 } else if (line[1] == 'n') {
100 uint8_t name[MAX_NAME_LENGTH]; 103 uint8_t name[MAX_NAME_LENGTH];
101 int i = 0; 104 int i = 0;
102 for (i=3; i<strlen(line); i++) { 105 size_t len = strlen(line);
106 for (i=3; i<len; i++) {
103 if (line[i] == 0 || line[i] == '\n') break; 107 if (line[i] == 0 || line[i] == '\n') break;
104 name[i - 3] = line[i]; 108 name[i - 3] = line[i];
105 } 109 }
@@ -111,7 +115,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
111 } else if (line[1] == 's') { 115 } else if (line[1] == 's') {
112 uint8_t status[MAX_USERSTATUS_LENGTH]; 116 uint8_t status[MAX_USERSTATUS_LENGTH];
113 int i = 0; 117 int i = 0;
114 for (i=3; i<strlen(line); i++) { 118 size_t len = strlen(line);
119 for (i=3; i<len; i++) {
115 if (line[i] == 0 || line[i] == '\n') break; 120 if (line[i] == 0 || line[i] == '\n') break;
116 status[i - 3] = line[i]; 121 status[i - 3] = line[i];
117 } 122 }
@@ -133,7 +138,8 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
133{ 138{
134 int i = 0; 139 int i = 0;
135 strcpy(output,input); 140 strcpy(output,input);
136 for (i=line_width; i < strlen(output); i = i + line_width) { 141 size_t len = strlen(output);
142 for (i=line_width; i < len; i = i + line_width) {
137 while (output[i] != ' ' && i != 0) { 143 while (output[i] != ' ' && i != 0) {
138 i--; 144 i--;
139 } 145 }
@@ -145,7 +151,7 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
145 151
146int count_lines(char *string) 152int count_lines(char *string)
147{ 153{
148 int len = strlen(string); 154 size_t len = strlen(string);
149 int i; 155 int i;
150 int count = 1; 156 int count = 1;
151 for (i=0; i < len; i++) { 157 for (i=0; i < len; i++) {
@@ -158,7 +164,7 @@ int count_lines(char *string)
158 164
159char *appender(char *str, const char c) 165char *appender(char *str, const char c)
160{ 166{
161 int len = strlen(str); 167 size_t len = strlen(str);
162 if (len < STRING_LENGTH) { 168 if (len < STRING_LENGTH) {
163 str[len + 1] = str[len]; 169 str[len + 1] = str[len];
164 str[len] = c; 170 str[len] = c;
@@ -216,7 +222,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
216 time ( &rawtime ); 222 time ( &rawtime );
217 timeinfo = localtime ( &rawtime ); 223 timeinfo = localtime ( &rawtime );
218 char* temp = asctime(timeinfo); 224 char* temp = asctime(timeinfo);
219 int len = strlen(temp); 225 size_t len = strlen(temp);
220 temp[len-1]='\0'; 226 temp[len-1]='\0';
221 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this 227 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this
222 new_lines(msg); 228 new_lines(msg);