astyled everything.

This commit is contained in:
irungentoo 2013-09-17 16:28:39 -04:00
parent dd12d464de
commit 5a83c1296c
12 changed files with 184 additions and 168 deletions

View File

@ -239,12 +239,14 @@ START_TEST(test_dht_state_saveloadsave)
memset(buffer, 0xCD, extra);
memset(buffer + extra + size, 0xCD, extra);
DHT_save(m->dht, buffer + extra);
for (i = 0; i < extra; i++) {
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", i);
}
int res = DHT_load_new(m->dht, buffer + extra, size);
if (res == -1)
ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
else {
@ -279,12 +281,14 @@ START_TEST(test_messenger_state_saveloadsave)
memset(buffer, 0xCD, extra);
memset(buffer + extra + size, 0xCD, extra);
Messenger_save(m, buffer + extra);
for (i = 0; i < extra; i++) {
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from Messenger_save() @%u", i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from Messenger_save() @%u", i);
}
int res = Messenger_load(m, buffer + extra, size);
if (res == -1)
ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
else {

View File

@ -137,6 +137,7 @@ void get_id(Tox *m, char *data)
tox_getaddress(m, address);
uint32_t i = 0;
for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
sprintf(data + 2 * i + offset, "%02X ", address[i]);
}
@ -257,9 +258,9 @@ void line_eval(Tox *m, char *line)
if (num >= 0) {
sprintf(numstring, "[i] Added friend as %d.", num);
save_data(m);
}
else
} else
sprintf(numstring, "[i] Unknown error %i.", num);
break;
}
@ -508,12 +509,14 @@ static int load_data(Tox *m)
{
FILE *data_file = fopen(data_file_name, "r");
size_t size = 0;
if (data_file) {
fseek(data_file, 0, SEEK_END);
size = ftell(data_file);
rewind(data_file);
uint8_t data[size];
if (fread(data, sizeof(uint8_t), size, data_file) != size) {
fputs("[!] could not read data file!\n", stderr);
fclose(data_file);
@ -537,6 +540,7 @@ static int load_data(Tox *m)
static int save_data(Tox *m)
{
FILE *data_file = fopen(data_file_name, "w");
if (!data_file) {
perror("[!] load_key");
return 0;
@ -563,6 +567,7 @@ static int save_data(Tox *m)
static int load_data_or_init(Tox *m, char *path)
{
data_file_name = path;
if (load_data(m))
return 1;
@ -671,6 +676,7 @@ int main(int argc, char *argv[])
new_lines("[i] change username with /n");
uint8_t name[TOX_MAX_NAME_LENGTH];
uint16_t namelen = tox_getselfname(m, name, sizeof(name));
if (namelen > 0) {
char whoami[128 + TOX_MAX_NAME_LENGTH];
snprintf(whoami, sizeof(whoami), "[i] your current username is: %s", name);

View File

@ -1579,6 +1579,7 @@ void DHT_save(DHT *dht, uint8_t *data)
len = num * sizeof(Client_data);
type = DHT_STATE_TYPE_CLIENTS;
data = z_state_save_subheader(data, len, type);
if (num) {
Client_data *clients = (Client_data *)data;
@ -1586,6 +1587,7 @@ void DHT_save(DHT *dht, uint8_t *data)
if (dht->close_clientlist[i].timestamp != 0)
memcpy(&clients[num++], &dht->close_clientlist[i], sizeof(Client_data));
}
data += len;
}

View File

@ -802,6 +802,7 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam
if (m->chats[groupnumber] == NULL)
return -1;
return group_peername(m->chats[groupnumber], peernumber, name);
}
/* return 1 if that friend was invited to the group
@ -1609,6 +1610,7 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le
break;
#ifdef DEBUG
default:
fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n",
length, type);

View File

@ -289,10 +289,12 @@ int group_peername(Group_Chat *chat, int peernum, uint8_t *name)
{
if ((uint32_t)peernum >= chat->numpeers)
return -1;
if (chat->group[peernum].nick_len == 0) {
memcpy(name, "NSA Agent", 10); /* Kindly remind the user that someone with no name might be a NSA agent.*/
return 10;
}
memcpy(name, chat->group[peernum].nick, chat->group[peernum].nick_len);
return chat->group[peernum].nick_len;
}