summaryrefslogtreecommitdiff
blob: 660ab78c65b9747dfef76e8f7e43964be6c27748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--- CPU/spim-utils.c	2006-01-22 01:15:11.000000000 -0600
+++ CPU/spim-utils.c	2006-01-22 01:35:59.000000000 -0600
@@ -105,14 +105,25 @@
       bare_machine = 0;		/* Exception handler uses extended machine */
       accept_pseudo_insts = 1;
 
-      for(filename = strtok_r(exception_file_names, ":", &state);
-          filename;
-          filename = strtok_r(NULL,  ":", &state)) {
-
-        if (read_assembly_file (filename))
-          fatal_error ("Cannot read exception handler: %s\n", filename);
-        write_output (message_out, "Loaded: %s\n", filename);
-      }
+      /*
+       * strtok_r does not guarantee to keep the string usable, so we must back
+       * up the string prior to use
+       */
+      char *files;
+      if ((files = strdup(exception_file_names)) == NULL)
+         fatal_error("Insufficient memory to complete.\n");
+
+      for (filename = strtok_r (files, ":", &state);
+           filename;
+           filename = strtok_r (NULL, ":", &state))
+         {
+            if (read_assembly_file (filename))
+               fatal_error ("Cannot read exception handler: %s\n", filename);
+
+            write_output (message_out, "Loaded: %s\n", filename);
+         }
+
+      free (files);
 
       bare_machine = old_bare;
       accept_pseudo_insts = old_accept;