ref: 51afad2c12012e90d719029f889afaaa74a048b6
parent: 545147c3896747fce52f922fe984f40ecc10bea3
author: Ali Gholami Rudi <[email protected]>
date: Sat Dec 19 15:23:27 EST 2020
font: buffers of size GNLEN for glyph names
--- a/dev.c
+++ b/dev.c
@@ -77,7 +77,7 @@
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);
@@ -86,7 +86,7 @@
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;
@@ -99,7 +99,7 @@
continue;
}
if (!strcmp("sizes", tok)) {
- while (fscanf(desc, "%s", tok) == 1)
+ while (fscanf(desc, "%128s", tok) == 1)
if (!strcmp("0", tok))
break;
continue;
--- a/dir.c
+++ b/dir.c
@@ -77,7 +77,7 @@
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;
--- a/font.c
+++ b/font.c
@@ -327,16 +327,16 @@
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];
@@ -472,13 +472,13 @@
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;
@@ -499,13 +499,13 @@
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)
@@ -523,12 +523,12 @@
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)
@@ -539,10 +539,10 @@
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));
@@ -605,7 +605,7 @@
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;
@@ -623,7 +623,7 @@
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)) {
--- a/hyph.c
+++ b/hyph.c
@@ -296,7 +296,7 @@
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 */
@@ -306,7 +306,7 @@
}
/* 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);
@@ -313,7 +313,7 @@
}
/* 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);
@@ -320,7 +320,7 @@
}
/* 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 */
--- a/roff.h
+++ b/roff.h
@@ -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 */
--- a/sbuf.c
+++ b/sbuf.c
@@ -38,7 +38,7 @@
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);