From code inspection the math in handle_ctrl_cmd() looks super sketchy because it subjects -1 from cmdptr and then does a "% KDB_CMD_HISTORY_COUNT". It turns out that this code works because "cmdptr" is unsigned and KDB_CMD_HISTORY_COUNT is a nice power of 2. Let's make this a little less sketchy. This patch should be a no-op.
Showing the changes to kernel/debug (1 of 1 file). Show all
Unified · Split
| @@ -1108,7 +1108,8 @@ static int handle_ctrl_cmd(char *cmd) · 1107 unmodified lines | ||
| 1108 | 1108 | switch (*cmd) { |
| 1109 | 1109 | case CTRL_P: |
| 1110 | 1110 | if (cmdptr != cmd_tail) |
| 1111 | − cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT; | |
| 1111 | + cmdptr = (cmdptr + KDB_CMD_HISTORY_COUNT - 1) % | |
| 1112 | + KDB_CMD_HISTORY_COUNT; | |
| 1112 | 1113 | strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); |
| 1113 | 1114 | return 1; |
| 1114 | 1115 | case CTRL_N: |