commit c7ef523
Devine Lu Linvega
·
2024-02-26 01:21:30 +0000 UTC
parent a55b07e
Disallow runic labels
1 files changed,
+13,
-0
+13,
-0
1@@ -55,6 +55,8 @@ static char ops[][4] = {
2 "ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"
3 };
4
5+static char *runes = "|$@&,_.-;=!?#\"%~";
6+
7 static int scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i]) if(!a[i] || ++i >= len) return 1; return 0; } /* string compare */
8 static int sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */
9 static int shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */
10@@ -156,6 +158,15 @@ makemacro(char *name, FILE *f)
11 return 1;
12 }
13
14+static int
15+isrune(char c)
16+{
17+ char cc, *r = runes;
18+ while((cc = *r++))
19+ if(c == cc) return 1;
20+ return 0;
21+}
22+
23 static int
24 makelabel(char *name)
25 {
26@@ -166,6 +177,8 @@ makelabel(char *name)
27 return error("Label name is hex number", name);
28 if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name))
29 return error("Label name is invalid", name);
30+ if(isrune(name[0]))
31+ return error("Label name is runic", name);
32 if(p.label_len == 0x400)
33 return error("Labels limit exceeded", name);
34 l = &p.labels[p.label_len++];