History

kdb: Cleanup math with KDB_CMD_HISTORY_COUNT

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.

Douglas Anderson committed 6 years ago

Commit 1b310031 parent 195867f1 file · +2 −1Browse files

Showing the changes to kernel/debug (1 of 1 file). Show all

Unified · Split

kernel/debug/kdb/kdb_main.c+2−1
@@ -1108,7 +1108,8 @@ static int handle_ctrl_cmd(char *cmd) · 1107 unmodified lines
11081108 switch (*cmd) {
11091109 case CTRL_P:
11101110 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;
11121113 strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
11131114 return 1;
11141115 case CTRL_N:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t