handle arbitrary length names in subfontname.
handle overflow in offset computation in font.c
This commit is contained in:
parent
e354760aca
commit
d4aef6a074
2 changed files with 18 additions and 12 deletions
|
|
@ -177,7 +177,7 @@ int
|
||||||
loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
|
loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
|
||||||
{
|
{
|
||||||
int i, oi, wid, top, bottom;
|
int i, oi, wid, top, bottom;
|
||||||
Rune pic;
|
int pic; /* need >16 bits for adding offset below */
|
||||||
Fontchar *fi;
|
Fontchar *fi;
|
||||||
Cachefont *cf;
|
Cachefont *cf;
|
||||||
Cachesubf *subf, *of;
|
Cachesubf *subf, *of;
|
||||||
|
|
@ -270,10 +270,12 @@ loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
|
||||||
Found2:
|
Found2:
|
||||||
subf->age = f->age;
|
subf->age = f->age;
|
||||||
|
|
||||||
|
/* possible overflow here, but works out okay */
|
||||||
pic += cf->offset;
|
pic += cf->offset;
|
||||||
if(pic-cf->min >= subf->f->n)
|
pic -= cf->min;
|
||||||
|
if(pic >= subf->f->n)
|
||||||
goto TryPJW;
|
goto TryPJW;
|
||||||
fi = &subf->f->info[pic - cf->min];
|
fi = &subf->f->info[pic];
|
||||||
if(fi->width == 0)
|
if(fi->width == 0)
|
||||||
goto TryPJW;
|
goto TryPJW;
|
||||||
wid = (fi+1)->x - fi->x;
|
wid = (fi+1)->x - fi->x;
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,22 @@
|
||||||
char*
|
char*
|
||||||
subfontname(char *cfname, char *fname, int maxdepth)
|
subfontname(char *cfname, char *fname, int maxdepth)
|
||||||
{
|
{
|
||||||
char *t, *u, tmp1[64], tmp2[64];
|
char *t, *u, *tmp1, *tmp2;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
t = strdup(cfname); /* t is the return string */
|
||||||
if(strcmp(cfname, "*default*") == 0)
|
if(strcmp(cfname, "*default*") == 0)
|
||||||
return strdup(cfname);
|
return t;
|
||||||
t = cfname;
|
|
||||||
if(t[0] != '/'){
|
if(t[0] != '/'){
|
||||||
snprint(tmp2, sizeof tmp2, "%s", fname);
|
tmp2 = strdup(fname);
|
||||||
u = utfrrune(tmp2, '/');
|
u = utfrrune(tmp2, '/');
|
||||||
if(u)
|
if(u)
|
||||||
u[0] = 0;
|
u[0] = 0;
|
||||||
else
|
else
|
||||||
strcpy(tmp2, ".");
|
strcpy(tmp2, ".");
|
||||||
snprint(tmp1, sizeof tmp1, "%s/%s", tmp2, t);
|
tmp1 = smprint("%s/%s", tmp2, t);
|
||||||
|
free(tmp2);
|
||||||
|
free(t);
|
||||||
t = tmp1;
|
t = tmp1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,14 +35,16 @@ subfontname(char *cfname, char *fname, int maxdepth)
|
||||||
if((1<<i) > maxdepth)
|
if((1<<i) > maxdepth)
|
||||||
continue;
|
continue;
|
||||||
/* try i-bit grey */
|
/* try i-bit grey */
|
||||||
snprint(tmp2, sizeof tmp2, "%s.%d", t, i);
|
tmp2 = smprint("%s.%d", t, i);
|
||||||
if(access(tmp2, AREAD) == 0)
|
if(access(tmp2, AREAD) == 0) {
|
||||||
return strdup(tmp2);
|
free(t);
|
||||||
|
return tmp2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try default */
|
/* try default */
|
||||||
if(access(t, AREAD) == 0)
|
if(access(t, AREAD) == 0)
|
||||||
return strdup(t);
|
return t;
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue