Mail Archives: djgpp/2001/12/12/06:47:54
X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f
|
From: | Waldemar Schultz <schultz AT ma DOT tum DOT de>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | gcc bug or am I blind?
|
Date: | Wed, 12 Dec 2001 12:37:46 +0100
|
Organization: | [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
|
Lines: | 100
|
Message-ID: | <3C17418A.85364005@ma.tum.de>
|
NNTP-Posting-Host: | pcritter14.mathematik.tu-muenchen.de
|
Mime-Version: | 1.0
|
X-Trace: | wsc10.lrz-muenchen.de 1008157062 12114 131.159.68.151 (12 Dec 2001 11:37:42 GMT)
|
X-Complaints-To: | news AT lrz-muenchen DOT de
|
NNTP-Posting-Date: | 12 Dec 2001 11:37:42 GMT
|
X-Mailer: | Mozilla 4.75 [de] (Win98; U)
|
X-Accept-Language: | de,en-US
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hi,
Please have a look on this program
//M_CAT.c
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <conio.h>
char *m_strcat(char *base, ...){
va_list arg_ptr;
char *dest;
char *arg;
printf("%s\n",base);
if(!base) return NULL;
dest=strdup(base);
if(!dest) return NULL;
va_start(arg_ptr,base);
for(;;)
{
arg=va_arg(arg_ptr,char *);
if(!arg || !*arg) break;
printf("'%s':'%s'%ld\n",dest,arg,strlen(arg));getch();
dest=realloc(dest,strlen(arg)*sizeof(*dest));
if(!dest)
break;
strcat(dest,arg);
}
va_end(arg_ptr);
return dest;
}
int main(void){
char *a="hello ", *b="out ", *c="there ";
char *s;
s=m_strcat("hello ","out ","there ",NULL);
if(s)
{
printf("%s\n",s); printf("%p\n",s);
free(s);
}
s=m_strcat("HI",a,b,c,NULL);
if(s)
{
printf("%s\n",s); printf("%p\n",s);
free(s);
}
return EXIT_SUCCESS;
}
//M_CAT.c
compiling and running gives the following:
#66:W98 C:\USR\FGSM\H2O\SIM\TOOL>gcc -W -Wall -g m_cat.c
#66:W98 C:\USR\FGSM\H2O\SIM\TOOL>a
hello
'hello ':'out '4
'hello out ':'there '6
hello out there
20b30
HI
Exiting due to signal SIGSEGV
General Protection Fault at eip=00004633
eax=20657255 ebx=00020b3c ecx=00020b4c edx=00020b44 esi=00000008
edi=00000008
ebp=006b6f5c esp=006b6f4c program=C:\USR\FGSM\H2O\SIM\TOOL\A.EXE
cs: sel=00a7 base=82d93000 limit=006b6fff
ds: sel=00af base=82d93000 limit=006b6fff
es: sel=00af base=82d93000 limit=006b6fff
fs: sel=0087 base=0000c680 limit=0000ffff
gs: sel=00bf base=00000000 limit=0010ffff
ss: sel=00af base=82d93000 limit=006b6fff
App stack: [006b7000..00637000] Exceptn stack: [00011ebc..0000ff7c]
Call frame traceback EIPs:
0x00004633 _malloc+99
0x00002fea _strdup+90
0x000015bc _m_strcat+56, line 15 of m_cat.c
0x00001729 _main+145, line 42 of m_cat.c
0x00002b52 ___crt1_startup+178
#66:W98 C:\USR\FGSM\H2O\SIM\TOOL>symify a.exe
#66:W98 C:\USR\FGSM\H2O\SIM\TOOL>gcc -v
Reading specs from e:/djgpp/lib/gcc-lib/djgpp/2.953/specs
gcc version 2.95.3 20010315/djgpp (release)
can anyone see somthing I am doing wrong?
or is there an issue with varargs ?
Thank you for any help.
--
Gruss Waldemar Schultz. schultz AT ma DOT tum DOT de
Technische Universität München, Zentrum Mathematik M1, D 80290 München
Tel: +49 (0)89 2892 8226 FAX: +49 (0)89 2892 8228
- Raw text -