Note to self: use strncpy always.

master
MadcowOG 2023-03-29 12:25:41 -07:00
parent 0a9f987d22
commit 1aae27409b
1 changed files with 3 additions and 2 deletions

View File

@ -570,7 +570,7 @@ char* get_line(int fd) {
return NULL; return NULL;
buffer[i] = '\0'; buffer[i] = '\0';
output = strcpy(ecalloc(i, sizeof(*output)), buffer); output = strncpy(ecalloc(i, sizeof(char)), buffer, i*sizeof(char));
return output; return output;
} }
@ -579,6 +579,7 @@ void on_stdin(void) {
while (1) { while (1) {
char *buffer = get_line(STDIN_FILENO); char *buffer = get_line(STDIN_FILENO);
if (!buffer || !strlen(buffer)) { if (!buffer || !strlen(buffer)) {
if (buffer)
free(buffer); free(buffer);
return; return;
} }