-Wwrite-strings: Fix Solaris "set procfs-file"
authorPedro Alves <palves@redhat.com>
Wed, 5 Apr 2017 18:21:36 +0000 (19:21 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 5 Apr 2017 18:21:36 +0000 (19:21 +0100)
Compiling GDB with -Wwrite-strings flags this code in gdb/proc-api.c:

  static char *procfs_filename = "procfs_trace";

as needing a cast.  However, this variable is a command variable, and
as such it's incorrect to initialize it to a literal, since when you
use the corresponding set command, gdb frees the old string...

I didn't manage to fully build Solaris gdb (fails for other reasons),
but I confirmed that the system GDB on Solaris 11 crashes when running
this command:

 (gdb) set procfs-file foo
 Segmentation Fault (core dumped)

So I don't think this commit can make it worse than the status quo.

gdb/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

* proc-api.c (procfs_filename): Don't initialize
        procfs_filename.
(prepare_to_trace): Assume procfs_filename is non-NULL.
(_initialize_proc_api): Give procfs_filename a default value here.

gdb/ChangeLog
gdb/proc-api.c

index d3918599f20ca1446761d3e1d5aebf7aa2aa162f..f4e9562fb2d423e96552f02bac1b2450d79c000c 100644 (file)
@@ -1,3 +1,10 @@
+2017-04-05  Pedro Alves  <palves@redhat.com>
+
+       * proc-api.c (procfs_filename): Don't initialize
+        procfs_filename.
+       (prepare_to_trace): Assume procfs_filename is non-NULL.
+       (_initialize_proc_api): Give procfs_filename a default value here.
+
 2017-04-05  Pedro Alves  <palves@redhat.com>
 
        * break-catch-throw.c (handle_gnu_v3_exceptions): Constify
index 72746ce466a897eb8637b41f9492b7b400cfcadd..dbadd552bf419b4935819c1e14f5d115ad9f8f32 100644 (file)
@@ -60,15 +60,14 @@ struct trans {
 
 static int   procfs_trace    = 0;
 static FILE *procfs_file     = NULL;
-static char *procfs_filename = "procfs_trace";
+static char *procfs_filename;
 
 static void
 prepare_to_trace (void)
 {
   if (procfs_trace)                    /* if procfs tracing turned on */
     if (procfs_file == NULL)           /* if output file not yet open */
-      if (procfs_filename != NULL)     /* if output filename known */
-       procfs_file = fopen (procfs_filename, "a");     /* open output file */
+      procfs_file = fopen (procfs_filename, "a");      /* open output file */
 }
 
 static void
@@ -785,6 +784,7 @@ Show tracing for /proc api calls."), NULL,
                           NULL, /* FIXME: i18n: */
                           &setlist, &showlist);
 
+  procfs_filename = xstrdup ("procfs_trace");
   add_setshow_filename_cmd ("procfs-file", no_class, &procfs_filename, _("\
 Set filename for /proc tracefile."), _("\
 Show filename for /proc tracefile."), NULL,
This page took 0.031318 seconds and 4 git commands to generate.