diff options
author | James Booth <boothj5@gmail.com> | 2012-02-19 20:57:46 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-02-19 20:57:46 +0000 |
commit | b3f42cd300e703e4d411ed03cef138462ff34fbf (patch) | |
tree | 2e3a5c85c13ea4f0ecc72622c68fa3152045011e | |
parent | 35d224a2219f8acb9907825bca140e7400b63ba3 (diff) | |
download | profani-tty-b3f42cd300e703e4d411ed03cef138462ff34fbf.tar.gz |
Dynamic memory allocation on get chat recipient
-rw-r--r-- | command.c | 7 | ||||
-rw-r--r-- | windows.c | 5 | ||||
-rw-r--r-- | windows.h | 2 |
3 files changed, 9 insertions, 5 deletions
diff --git a/command.c b/command.c index 84ac8ad5..ce1919cf 100644 --- a/command.c +++ b/command.c @@ -1,4 +1,5 @@ #include <string.h> +#include <stdlib.h> #include <ncurses.h> #include "command.h" #include "jabber.h" @@ -176,7 +177,7 @@ static int _cmd_msg(char *inp) char *msg = NULL; // copy input - char inp_cpy[100]; + char inp_cpy[strlen(inp) + 1]; strcpy(inp_cpy, inp); // get user @@ -211,10 +212,10 @@ static int _cmd_close(char *inp) static int _cmd_default(char *inp) { if (win_in_chat()) { - char recipient[100] = ""; - win_get_recipient(recipient); + char *recipient = win_get_recipient(); jabber_send(inp, recipient); win_show_outgoing_msg("me", recipient, inp); + free(recipient); } else { cons_bad_command(inp); } diff --git a/windows.c b/windows.c index 676afcb9..a1e7e8fd 100644 --- a/windows.c +++ b/windows.c @@ -1,4 +1,5 @@ #include <string.h> +#include <stdlib.h> #include <ncurses.h> #include "windows.h" #include "util.h" @@ -86,9 +87,11 @@ int win_in_chat(void) return ((_curr_win != 0) && (strcmp(_wins[_curr_win].from, "") != 0)); } -void win_get_recipient(char *recipient) +char *win_get_recipient(void) { + char *recipient = (char *) malloc(sizeof(char) * (strlen(_wins[_curr_win].from) + 1)); strcpy(recipient, _wins[_curr_win].from); + return recipient; } void win_show_incomming_msg(char *from, char *message) diff --git a/windows.h b/windows.h index a5abe763..eccccf56 100644 --- a/windows.h +++ b/windows.h @@ -30,7 +30,7 @@ int win_is_active(int i); void win_switch_to(int i); void win_close_win(void); int win_in_chat(void); -void win_get_recipient(char *recipient); +char *win_get_recipient(void); void win_show_incomming_msg(char *from, char *message); void win_show_outgoing_msg(char *from, char *to, char *message); |