scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit a9645b102283223091826bff01b2441fb8514e41
parent 1448724dc8d932cb954e2910639106ee0b3f1406
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 30 Mar 2026 13:59:20 -0700

as: Use unsigned char for instruction buffers

`char` and `unsigned char` are not compatible types (on many systems),
so it is not legal to pass a `unsigned char *` to a function expecting
`char *` without an explicit cast.

These char arrays are often constructed from a multi-byte integer
(for example, tobytes()), relying on implementation-defined
conversions, so just use unsigned char to avoid this.

Diffstat:
Msrc/cmd/scc-as/as.h | 4++--
Msrc/cmd/scc-as/ins.c | 8++++----
Msrc/cmd/scc-as/ppc/ins.c | 2+-
Msrc/cmd/scc-as/symbol.c | 2+-
Msrc/cmd/scc-as/x86/ins.c | 8++++----
5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/cmd/scc-as/as.h b/src/cmd/scc-as/as.h @@ -100,7 +100,7 @@ union yylval { /* symbol.c */ void cleansecs(void); void ibinfmt(void); -void emit(char *, int); +void emit(unsigned char *, int); Section *defsec(char *, char *); Symbol *tmpsym(unsigned long long); void killtmp(void); @@ -139,7 +139,7 @@ int match(Op *, Node **); Node *moperand(void); /* ins.c */ -char *tobytes(unsigned long long, int, int); +unsigned char *tobytes(unsigned long long, int, int); /* binfmt.c */ void writeout(char *); diff --git a/src/cmd/scc-as/ins.c b/src/cmd/scc-as/ins.c @@ -25,10 +25,10 @@ reloc(Symbol *sym, { } -char * +unsigned char * tobytes(unsigned long long v, int nbytes, int inc) { - static char buf[sizeof(unsigned long long)]; + static unsigned char buf[sizeof(unsigned long long)]; int idx; idx = (inc < 0) ? nbytes-1 : 0; @@ -60,7 +60,7 @@ xstring(int which, Node **args) s = np->sym->name; len = strlen(s); len += which == XSTRING; - emit(s, len); + emit((unsigned char *)s, len); } } @@ -242,7 +242,7 @@ align(Op *op, Node **args) pcal = pc+al & ~al; for (al = pcal - pc; al > 0; --al) - emit((char []) {0}, 1); + emit((unsigned char []) {0}, 1); } void diff --git a/src/cmd/scc-as/ppc/ins.c b/src/cmd/scc-as/ppc/ins.c @@ -123,7 +123,7 @@ moperand(void) static void emit_packed(unsigned long ins) { - char buff[4]; + unsigned char buff[4]; if (endian == BIG_ENDIAN) { buff[0] = ins >> 24; diff --git a/src/cmd/scc-as/symbol.c b/src/cmd/scc-as/symbol.c @@ -417,7 +417,7 @@ cleansecs(void) } void -emit(char *bytes, int n) +emit(unsigned char *bytes, int n) { struct lsection *lsec = (struct lsection *) cursec; diff --git a/src/cmd/scc-as/x86/ins.c b/src/cmd/scc-as/x86/ins.c @@ -302,7 +302,7 @@ void reg8_reg8(Op *op, Node **args) { int src, dst; - char buf[op->size]; + unsigned char buf[op->size]; src = reg8toint(args[0]); dst = reg8toint(args[1]); @@ -315,7 +315,7 @@ void imm8_reg8(Op *op, Node **args) { int src, dst; - char buf[op->size]; + unsigned char buf[op->size]; src = (*args)->sym->value; dst = reg8toint(args[1]); @@ -330,7 +330,7 @@ void reg16_reg16(Op *op, Node **args) { int src, dst; - char buf[op->size]; + unsigned char buf[op->size]; src = reg16toint(args[0]); dst = reg16toint(args[1]); @@ -344,7 +344,7 @@ void reg32_reg32(Op *op, Node **args) { int src, dst; - char buf[op->size]; + unsigned char buf[op->size]; src = reg32toint(args[0]); dst = reg32toint(args[1]);