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
1108 switch (*cmd) {1108 switch (*cmd) {
1109 case CTRL_P:1109 case CTRL_P:
1110 if (cmdptr != cmd_tail)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 strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);1113 strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
1113 return 1;1114 return 1;
1114 case CTRL_N:1115 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