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;
buffer[i] = '\0';
output = strcpy(ecalloc(i, sizeof(*output)), buffer);
output = strncpy(ecalloc(i, sizeof(char)), buffer, i*sizeof(char));
return output;
}
@ -579,7 +579,8 @@ void on_stdin(void) {
while (1) {
char *buffer = get_line(STDIN_FILENO);
if (!buffer || !strlen(buffer)) {
free(buffer);
if (buffer)
free(buffer);
return;
}