* [patch] libiberty/vasprintf.c bug
@ 2007-03-22 8:15 qinwei
2007-03-22 18:16 ` DJ Delorie
0 siblings, 1 reply; 4+ messages in thread
From: qinwei @ 2007-03-22 8:15 UTC (permalink / raw)
To: gdb-patches
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch] libiberty/vasprintf.c bug
2007-03-22 8:15 [patch] libiberty/vasprintf.c bug qinwei
@ 2007-03-22 18:16 ` DJ Delorie
2007-03-23 2:44 ` qinwei
0 siblings, 1 reply; 4+ messages in thread
From: DJ Delorie @ 2007-03-22 18:16 UTC (permalink / raw)
To: qinwei; +Cc: gdb-patches
If ptr is NULL, shouldn't we add strlen("(null)") ?
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch] libiberty/vasprintf.c bug
2007-03-22 18:16 ` DJ Delorie
@ 2007-03-23 2:44 ` qinwei
2007-03-23 3:45 ` DJ Delorie
0 siblings, 1 reply; 4+ messages in thread
From: qinwei @ 2007-03-23 2:44 UTC (permalink / raw)
To: gdb-patches
> If ptr is NULL, shouldn't we add strlen("(null)") ?
Yes. This will cause error.
const char *p = NULL;
int i = strlen (p);
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch] libiberty/vasprintf.c bug
2007-03-23 2:44 ` qinwei
@ 2007-03-23 3:45 ` DJ Delorie
0 siblings, 0 replies; 4+ messages in thread
From: DJ Delorie @ 2007-03-23 3:45 UTC (permalink / raw)
To: qinwei; +Cc: gdb-patches
> > If ptr is NULL, shouldn't we add strlen("(null)") ?
>
> Yes. This will cause error.
> const char *p = NULL;
> int i = strlen (p);
I understand that. My question was, if you printf("%s", NULL), what
happens? If it prints "(null)", does that mean you need to account
for the length of that string in your calculations?
(also, note that libiberty patches go to gcc-patches@gcc.gnu.org, in
addition to any other lists who might be interested)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-23 3:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-22 8:15 [patch] libiberty/vasprintf.c bug qinwei
2007-03-22 18:16 ` DJ Delorie
2007-03-23 2:44 ` qinwei
2007-03-23 3:45 ` DJ Delorie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox