this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix tab-completion bug with load/save/etc. (#2533)

authored by

Alice and committed by
GitHub
23998c76 712be942

+12 -2
+12 -2
src/studio/screens/console.c
··· 1186 1186 { 1187 1187 // This is the first option to be added. Initialize the prefix. 1188 1188 strncpy(data->commonPrefix, option, CONSOLE_BUFFER_SCREEN); 1189 + // strncpy does not null-terminate if the source string is too long so 1190 + // null terminate in the end just to be sure 1191 + data->commonPrefix[CONSOLE_BUFFER_SCREEN - 1] = 0; 1189 1192 } 1190 1193 else 1191 1194 { ··· 1202 1205 } 1203 1206 1204 1207 // The option matches the incomplete word, add it to the list. 1205 - strncat(data->options, option, CONSOLE_BUFFER_SCREEN); 1206 - strncat(data->options, " ", CONSOLE_BUFFER_SCREEN); 1208 + // the last parameter of strcat is the maximum number of characters to be 1209 + // copied, and it adds a null terminator in the end. data->options having 1210 + // capacity CONSOLE_BUFFER_SCREEN, we can append CONSOLE_BUFFER_SCREEN - 1211 + // strlen(data->options) - 1 characters to its end at most 1212 + strncat(data->options, option, CONSOLE_BUFFER_SCREEN - strlen(data->options) - 1); 1213 + strncat(data->options, " ", CONSOLE_BUFFER_SCREEN - strlen(data->options) - 1); 1207 1214 } 1208 1215 } 1209 1216 ··· 1212 1219 { 1213 1220 char* input = malloc(CONSOLE_BUFFER_SCREEN); 1214 1221 strncpy(input, console->input.text, CONSOLE_BUFFER_SCREEN); 1222 + // strncpy does not null-terminate if the source string is too long so 1223 + // null terminate in the end just to be sure 1224 + input[CONSOLE_BUFFER_SCREEN - 1] = 0; 1215 1225 1216 1226 printLine(console); 1217 1227 printBack(console, hint);