From c86561f6257fd865590caacb3a4ad709c848eb68 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Thu, 19 Mar 2015 11:44:26 +0100 Subject: db: fix unicode support (thanks giacomo) from the unicode-db patch readme: 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 --- sys/src/cmd/db/command.c | 6 +++--- sys/src/cmd/db/defs.h | 2 +- sys/src/cmd/db/fns.h | 2 +- sys/src/cmd/db/pcs.c | 2 +- sys/src/cmd/db/print.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/src/cmd/db/command.c b/sys/src/cmd/db/command.c index c45f306df..d855b7546 100644 --- a/sys/src/cmd/db/command.c +++ b/sys/src/cmd/db/command.c @@ -23,8 +23,8 @@ WORD adrval, cntval, loopcnt; int adrflg, cntflg; /* command decoding */ - -command(char *buf, int defcom) +int +command(Rune *buf, int defcom) { char *reg; char savc; @@ -39,7 +39,7 @@ command(char *buf, int defcom) if (*buf==EOR) return(FALSE); clrinp(); - lp=(Rune*)buf; + lp=buf; } do { adrflg=expr(0); /* first address */ diff --git a/sys/src/cmd/db/defs.h b/sys/src/cmd/db/defs.h index 5a12ba4cc..c68aaa196 100644 --- a/sys/src/cmd/db/defs.h +++ b/sys/src/cmd/db/defs.h @@ -64,7 +64,7 @@ struct bkpt { int count; int initcnt; int flag; - char comm[MAXCOM]; + Rune comm[MAXCOM]; BKPT *nxtbkpt; }; diff --git a/sys/src/cmd/db/fns.h b/sys/src/cmd/db/fns.h index 6f6b38d15..73c5dbf8d 100644 --- a/sys/src/cmd/db/fns.h +++ b/sys/src/cmd/db/fns.h @@ -8,7 +8,7 @@ void clrinp(void); 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); diff --git a/sys/src/cmd/db/pcs.c b/sys/src/cmd/db/pcs.c index de002430a..1b0ee32a7 100644 --- a/sys/src/cmd/db/pcs.c +++ b/sys/src/cmd/db/pcs.c @@ -20,7 +20,7 @@ subpcs(int modif) int n, r; long line, curr; BKPT *bk; - char *comptr; + Rune *comptr; runmode=SINGLE; r = 0; diff --git a/sys/src/cmd/db/print.c b/sys/src/cmd/db/print.c index cb7938274..3c04edab6 100644 --- a/sys/src/cmd/db/print.c +++ b/sys/src/cmd/db/print.c @@ -166,7 +166,7 @@ printtrace(int modif) 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; -- cgit v1.2.3