shithub: sl

Download patch

ref: 11700e8fe75f45de743eb63336f25de1bf398bc5
parent: 084b2085f8a8fb264fba9c88bcb84826a8ba7ea8
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Mar 19 22:55:03 EDT 2025

io: always strdup filename (else a crashe on io-set-filename! of in-memory io)

--- a/src/ios.c
+++ b/src/ios.c
@@ -3,8 +3,6 @@
 
 #define MOST_OF(x) ((x) - ((x)>>4))
 
-static char emptystr[] = "";
-
 sl_ios *ios_stdin = nil;
 sl_ios *ios_stdout = nil;
 sl_ios *ios_stderr = nil;
@@ -565,10 +563,8 @@
 void
 ios_free(sl_ios *s)
 {
-	if(s->loc.filename != emptystr){
-		MEM_FREE(s->loc.filename);
-		s->loc.filename = emptystr;
-	}
+	MEM_FREE(s->loc.filename);
+	s->loc.filename = nil;
 }
 
 static void
@@ -779,7 +775,7 @@
 {
 	_ios_init(s);
 	s->bm = bm_mem;
-	s->loc.filename = emptystr;
+	s->loc.filename = MEM_STRDUP("");
 	_buf_realloc(s, initsize);
 	return s;
 }