diff options
-rw-r--r-- | auto_tests/messenger_test.c | 2 | ||||
-rw-r--r-- | core/Messenger.c | 12 | ||||
-rw-r--r-- | core/Messenger.h | 16 | ||||
-rw-r--r-- | testing/nTox.c | 2 | ||||
-rw-r--r-- | testing/toxic/chat.c | 2 |
5 files changed, 25 insertions, 9 deletions
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 64b44d5f..28747899 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c | |||
@@ -169,7 +169,7 @@ START_TEST(test_getself_name) | |||
169 | char nick_check[len]; | 169 | char nick_check[len]; |
170 | 170 | ||
171 | setname(m, (uint8_t *)nickname, len); | 171 | setname(m, (uint8_t *)nickname, len); |
172 | getself_name(m, (uint8_t *)nick_check); | 172 | getself_name(m, (uint8_t *)nick_check, len); |
173 | 173 | ||
174 | ck_assert_msg((!STRINGS_EQUAL(nickname, nick_check)), | 174 | ck_assert_msg((!STRINGS_EQUAL(nickname, nick_check)), |
175 | "getself_name failed to return the known name!\n" | 175 | "getself_name failed to return the known name!\n" |
diff --git a/core/Messenger.c b/core/Messenger.c index ebde5a78..1c81163c 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -267,10 +267,18 @@ int setname(Messenger *m, uint8_t * name, uint16_t length) | |||
267 | put it in name | 267 | put it in name |
268 | name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. | 268 | name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. |
269 | return the length of the name */ | 269 | return the length of the name */ |
270 | uint16_t getself_name(Messenger *m, uint8_t *name) | 270 | uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen) |
271 | { | 271 | { |
272 | uint16_t len; | ||
273 | |||
274 | if (name == NULL || nlen == 0) { | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | len = MIN(nlen, m->name_length); | ||
272 | memcpy(name, m->name, m->name_length); | 279 | memcpy(name, m->name, m->name_length); |
273 | return m->name_length; | 280 | |
281 | return len; | ||
274 | } | 282 | } |
275 | 283 | ||
276 | /* get name of friendnumber | 284 | /* get name of friendnumber |
diff --git a/core/Messenger.h b/core/Messenger.h index fa69d104..aa9611a4 100644 --- a/core/Messenger.h +++ b/core/Messenger.h | |||
@@ -196,10 +196,18 @@ int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t lengt | |||
196 | return -1 if failure */ | 196 | return -1 if failure */ |
197 | int setname(Messenger *m, uint8_t *name, uint16_t length); | 197 | int setname(Messenger *m, uint8_t *name, uint16_t length); |
198 | 198 | ||
199 | /* get our nickname | 199 | /** |
200 | put it in name | 200 | * @brief Get your nickname. |
201 | return the length of the name*/ | 201 | * |
202 | uint16_t getself_name(Messenger *m, uint8_t *name); | 202 | * @param[in] m The messanger context to use. |
203 | * | ||
204 | * @param[inout] name Pointer to a string for the name. | ||
205 | * | ||
206 | * @param[in] nlen The length of the string buffer. | ||
207 | * | ||
208 | * @return Return the length of the name, 0 on error. | ||
209 | */ | ||
210 | uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen); | ||
203 | 211 | ||
204 | /* get name of friendnumber | 212 | /* get name of friendnumber |
205 | put it in name | 213 | put it in name |
diff --git a/testing/nTox.c b/testing/nTox.c index 59d1cbf6..74db2ae2 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -113,7 +113,7 @@ char *format_message(Messenger *m, char *message, int friendnum) | |||
113 | if (friendnum != -1) { | 113 | if (friendnum != -1) { |
114 | getname(m, friendnum, (uint8_t*)name); | 114 | getname(m, friendnum, (uint8_t*)name); |
115 | } else { | 115 | } else { |
116 | getself_name(m, (uint8_t*)name); | 116 | getself_name(m, (uint8_t*)name, sizeof(name)); |
117 | } | 117 | } |
118 | char *msg = malloc(100+strlen(message)+strlen(name)+1); | 118 | char *msg = malloc(100+strlen(message)+strlen(name)+1); |
119 | 119 | ||
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 112b20b7..59b13492 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -210,7 +210,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct | |||
210 | wattroff(ctx->history, COLOR_PAIR(2)); | 210 | wattroff(ctx->history, COLOR_PAIR(2)); |
211 | 211 | ||
212 | uint8_t selfname[MAX_NAME_LENGTH]; | 212 | uint8_t selfname[MAX_NAME_LENGTH]; |
213 | int len = getself_name(m, selfname); | 213 | int len = getself_name(m, selfname, sizeof(selfname)); |
214 | char msg[MAX_STR_SIZE-len-4]; | 214 | char msg[MAX_STR_SIZE-len-4]; |
215 | snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); | 215 | snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); |
216 | 216 | ||