Rewrite remaining strcpy() calls in core.
authorDavid Griffith <dave@661.org>
Sat, 2 Feb 2019 09:00:38 +0000 (01:00 -0800)
committerDavid Griffith <dave@661.org>
Sat, 2 Feb 2019 09:00:38 +0000 (01:00 -0800)
I need to remember to free all members of the f_setup and u_setup
structures. It seems like the place to do this is in reset_memory() for
the core and os_quit() for curses.  I should add os_quit() for the other
interfaces.

src/common/files.c

index 62892b21292f9798c9a6e248fd150264e49fb41d..cd54c154000561e8c6ed364b3136cc58ea575832 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include "frotz.h"
 
 #ifndef SEEK_SET
@@ -74,8 +75,8 @@ void script_open (void)
        if (!os_read_file_name (new_name, f_setup.script_name, FILE_SCRIPT))
            goto done;
 
-       strcpy (f_setup.script_name, new_name);
-
+       free(f_setup.script_name);
+       f_setup.script_name = strdup(new_name);
     }
 
     /* Opening in "at" mode doesn't work for script_erase_input... */
@@ -294,7 +295,8 @@ void record_open (void)
 
     if (os_read_file_name (new_name, f_setup.command_name, FILE_RECORD)) {
 
-       strcpy (f_setup.command_name, new_name);
+       free(f_setup.command_name);
+       f_setup.command_name = strdup(new_name);
 
        if ((rfp = fopen (new_name, "wt")) != NULL)
            ostream_record = TRUE;
@@ -418,7 +420,8 @@ void replay_open (void)
 
     if (os_read_file_name (new_name, f_setup.command_name, FILE_PLAYBACK)) {
 
-       strcpy (f_setup.command_name, new_name);
+       free(f_setup.command_name);
+       f_setup.command_name = strdup(new_name);
 
        if ((pfp = fopen (new_name, "rt")) != NULL) {