- if (rs->hist_entry == READLINE_MAX_CMDS - 1 || rs->hist_entry == -1)
- return;
- if (rs->history[++rs->hist_entry] != NULL) {
+ if (rs->hist_entry == -1)
+ return;
+ if (rs->hist_entry < READLINE_MAX_CMDS - 1 &&
+ rs->history[++rs->hist_entry] != NULL) {