Fix unicode support in db(1).
command() receives a char* that is assigned to lp, which is a Rune*,
and lp is incremented later in readchar(), so each read consumed 4 bytes.
The only time command() is called is in runpcs() with bkpt->comm,
which is a char* built in subpcs through a char*, so the string stored in
bkpt->comm was not a Rune string. A way to test the bug is:
db program
main:b argv/X
:r
Reference: /n/sources/patch/unicode-db
Date: Thu Mar 19 07:23:13 CET 2015
Signed-off-by:
k0...@shike2.com
--- /sys/src/cmd/db/command.c Thu Mar 19 07:06:13 2015
+++ /sys/src/cmd/db/command.c Thu Mar 19 07:06:09 2015
@@ -24,7 +24,7 @@
/* command decoding */
-command(char *buf, int defcom)
+command(Rune *buf, int defcom)
{
char *reg;
char savc;
@@ -39,7 +39,7 @@
if (*buf==EOR)
return(FALSE);
clrinp();
- lp=(Rune*)buf;
+ lp=buf;
}
do {
adrflg=expr(0); /* first address */
--- /sys/src/cmd/db/defs.h Thu Mar 19 07:06:19 2015
+++ /sys/src/cmd/db/defs.h Thu Mar 19 07:06:16 2015
@@ -64,7 +64,7 @@
int count;
int initcnt;
int flag;
- char comm[MAXCOM];
+ Rune comm[MAXCOM];
BKPT *nxtbkpt;
};
--- /sys/src/cmd/db/fns.h Thu Mar 19 07:06:26 2015
+++ /sys/src/cmd/db/fns.h Thu Mar 19 07:06:22 2015
@@ -8,7 +8,7 @@
void cmdmap(Map*);
void cmdsrc(int, Map*);
void cmdwrite(int, Map*);
-int command(char*, int);
+int command(Rune*, int);
int convdig(int);
void ctrace(int);
WORD defval(WORD);
--- /sys/src/cmd/db/pcs.c Thu Mar 19 07:06:32 2015
+++ /sys/src/cmd/db/pcs.c Thu Mar 19 07:06:28 2015
@@ -20,7 +20,7 @@
int n, r;
long line, curr;
BKPT *bk;
- char *comptr;
+ Rune *comptr;
runmode=SINGLE;
r = 0;
--- /sys/src/cmd/db/print.c Thu Mar 19 07:06:39 2015
+++ /sys/src/cmd/db/print.c Thu Mar 19 07:06:35 2015
@@ -166,7 +166,7 @@
dprint(buf);
if (bk->count != 1)
dprint(",%d", bk->count);
- dprint(":%c %s", bk->flag == BKPTTMP ? 'B' : 'b', bk->comm);
+ dprint(":%c %S", bk->flag == BKPTTMP ? 'B' : 'b', bk->comm);
}
break;