Commit:d12d18424997ed37819ef3832b25c25094e6ff1d (browse)
Parent:3f4f25323d5c8a10d595c8c9dc483479fe42d61f
Author:Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
Date:Wed Aug 5 14:42:07 CES 2020
Message:
fix stack overflow; close file when not needed; fix alternative text file reading

fontsel.c => 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]);