From: qinwei<qinwei@sunnorth.com.cn>
To: gdb-patches@sourceware.org
Subject: [patch] libiberty/vasprintf.c bug
Date: Thu, 22 Mar 2007 08:15:00 -0000 [thread overview]
Message-ID: <OF668DB54A.138E7B2A-ON482572A6.002B831E-482572A6.002D6007@sunnorth.com.cn> (raw)
Dears, problems are here:
#include<stdio.h>
class student
{
public:
student(int age)
{
m_age = age;
}
void ShowAge()
{
printf("%d",m_age);
}
protected:
int m_age;
};
int main(void)
{
student aa(10);
aa.ShowAge();
return 0;
}
build it with score-elf-gcc (gcc-4.2),
and debug it with score-elf-gdb (gdb-6.6 release version),
(gdb) b 12
Breakpoint 1 at 0x196: file main.cxx, line 12.
(gdb) r
Starting program: /home/qinwei/GJ283/code/build_linux/debug-gdb/tt
Breakpoint 1, student::ShowAge (this=0x7ffffd8) at main.cxx:12
12 printf("%d",m_age);
(gdb) p this.ShowAge()
Cannot resolve method (null)ShowAge to any overloaded instance
(gdb)
When type "p this.ShowAge()", gdb (linux-version) will call function
"error" which will call "vasprintf" in glibc and print this error
message correctly.
But using mingw-build gdb, this case will cause segmentation fault.
For mingw-build gdb will use "vasprintf" in libiberty/vasprintf.c
which has bug. Modify this can solve the problem.
diff -ruN vasprintf.c vasprintf.c.new &>vasprintf.c.patch
--- vasprintf.c 2007-03-22 16:03:13.000000000 +0800
+++ vasprintf.c.new 2007-03-13 11:50:27.000000000 +0800
@@ -64,6 +64,7 @@
int_vasprintf (char **result, const char *format, va_list args)
{
const char *p = format;
+ char *ptr = NULL;
/* Add one to make sure that it is never zero, which might cause malloc
to return NULL. */
int total_width = strlen (format) + 1;
@@ -125,7 +126,8 @@
total_width += 307;
break;
case 's':
- total_width += strlen (va_arg (ap, char *));
+ if ((ptr = va_arg (ap, char *)) != NULL)
+ total_width += strlen (ptr);
break;
case 'p':
case 'n':
Best regards,
Qinwei
Mail qinwei@sunnorth.com.cn
Phone +86-010-62981668-2708
Fax +86-010-62985972
next reply other threads:[~2007-03-22 8:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-22 8:15 qinwei [this message]
2007-03-22 18:16 ` DJ Delorie
2007-03-23 2:44 ` qinwei
2007-03-23 3:45 ` DJ Delorie
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=OF668DB54A.138E7B2A-ON482572A6.002B831E-482572A6.002D6007@sunnorth.com.cn \
--to=qinwei@sunnorth.com.cn \
--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