Fix startup on MS-Windows when 'gdb.ini' is found in $HOME
authorEli Zaretskii <eliz@gnu.org>
Mon, 2 May 2016 16:37:43 +0000 (19:37 +0300)
committerEli Zaretskii <eliz@gnu.org>
Mon, 2 May 2016 16:37:43 +0000 (19:37 +0300)
* windows-nat.c (_initialize_check_for_gdb_ini): Fix off-by-one
error in allocation of space for "$HOME/.gdbinit" string.  This
caused GDB to abort on startup whenever a '~/gdb.ini' file was
actually found, because xsnprintf would hit an assertion
violation.

gdb/ChangeLog
gdb/windows-nat.c

index 6d7bfb27ee8c8b967cb0575b126254b4893abfdc..7d69419b8cc4dbd1676a4d49f828a065148edda8 100644 (file)
@@ -1,3 +1,11 @@
+2016-05-02  Eli Zaretskii  <eliz@gnu.org>
+
+       * windows-nat.c (_initialize_check_for_gdb_ini): Fix off-by-one
+       error in allocation of space for "$HOME/.gdbinit" string.  This
+       caused GDB to abort on startup whenever a '~/gdb.ini' file was
+       actually found, because xsnprintf would hit an assertion
+       violation.
+
 2016-04-28  Simon Marchi  <simon.marchi@ericsson.com>
 
        * cli/cli-decode.c (help_cmd_list): Do not list commands that
index 71d6670aaa04f2de0ce6dfe5ca0ad71226d50f1a..2e8a777411dc2dd07c5453ea792d87ee88004c15 100644 (file)
@@ -2702,7 +2702,7 @@ _initialize_check_for_gdb_ini (void)
     {
       char *p;
       char *oldini = (char *) alloca (strlen (homedir) +
-                                     sizeof ("/gdb.ini"));
+                                     sizeof ("gdb.ini") + 1);
       strcpy (oldini, homedir);
       p = strchr (oldini, '\0');
       if (p > oldini && !IS_DIR_SEPARATOR (p[-1]))
@@ -2711,9 +2711,9 @@ _initialize_check_for_gdb_ini (void)
       if (access (oldini, 0) == 0)
        {
          int len = strlen (oldini);
-         char *newini = (char *) alloca (len + 1);
+         char *newini = (char *) alloca (len + 2);
 
-         xsnprintf (newini, len + 1, "%.*s.gdbinit",
+         xsnprintf (newini, len + 2, "%.*s.gdbinit",
                     (int) (len - (sizeof ("gdb.ini") - 1)), oldini);
          warning (_("obsolete '%s' found. Rename to '%s'."), oldini, newini);
        }
This page took 0.029572 seconds and 4 git commands to generate.