From c3d2ff6bfbaa98d19aa0b35abee4b0e35e827a6f Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 11 Feb 2014 19:12:26 -0500 Subject: [PATCH] couple fixes --- src/chat.c | 3 ++- src/chat_commands.c | 3 ++- src/misc_tools.c | 6 +++--- src/misc_tools.h | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/chat.c b/src/chat.c index 8077b10..efec9fa 100644 --- a/src/chat.c +++ b/src/chat.c @@ -136,7 +136,8 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil ChatContext *ctx = self->chatwin; - uint8_t *filename = get_file_name(pathname); + uint8_t filename[MAX_STR_SIZE]; + get_file_name(pathname, filename); wprintw(ctx->history, "File transfer request for '%s' (%llu bytes).\n", filename, (long long unsigned int)filesize); diff --git a/src/chat_commands.c b/src/chat_commands.c index 32dedde..8a9505a 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -164,7 +164,8 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv uint64_t filesize = ftell(file_to_send); fseek(file_to_send, 0, SEEK_SET); - uint8_t *filename = get_file_name(path); + uint8_t filename[MAX_STR_SIZE]; + get_file_name(path, filename); int filenum = tox_new_file_sender(m, self->num, filesize, filename, strlen(filename) + 1); if (filenum == -1) { diff --git a/src/misc_tools.c b/src/misc_tools.c index d3669b6..395a25b 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -194,8 +194,8 @@ void mv_curs_end(WINDOW *w, size_t len, int max_y, int max_x) wmove(w, end_y, end_x); } -/* Returns base file name from path or original file name if no path is supplied */ -uint8_t *get_file_name(uint8_t *pathname) +/* gets base file name from path or original file name if no path is supplied */ +void get_file_name(uint8_t *pathname, uint8_t *namebuf) { int idx = strlen(pathname) - 1; @@ -214,5 +214,5 @@ uint8_t *get_file_name(uint8_t *pathname) filename = pathname; } - return filename; + snprintf(namebuf, MAX_STR_SIZE, "%s", filename); } diff --git a/src/misc_tools.h b/src/misc_tools.h index 1aa6c48..5e3d5d0 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -48,5 +48,5 @@ bool valid_nick(uint8_t *nick); /* Moves the cursor to the end of the line in given window */ void mv_curs_end(WINDOW *w, size_t len, int max_y, int max_x); -/* Returns base file name from path or original file name if no path is supplied */ -uint8_t *get_file_name(uint8_t *pathname); +/* gets base file name from path or original file name if no path is supplied */ +void get_file_name(uint8_t *pathname, uint8_t *buf);