This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] libiberty/vasprintf.c bug
- From: qinwei<qinwei at sunnorth dot com dot cn>
- To: gdb-patches at sourceware dot org
- Date: Thu, 22 Mar 2007 16:15:39 +0800
- Subject: [patch] libiberty/vasprintf.c bug
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