From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5699 invoked by alias); 22 Mar 2007 08:15:52 -0000 Received: (qmail 5687 invoked by uid 22791); 22 Mar 2007 08:15:51 -0000 X-Spam-Check-By: sourceware.org Received: from mail.sunnorth.com.cn (HELO mswbj01.sunnorth.com.cn) (124.42.0.200) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 22 Mar 2007 08:15:46 +0000 Received: from maillog.sunnorth.com.cn (unverified [172.20.10.250]) by mswbj01.sunnorth.com.cn (Clearswift SMTPRS 5.2.5) with ESMTP id for ; Thu, 22 Mar 2007 16:15:41 +0800 Received: from ntns1cn.sunnorth.com.cn (ntns1cn.sunnorth.com.cn [172.20.10.252]) by maillog.sunnorth.com.cn (8.12.10/8.12.10) with ESMTP id l2MA8JO6014460 for ; Thu, 22 Mar 2007 18:08:19 +0800 To: gdb-patches@sourceware.org Subject: [patch] libiberty/vasprintf.c bug MIME-Version: 1.0 X-Mailer: Lotus Notes Release 6.5 September 26, 2003 Message-ID: From: qinwei Date: Thu, 22 Mar 2007 08:15:00 -0000 Content-Type: text/plain; charset="US-ASCII" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-03/txt/msg00193.txt.bz2 Dears, problems are here: #include 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