Skip to content

Commit

Permalink
font: buffers of size GNLEN for glyph names
Browse files Browse the repository at this point in the history
  • Loading branch information
aligrudi committed Dec 19, 2020
1 parent 545147c commit 51afad2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int dev_mnt(int pos, char *id, char *name)
int dev_open(char *dir, char *dev)
{
char path[PATHLEN];
char tok[ILNLEN];
char tok[128];
int i;
FILE *desc;
snprintf(dev_dir, sizeof(dev_dir), "%s", dir);
Expand All @@ -86,7 +86,7 @@ int dev_open(char *dir, char *dev)
desc = fopen(path, "r");
if (!desc)
return 1;
while (fscanf(desc, "%s", tok) == 1) {
while (fscanf(desc, "%128s", tok) == 1) {
if (tok[0] == '#') {
skipline(desc);
continue;
Expand All @@ -99,7 +99,7 @@ int dev_open(char *dir, char *dev)
continue;
}
if (!strcmp("sizes", tok)) {
while (fscanf(desc, "%s", tok) == 1)
while (fscanf(desc, "%128s", tok) == 1)
if (!strcmp("0", tok))
break;
continue;
Expand Down
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void setcolor(int m)

void dir_fix(struct sbuf *sbuf, char *src)
{
char cmd[ILNLEN];
char cmd[1024];
char *prev_s = src;
char *r, *c;
int f = -1, s = -1, m = -1;
Expand Down
30 changes: 15 additions & 15 deletions font.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,16 @@ int font_layout(struct font *fn, struct glyph **gsrc, int nsrc, int sz,
static int font_readchar(struct font *fn, FILE *fin, int *n, int *gid)
{
struct glyph *g;
char tok[ILNLEN];
char name[ILNLEN];
char id[ILNLEN];
char tok[128];
char name[GNLEN];
char id[GNLEN];
int type;
if (fscanf(fin, "%s %s", name, tok) != 2)
if (fscanf(fin, GNFMT " %128s", name, tok) != 2)
return 1;
if (!strcmp("---", name))
sprintf(name, "c%04d", *n);
if (strcmp("\"", tok)) {
if (fscanf(fin, "%d %s", &type, id) != 2)
if (fscanf(fin, "%d " GNFMT, &type, id) != 2)
return 1;
*gid = font_glyphput(fn, id, name, type);
g = &fn->gl[*gid];
Expand Down Expand Up @@ -472,13 +472,13 @@ static int font_readgsub(struct font *fn, FILE *fin)
struct grule *rule;
int feat, scrp, lang;
int i, n;
if (fscanf(fin, "%s %d", tok, &n) != 2)
if (fscanf(fin, "%128s %d", tok, &n) != 2)
return 1;
font_readfeat(fn, tok, &feat, &scrp, &lang);
rule = font_gsub(fn, n, feat, scrp, lang);
rule->sec = fn->secs;
for (i = 0; i < n; i++) {
if (fscanf(fin, "%s", tok) != 1)
if (fscanf(fin, "%128s", tok) != 1)
return 1;
if (tok[0] == '-')
rule->pats[i].flg = GF_PAT;
Expand All @@ -499,13 +499,13 @@ static int font_readgpos(struct font *fn, FILE *fin)
struct grule *rule;
int feat, scrp, lang;
int i, n;
if (fscanf(fin, "%s %d", tok, &n) != 2)
if (fscanf(fin, "%128s %d", tok, &n) != 2)
return 1;
font_readfeat(fn, tok, &feat, &scrp, &lang);
rule = font_gpos(fn, n, feat, scrp, lang);
rule->sec = fn->secs;
for (i = 0; i < n; i++) {
if (fscanf(fin, "%s", tok) != 1)
if (fscanf(fin, "%128s", tok) != 1)
return 1;
col = strchr(tok, ':');
if (col)
Expand All @@ -523,12 +523,12 @@ static int font_readgpos(struct font *fn, FILE *fin)

static int font_readggrp(struct font *fn, FILE *fin)
{
char tok[ILNLEN];
char tok[GNLEN];
int id, n, i, g;
if (fscanf(fin, "%d %d", &id, &n) != 2)
return 1;
for (i = 0; i < n; i++) {
if (fscanf(fin, "%s", tok) != 1)
if (fscanf(fin, GNFMT, tok) != 1)
return 1;
g = font_idx(fn, font_glyph(fn, tok));
if (g >= 0)
Expand All @@ -539,10 +539,10 @@ static int font_readggrp(struct font *fn, FILE *fin)

static int font_readkern(struct font *fn, FILE *fin)
{
char c1[ILNLEN], c2[ILNLEN];
char c1[GNLEN], c2[GNLEN];
struct grule *rule;
int val;
if (fscanf(fin, "%s %s %d", c1, c2, &val) != 3)
if (fscanf(fin, GNFMT " " GNFMT " %d", c1, c2, &val) != 3)
return 1;
rule = font_gpos(fn, 2, font_findfeat(fn, "kern"), -1, -1);
rule->pats[0].g = font_idx(fn, font_glyph(fn, c1));
Expand Down Expand Up @@ -605,7 +605,7 @@ struct font *font_open(char *path)
struct font *fn;
int ch_g = -1; /* last glyph in the charset */
int ch_n = 0; /* number of glyphs in the charset */
char tok[ILNLEN];
char tok[128];
FILE *fin;
char ligs[512][GNLEN];
int ligs_n = 0;
Expand All @@ -623,7 +623,7 @@ struct font *font_open(char *path)
fn->ch_dict = dict_make(-1, 1, 0);
fn->ch_map = dict_make(-1, 1, 0);
fn->ggrp = iset_make();
while (fscanf(fin, "%s", tok) == 1) {
while (fscanf(fin, "%128s", tok) == 1) {
if (!strcmp("char", tok)) {
font_readchar(fn, fin, &ch_n, &ch_g);
} else if (!strcmp("kern", tok)) {
Expand Down
8 changes: 4 additions & 4 deletions hyph.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void hyphenate(char *hyph, char *word, int flg)

void tr_hpfa(char **args)
{
char tok[ILNLEN], c1[ILNLEN], c2[ILNLEN];
char tok[128], c1[GNLEN], c2[GNLEN];
FILE *filp;
hyinit = 1;
/* load english hyphenation patterns with no arguments */
Expand All @@ -306,21 +306,21 @@ void tr_hpfa(char **args)
}
/* reading patterns */
if (args[1] && (filp = fopen(args[1], "r"))) {
while (fscanf(filp, "%s", tok) == 1)
while (fscanf(filp, "%128s", tok) == 1)
if (strlen(tok) < WORDLEN)
hy_add(tok);
fclose(filp);
}
/* reading exceptions */
if (args[2] && (filp = fopen(args[2], "r"))) {
while (fscanf(filp, "%s", tok) == 1)
while (fscanf(filp, "%128s", tok) == 1)
if (strlen(tok) < WORDLEN)
hw_add(tok);
fclose(filp);
}
/* reading hcode mappings */
if (args[3] && (filp = fopen(args[3], "r"))) {
while (fscanf(filp, "%s", tok) == 1) {
while (fscanf(filp, "%128s", tok) == 1) {
char *s = tok;
if (utf8read(&s, c1) && utf8read(&s, c2) && !*s)
hcode_add(c2, c1); /* inverting */
Expand Down
2 changes: 1 addition & 1 deletion roff.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#define NFONTS 32 /* number of fonts */
#define FNLEN 32 /* font name length */
#define GNLEN 32 /* glyph name length */
#define GNFMT "%32s" /* glyph name scanf format */
#define NMLEN 128 /* macro/register/environment name length */
#define RNLEN NMLEN /* register/macro name */
#define NREGS 8192 /* number of mapped names */
#define ILNLEN 1000 /* line limit of input files */
#define NARGS 32 /* number of macro arguments */
#define NPREV 16 /* environment stack depth */
#define NTRAPS 1024 /* number of traps per page */
Expand Down
2 changes: 1 addition & 1 deletion sbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void sbuf_append(struct sbuf *sbuf, char *s)

void sbuf_printf(struct sbuf *sbuf, char *s, ...)
{
char buf[ILNLEN];
char buf[1024];
va_list ap;
va_start(ap, s);
vsnprintf(buf, sizeof(buf), s, ap);
Expand Down

0 comments on commit 51afad2

Please sign in to comment.