1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Dynamic memory allocation on get chat recipient

This commit is contained in:
James Booth 2012-02-19 20:57:46 +00:00
parent 35d224a221
commit b3f42cd300
3 changed files with 9 additions and 5 deletions

View File

@ -1,4 +1,5 @@
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <ncurses.h> #include <ncurses.h>
#include "command.h" #include "command.h"
#include "jabber.h" #include "jabber.h"
@ -176,7 +177,7 @@ static int _cmd_msg(char *inp)
char *msg = NULL; char *msg = NULL;
// copy input // copy input
char inp_cpy[100]; char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp); strcpy(inp_cpy, inp);
// get user // get user
@ -211,10 +212,10 @@ static int _cmd_close(char *inp)
static int _cmd_default(char *inp) static int _cmd_default(char *inp)
{ {
if (win_in_chat()) { if (win_in_chat()) {
char recipient[100] = ""; char *recipient = win_get_recipient();
win_get_recipient(recipient);
jabber_send(inp, recipient); jabber_send(inp, recipient);
win_show_outgoing_msg("me", recipient, inp); win_show_outgoing_msg("me", recipient, inp);
free(recipient);
} else { } else {
cons_bad_command(inp); cons_bad_command(inp);
} }

View File

@ -1,4 +1,5 @@
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <ncurses.h> #include <ncurses.h>
#include "windows.h" #include "windows.h"
#include "util.h" #include "util.h"
@ -86,9 +87,11 @@ int win_in_chat(void)
return ((_curr_win != 0) && (strcmp(_wins[_curr_win].from, "") != 0)); 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); strcpy(recipient, _wins[_curr_win].from);
return recipient;
} }
void win_show_incomming_msg(char *from, char *message) void win_show_incomming_msg(char *from, char *message)

View File

@ -30,7 +30,7 @@ int win_is_active(int i);
void win_switch_to(int i); void win_switch_to(int i);
void win_close_win(void); void win_close_win(void);
int win_in_chat(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_incomming_msg(char *from, char *message);
void win_show_outgoing_msg(char *from, char *to, char *message); void win_show_outgoing_msg(char *from, char *to, char *message);