···11861186 {
11871187 // This is the first option to be added. Initialize the prefix.
11881188 strncpy(data->commonPrefix, option, CONSOLE_BUFFER_SCREEN);
11891189+ // strncpy does not null-terminate if the source string is too long so
11901190+ // null terminate in the end just to be sure
11911191+ data->commonPrefix[CONSOLE_BUFFER_SCREEN - 1] = 0;
11891192 }
11901193 else
11911194 {
···12021205 }
1203120612041207 // The option matches the incomplete word, add it to the list.
12051205- strncat(data->options, option, CONSOLE_BUFFER_SCREEN);
12061206- strncat(data->options, " ", CONSOLE_BUFFER_SCREEN);
12081208+ // the last parameter of strcat is the maximum number of characters to be
12091209+ // copied, and it adds a null terminator in the end. data->options having
12101210+ // capacity CONSOLE_BUFFER_SCREEN, we can append CONSOLE_BUFFER_SCREEN -
12111211+ // strlen(data->options) - 1 characters to its end at most
12121212+ strncat(data->options, option, CONSOLE_BUFFER_SCREEN - strlen(data->options) - 1);
12131213+ strncat(data->options, " ", CONSOLE_BUFFER_SCREEN - strlen(data->options) - 1);
12071214 }
12081215}
12091216···12121219{
12131220 char* input = malloc(CONSOLE_BUFFER_SCREEN);
12141221 strncpy(input, console->input.text, CONSOLE_BUFFER_SCREEN);
12221222+ // strncpy does not null-terminate if the source string is too long so
12231223+ // null terminate in the end just to be sure
12241224+ input[CONSOLE_BUFFER_SCREEN - 1] = 0;
1215122512161226 printLine(console);
12171227 printBack(console, hint);