mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #112 from KostyaKow/master
took out several strlen() calls out of the loop; replaced int's with siz...
This commit is contained in:
commit
85b2db2ad2
|
@ -41,12 +41,14 @@
|
|||
|
||||
#define PORT 33445
|
||||
|
||||
//TODO: rewrite
|
||||
unsigned char * hex_string_to_bin(char hex_string[])
|
||||
{
|
||||
unsigned char * val = malloc(strlen(hex_string));
|
||||
size_t len = strlen(hex_string);
|
||||
unsigned char * val = malloc(len);
|
||||
char * pos = hex_string;
|
||||
int i=0;
|
||||
while(i < strlen(hex_string))
|
||||
while(i < len)
|
||||
{
|
||||
sscanf(pos,"%2hhx",&val[i]);
|
||||
pos+=2;
|
||||
|
@ -139,4 +141,4 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
shutdown_networking();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,14 +60,15 @@ void printip(IP_Port ip_port)
|
|||
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));
|
||||
}
|
||||
|
||||
/* horrible function from one of my first C programs.
|
||||
*only here because I was too lazy to write a proper one. */
|
||||
//TODO: rewrite
|
||||
unsigned char * hex_string_to_bin(char hex_string[])
|
||||
{
|
||||
unsigned char * val = malloc(strlen(hex_string));
|
||||
size_t len = strlen(hex_string);
|
||||
unsigned char * val = malloc(len);
|
||||
char * pos = hex_string;
|
||||
int i=0;
|
||||
while(i < strlen(hex_string)) {
|
||||
while(i < len)
|
||||
{
|
||||
sscanf(pos,"%2hhx",&val[i]);
|
||||
pos+=2;
|
||||
i++;
|
||||
|
@ -239,4 +240,4 @@ int main(int argc, char *argv[])
|
|||
|
||||
shutdown_networking();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,14 +114,15 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
|
|||
printf("\n--------------------END-----------------------------\n\n\n");
|
||||
}
|
||||
|
||||
//horrible function from one of my first C programs.
|
||||
//only here because I was too lazy to write a proper one.
|
||||
//TODO: rewrite
|
||||
unsigned char * hex_string_to_bin(char hex_string[])
|
||||
{
|
||||
unsigned char * val = malloc(strlen(hex_string));
|
||||
size_t len = strlen(hex_string);
|
||||
unsigned char * val = malloc(len);
|
||||
char * pos = hex_string;
|
||||
int i=0;
|
||||
while(i < strlen(hex_string)) {
|
||||
while(i < len)
|
||||
{
|
||||
sscanf(pos,"%2hhx",&val[i]);
|
||||
pos+=2;
|
||||
i++;
|
||||
|
@ -191,4 +192,4 @@ int main(int argc, char *argv[])
|
|||
|
||||
shutdown_networking();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,14 +50,14 @@
|
|||
|
||||
#endif
|
||||
|
||||
//horrible function from one of my first C programs.
|
||||
//only here because I was too lazy to write a proper one.
|
||||
//TODO: rewrite
|
||||
unsigned char * hex_string_to_bin(char hex_string[])
|
||||
{
|
||||
unsigned char * val = malloc(strlen(hex_string));
|
||||
size_t len = strlen(hex_string);
|
||||
unsigned char * val = malloc(len);
|
||||
char * pos = hex_string;
|
||||
int i=0;
|
||||
while(i < strlen(hex_string))
|
||||
while(i < len)
|
||||
{
|
||||
sscanf(pos,"%2hhx",&val[i]);
|
||||
pos+=2;
|
||||
|
|
|
@ -46,12 +46,15 @@ void new_lines(char *line)
|
|||
do_refresh();
|
||||
}
|
||||
|
||||
//TODO: rewrite
|
||||
unsigned char * hex_string_to_bin(char hex_string[])
|
||||
{
|
||||
unsigned char * val = malloc(strlen(hex_string));
|
||||
size_t len = strlen(hex_string);
|
||||
unsigned char * val = malloc(len);
|
||||
char * pos = hex_string;
|
||||
int i=0;
|
||||
while(i < strlen(hex_string)) {
|
||||
while(i < len)
|
||||
{
|
||||
sscanf(pos,"%2hhx",&val[i]);
|
||||
pos+=2;
|
||||
i++;
|
||||
|
@ -80,7 +83,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
|||
doMessenger();
|
||||
} else if (line[1] == 'm') { //message command: /m friendnumber messsage
|
||||
int i;
|
||||
int len = strlen(line);
|
||||
size_t len = strlen(line);
|
||||
char numstring[len-3];
|
||||
char message[len-3];
|
||||
for (i=0; i<len; i++) {
|
||||
|
@ -99,7 +102,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
|||
} else if (line[1] == 'n') {
|
||||
uint8_t name[MAX_NAME_LENGTH];
|
||||
int i = 0;
|
||||
for (i=3; i<strlen(line); i++) {
|
||||
size_t len = strlen(line);
|
||||
for (i=3; i<len; i++) {
|
||||
if (line[i] == 0 || line[i] == '\n') break;
|
||||
name[i - 3] = line[i];
|
||||
}
|
||||
|
@ -111,7 +115,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
|||
} else if (line[1] == 's') {
|
||||
uint8_t status[MAX_USERSTATUS_LENGTH];
|
||||
int i = 0;
|
||||
for (i=3; i<strlen(line); i++) {
|
||||
size_t len = strlen(line);
|
||||
for (i=3; i<len; i++) {
|
||||
if (line[i] == 0 || line[i] == '\n') break;
|
||||
status[i - 3] = line[i];
|
||||
}
|
||||
|
@ -133,7 +138,8 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
|
|||
{
|
||||
int i = 0;
|
||||
strcpy(output,input);
|
||||
for (i=line_width; i < strlen(output); i = i + line_width) {
|
||||
size_t len = strlen(output);
|
||||
for (i=line_width; i < len; i = i + line_width) {
|
||||
while (output[i] != ' ' && i != 0) {
|
||||
i--;
|
||||
}
|
||||
|
@ -145,7 +151,7 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
|
|||
|
||||
int count_lines(char *string)
|
||||
{
|
||||
int len = strlen(string);
|
||||
size_t len = strlen(string);
|
||||
int i;
|
||||
int count = 1;
|
||||
for (i=0; i < len; i++) {
|
||||
|
@ -158,7 +164,7 @@ int count_lines(char *string)
|
|||
|
||||
char *appender(char *str, const char c)
|
||||
{
|
||||
int len = strlen(str);
|
||||
size_t len = strlen(str);
|
||||
if (len < STRING_LENGTH) {
|
||||
str[len + 1] = str[len];
|
||||
str[len] = c;
|
||||
|
@ -216,7 +222,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
|||
time ( &rawtime );
|
||||
timeinfo = localtime ( &rawtime );
|
||||
char* temp = asctime(timeinfo);
|
||||
int len = strlen(temp);
|
||||
size_t len = strlen(temp);
|
||||
temp[len-1]='\0';
|
||||
sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this
|
||||
new_lines(msg);
|
||||
|
|
Loading…
Reference in New Issue
Block a user