Skip to content

Commit

Permalink
Manually truncate long game window names
Browse files Browse the repository at this point in the history
Doing this explicitly instead of relying on snprintf
gets rid of a compiler warning
  • Loading branch information
JFreegman committed Dec 24, 2023
1 parent ed8b401 commit 7822797
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/game_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -918,7 +919,16 @@ static ToxWindow *game_new_window(Tox *m, GameType type, uint32_t friendnumber)
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, friendnumber);

snprintf(ret->name, sizeof(ret->name), "%s (%s)", window_name, nick);
char buf[sizeof(nick) + sizeof(ret->name) + 4];
snprintf(buf, sizeof(buf), "%s (%s)", window_name, nick);

const size_t name_size = sizeof(ret->name);

assert(name_size != 0 && name_size <= sizeof(buf));

buf[name_size - 1] = '\0';

snprintf(ret->name, name_size, "%s", buf);
} else {
snprintf(ret->name, sizeof(ret->name), "%s", window_name);
}
Expand Down

0 comments on commit 7822797

Please sign in to comment.