shithub: fontsel

Download patch

ref: d12d18424997ed37819ef3832b25c25094e6ff1d
parent: 3f4f25323d5c8a10d595c8c9dc483479fe42d61f
author: Sigrid Haflínudóttir <[email protected]>
date: Wed Aug 5 10:42:07 EDT 2020

fix stack overflow; close file when not needed; fix alternative text file reading

--- a/fontsel.c
+++ b/fontsel.c
@@ -61,6 +61,7 @@
 static Fontdir *dirs, *cdir;
 static int ndirs, idir;
 static char lasterr[256];
+int mainstacksize = 32768;
 
 static void
 redraw(void)
@@ -120,7 +121,7 @@
 	long i, n;
 
 	k = strlen(t);
-	if(k > 4 && strcmp(&t[k-4], ".ttf") == 0){
+	if(k > 4 && (cistrcmp(&t[k-4], ".ttf") == 0 || cistrcmp(&t[k-4], ".otf") == 0)){
 		fdir->nfonts = 1;
 		fdir->sz = Ttfdefsz;
 		fdir->isttf = 1;
@@ -165,7 +166,7 @@
 	long i, n;
 	char t[1024];
 
-	doff = sprint(t, prefix);
+	doff = sprint(t, "%s", prefix);
 	t[doff++] = '/';
 	t[doff] = 0;
 	if((f = open(t, OREAD)) < 0){
@@ -177,8 +178,9 @@
 		close(f);
 		return;
 	}
+	close(f);
 	for(i = 0; i < n; i++){
-		sprint(t+doff, d[i].name);
+		strcpy(t+doff, d[i].name);
 		if((fin = open(t, OREAD)) < 0)
 			continue;
 		if((din = dirfstat(fin)) != nil){
@@ -276,7 +278,7 @@
 	if(argc > 1)
 		usage();
 	else if(argc == 1)
-		loadtext(strcmp(argv[0], "-") == 0 ? 0 : open(argv[1], OREAD));
+		loadtext(strcmp(argv[0], "-") == 0 ? 0 : open(argv[0], OREAD));
 
 	for(n = 0; n < nelem(prefixes); n++)
 		findfonts(prefixes[n]);