-Wwrite-strings: Don't initialize string command variables to empty string
authorPedro Alves <palves@redhat.com>
Wed, 5 Apr 2017 18:21:33 +0000 (19:21 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 5 Apr 2017 18:21:33 +0000 (19:21 +0100)
-Wwrite-strings flags these initializations as requiring a cast.
However, these variables are command variables, and as such point to
heap-allocated memory.  The initial allocation is always done when the
corresponding command is registered.  E.g.,:

    dprintf_function = xstrdup ("printf");
    add_setshow_string_cmd ("dprintf-function", class_support,
    &dprintf_function, _("\
  Set the function to use for dynamic printf"), _("\
  Show the function to use for dynamic printf"), NULL,
    update_dprintf_commands, NULL,
    &setlist, &showlist);

That's why we never reach a bogus attempt to free these string
literals.

So, just drop the incorrect initializations.

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

* breakpoint.c (dprintf_function, dprintf_channel): Don't initialize.
* tracepoint.c (default_collect): Don't initialize.

gdb/ChangeLog
gdb/breakpoint.c
gdb/tracepoint.c

index 4b0024798c2d4f16bd3bf64d1a99d5f78cef4eba..925cb947c2f82e457c57c2c4ddbc1246a8b60ce6 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-05  Pedro Alves  <palves@redhat.com>
+
+       * breakpoint.c (dprintf_function, dprintf_channel): Don't initialize.
+       * tracepoint.c (default_collect): Don't initialize.
+
 2017-04-05  Pedro Alves  <palves@redhat.com>
 
        * macroexp.c (macro_buffer::shared): Now a bool.
index ab6e9c8ffc751053d4ca1fee67ea4df46c8a2c3e..f0db3e44b62afed42731aaccce9d7ae385244ffd 100644 (file)
@@ -345,7 +345,7 @@ static const char *dprintf_style = dprintf_style_gdb;
    copied into the command, so it can be anything that GDB can
    evaluate to a callable address, not necessarily a function name.  */
 
-static char *dprintf_function = "";
+static char *dprintf_function;
 
 /* The channel to use for dynamic printf if the preferred style is to
    call into the inferior; if a nonempty string, it will be passed to
@@ -355,7 +355,7 @@ static char *dprintf_function = "";
    "stderr", this could be an app-specific expression like
    "mystreams[curlogger]".  */
 
-static char *dprintf_channel = "";
+static char *dprintf_channel;
 
 /* True if dprintf commands should continue to operate even if GDB
    has disconnected.  */
index 2da6fdd5434d4da3b91f242e491e880aa25decc2..87ef1418e6dc0f1cfcc8635fc87764a68241c149 100644 (file)
@@ -139,7 +139,7 @@ static struct traceframe_info *traceframe_info;
 static struct cmd_list_element *tfindlist;
 
 /* List of expressions to collect by default at each tracepoint hit.  */
-char *default_collect = "";
+char *default_collect;
 
 static int disconnected_tracing;
 
This page took 0.035035 seconds and 4 git commands to generate.