main_edit.c: Do not reference beyond end of array

This commit is contained in:
Joel Sherrill
2014-11-24 13:54:26 -06:00
parent d15202490c
commit 3bd0cd1ad5

View File

@@ -815,6 +815,11 @@ static int getachar(void)
#if KEY_HISTORY
if (key_history_in < sizeof(key_history)) {
key_history[key_history_in++] = ch;
#if defined(__rtems__)
} if (key_history_in > sizeof(key_history)) {
/* eliminate possibility of using index above array bounds */
assert( key_history_in > sizeof(key_history));
#endif
} else {
memmove(&key_history[0], &key_history[1], sizeof(key_history) - sizeof(key_history[0]));
key_history[key_history_in - 1] = ch;