Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Manually truncate long game window names #248

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Manually truncate long game window names
Doing this explicitly instead of relying on snprintf
gets rid of a compiler warning
JFreegman committed Dec 30, 2023
commit 66ebe1030d23acfffaa1e373671934e3ef65ac5d
12 changes: 11 additions & 1 deletion src/game_base.c
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
*
*/

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -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);
}