From: Pedro Alves <palves@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: Off-by-one error in windows-nat.c causes abort at startup
Date: Mon, 02 May 2016 18:01:00 -0000 [thread overview]
Message-ID: <59183932-8ea1-7c2c-d4e2-b1567ede1260@redhat.com> (raw)
In-Reply-To: <83wpncl8h4.fsf@gnu.org>
On 05/02/2016 05:39 PM, Eli Zaretskii wrote:
>> From: Pedro Alves <palves@redhat.com>
>>> --- gdb/windows-nat.c~ 2016-02-10 05:19:39.000000000 +0200
>>> +++ gdb/windows-nat.c 2016-04-30 11:57:08.500000000 +0300
>>> @@ -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);
>>
>> (I suspect this whole function could be rewritten in a clearer form...)
>
> Like not use xsnprintf at all, and instead use strcpy/strcat, perhaps?
>
Yeah, something like this (untested).
From 33738f6c5bf7f76d6cb6853aecf880c5570f7d74 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 2 May 2016 18:57:50 +0100
Subject: [PATCH] Rewrite/simplify old gdb.ini warning
---
gdb/windows-nat.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 2e8a777..161e887 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -2694,27 +2694,28 @@ void
_initialize_check_for_gdb_ini (void)
{
char *homedir;
+
if (inhibit_gdbinit)
return;
homedir = getenv ("HOME");
- if (homedir)
+ if (homedir != NULL)
{
- char *p;
- char *oldini = (char *) alloca (strlen (homedir) +
- sizeof ("gdb.ini") + 1);
- strcpy (oldini, homedir);
- p = strchr (oldini, '\0');
- if (p > oldini && !IS_DIR_SEPARATOR (p[-1]))
- *p++ = '/';
- strcpy (p, "gdb.ini");
+ size_t homedir_len = strlen (homedir);
+ char *oldini;
+
+ while (homedir_len > 0 && IS_DIR_SEPARATOR (homedir[homedir_len - 1]))
+ homedir_len--;
+
+ oldini = (char *) alloca (homedir_len + sizeof ("/gdb.ini"));
+ memcpy (oldini, homedir, homedir_len);
+ strcpy (oldini + homedir_len, "/gdb.ini");
if (access (oldini, 0) == 0)
{
- int len = strlen (oldini);
- char *newini = (char *) alloca (len + 2);
+ char *newini = (char *) alloca (homedir_len + sizeof ("/.gdbinit"));
- xsnprintf (newini, len + 2, "%.*s.gdbinit",
- (int) (len - (sizeof ("gdb.ini") - 1)), oldini);
+ memcpy (newini, homedir, homedir_len);
+ strcpy (newini + homedir_len, "/.gdbinit");
warning (_("obsolete '%s' found. Rename to '%s'."), oldini, newini);
}
}
--
2.5.5
prev parent reply other threads:[~2016-05-02 18:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-30 11:08 Eli Zaretskii
2016-05-02 11:50 ` Pedro Alves
2016-05-02 16:40 ` Eli Zaretskii
2016-05-02 18:01 ` Pedro Alves [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=59183932-8ea1-7c2c-d4e2-b1567ede1260@redhat.com \
--to=palves@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).