When emu_start() is first called, the Uxn struct is uninitialised stack data.
This meant the u->ram pointer would be an invalid address so the program would crash
with a segmentation fault when attempting to free it. By setting it to NULL, we avoid this
because calling free() on a NULL pointer is a no-op.
---
src/uxn11.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/uxn11.c b/src/uxn11.c
index 15adf5d..f2cda7f 100644
--- a/src/uxn11.c
+++ b/src/uxn11.c
@@ -227,6 +227,7 @@ main(int argc, char **argv)
if(argc < 2)
return emu_error("Usage", "uxncli game.rom args");
/* start sequence */
+ u.ram = NULL;
if(!emu_start(&u, argv[1]))
return emu_error("Start", "Failed");
if(!init())
--
2.35.1
---
src/uxn11.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/uxn11.c b/src/uxn11.c
index f2cda7f..c8d60b1 100644
--- a/src/uxn11.c
+++ b/src/uxn11.c
@@ -225,7 +225,7 @@ main(int argc, char **argv)
struct pollfd fds[2];
static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
if(argc < 2)
- return emu_error("Usage", "uxncli game.rom args");
+ return emu_error("Usage", "uxn11 game.rom args");
/* start sequence */
u.ram = NULL;
if(!emu_start(&u, argv[1]))
--
2.35.1
---
src/uxn11.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/uxn11.c b/src/uxn11.c
index c8d60b1..e68300f 100644
--- a/src/uxn11.c
+++ b/src/uxn11.c
@@ -199,7 +199,7 @@ emu_event(Uxn *u)
}
static int
-init(void)
+init(char *title)
{
Atom wmDelete;
display = XOpenDisplay(NULL);
@@ -210,6 +210,7 @@ init(void)
XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask);
wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
XSetWMProtocols(display, window, &wmDelete, 1);
+ XStoreName(display, window, title);
XMapWindow(display, window);
ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width, uxn_screen.height, 32, 0);
hide_cursor();
@@ -230,7 +231,7 @@ main(int argc, char **argv)
u.ram = NULL;
if(!emu_start(&u, argv[1]))
return emu_error("Start", "Failed");
- if(!init())
+ if(!init(argv[1]))
return emu_error("Init", "Failed");
/* console vector */
for(i = 2; i < argc; i++) {
--
2.35.1