Skip to content

Commit 595d8c8

Browse files
committedJun 13, 2014
fix possible crash
1 parent 413f520 commit 595d8c8

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed
 

‎messages.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct messages
1010

1111
typedef struct {
1212
uint16_t flags, height, length;
13-
char_t msg[1];
13+
char_t msg[0];
1414
} MESSAGE;
1515

1616
typedef struct {

‎tox_callbacks.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ static void* copy_message(uint8_t *str, uint16_t length, uint16_t flags)
22
{
33
length = utf8_validate(str, length);
44

5-
MESSAGE *msg = malloc(length + 6);
5+
MESSAGE *msg = malloc(sizeof(MESSAGE) + length);
66
msg->flags = flags;
77
msg->length = length;
88
memcpy(msg->msg, str, length);
@@ -23,7 +23,7 @@ static void* copy_groupmessage(Tox *tox, uint8_t *str, uint16_t length, uint16_t
2323
namelen = utf8_validate(name, namelen);
2424

2525

26-
MESSAGE *msg = malloc(6 + length + namelen);
26+
MESSAGE *msg = malloc(sizeof(MESSAGE) + 1 + length + namelen);
2727
msg->flags = flags;
2828
msg->length = length;
2929
memcpy(msg->msg, str, length);
@@ -162,8 +162,8 @@ static void callback_group_namelist_change(Tox *tox, int gid, int pid, uint8_t c
162162

163163
len = utf8_validate(name, len);
164164

165-
void *data = malloc(len + 1);
166-
*(uint8_t*)data = len;
165+
uint8_t *data = malloc(len + 1);
166+
data[0] = len;
167167
memcpy(data + 1, name, len);
168168

169169
postmessage(GROUP_PEER_NAME, gid, pid, data);

0 commit comments

Comments
 (0)
Please sign in to comment.