data: simplify and validate Japanese imports
This commit is contained in:
18
dict.c
18
dict.c
@@ -63,7 +63,7 @@ dictopen(char *path)
|
||||
Hmap *h;
|
||||
Biobuf *b;
|
||||
Str key;
|
||||
char *line, *tab;
|
||||
char *line, *tab, *p, *e;
|
||||
int len, lineno;
|
||||
|
||||
b = Bopen(path, OREAD);
|
||||
@@ -81,13 +81,21 @@ dictopen(char *path)
|
||||
continue;
|
||||
}
|
||||
tab = strchr(line, '\t');
|
||||
if(tab == nil || tab >= line + len - 1){
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
if(tab == nil || tab == line || tab >= line + len - 1 ||
|
||||
strchr(tab+1, '\t') != nil)
|
||||
die("malformed dictionary: %s:%d", path, lineno);
|
||||
*tab = '\0';
|
||||
if(utflen(line) > Maxrunes)
|
||||
die("dictionary key too long: %s:%d", path, lineno);
|
||||
for(p = tab+1; p < line+len; p = e+1){
|
||||
e = memchr(p, ' ', line+len-p);
|
||||
if(e == nil)
|
||||
e = line+len;
|
||||
if(utfnlen(p, e-p) > Maxrunes)
|
||||
die("dictionary candidate too long: %s:%d", path, lineno);
|
||||
if(e == line+len)
|
||||
break;
|
||||
}
|
||||
sinit(&key, line, tab - line);
|
||||
hmapset(&h, &key, tab+1, len - (tab - line) - 1);
|
||||
free(line);
|
||||
|
||||
Reference in New Issue
Block a user