This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16211] New: If mixing templates and va_list (va_arg) and char* string you wont be happy


I hope I do not offend anyone, but this code seems to segfault. Im not even sure
what this form wants as host triplet. I read the guidlines, and got the picture
that you do not want source, but I cant explain this any other way. Well here
goes, hope Ill not make a total fool of myself.

The crash comes from an invalid address returned by va_arg( ). Undefine CRASH to
see it work as expected.

gcc version 3.3 20030226 (prerelease) (SuSE Linux)

------------ Code snipet ---------------
#include <stdarg.h> //	va_list
#include <stdio.h>

#define CRASH

void func( const char *str,... );

#ifdef CRASH
template< class TYPE > bool FormTest( const char* str,char* i )
{
	func( str,i );
	return true;
}
#else
bool FormTest( const char* str,char* i )
{
	func( str,i );
	return true;
}
#endif

int main( void )
{
#ifdef CRASH
	FormTest< char* >( "%s\n","string" );
#else
	FormTest( "%s\n","string" );
#endif
}

void func( const char *str,va_list &ap );

void func( const char *str,... )
{
	va_list ap; va_start( ap,str );
	func( str,ap );
	va_end( ap );
}

void func( const char *str,va_list &ap )
{
	const char *pek; int i;
	pek=va_arg( ap,const char* ); printf( str,pek );
}

-- 
           Summary: If mixing templates and va_list (va_arg) and char*
                    string you wont be happy
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: netletter at comder dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: /lib/ld-linux.so.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16211


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]