We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 407ef92 commit bf12191Copy full SHA for bf12191
kirc.c
@@ -58,20 +58,17 @@ kbhit(void) {
58
}
59
60
/* handle keyboard strokes for command input */
61
-static char *
62
-input_handler() {
+static void
+input_handler(char *usrin, int len) {
63
64
- char *usrin = malloc(sizeof(char) * (IRC_MSG_MAX + 1));
65
struct termios tp, save;
66
67
tcgetattr(STDIN_FILENO, &tp);
68
save = tp;
69
tp.c_cc[VERASE] = 127;
70
tcsetattr(STDIN_FILENO, TCSANOW, &tp);
71
- fgets(usrin, IRC_MSG_MAX, stdin);
+ fgets(usrin, len, stdin);
72
tcsetattr(STDIN_FILENO, TCSANOW, &save);
73
-
74
- return usrin;
75
76
77
/* send command to irc server */
@@ -235,7 +232,7 @@ main(int argc, char **argv) {
235
232
while (waitpid(pid, NULL, WNOHANG) == 0) {
236
233
if (!kbhit()) dprintf(fd[1], ":\n");
237
234
else {
238
- strcpy(usrin, input_handler());
+ input_handler(usrin, IRC_MSG_MAX);
239
240
if (sscanf(usrin, ":%[M] %s %[^\n]\n", &c1, v2, v1) == 3 ||
241
sscanf(usrin, ":%[Qnjpm] %[^\n]\n", &c1, v1) == 2 ||
0 commit comments