Hi there,

(second try to post thread, was not logon and stupid browser loose all my message...)

We are doing a migration with our C applications from AIX 4.3 to Linux Red Hat Enterprise 3.0 (kernel 2.4.21-27.ELsmp) and with GCC 3.2.3. We got to runtime error in some executable so far. Looks all the same except some are sprintf and others fprintf errors. Here a GDB backtrace:

Code:
[Thread debugging using libthread_db enabled]
[New Thread 16384 (LWP 14014)]
Detaching after fork from child process 14017.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 14014)]
0x001ef703 in strlen () from /lib/i686/libc.so.6
(gdb) bt
#0  0x001ef703 in strlen () from /lib/i686/libc.so.6
#1  0x001bf8d9 in vfprintf () from /lib/i686/libc.so.6
#2  0x001c67ef in fprintf () from /lib/i686/libc.so.6
#3  0x0804ee63 in Write_PpiFileFor (Rec_Type_id=0x80612e8 "A1") at ppi_extract.pc:512
#4  0x08057c80 in Build_CcdRecA1 (r_trnreq=0xbfffcea0, r_emple_info=0xbfffc420) at ppi_extract.pc:2171
#5  0x0805541e in Build_CcdRecAA (r_trnreq=0xbfffcea0, req_type=0x8061090 "CHQ") at ppi_extract.pc:1624
#6  0x08054786 in Process_ReqTransFor (req_type=0x8061090 "CHQ") at ppi_extract.pc:1424
#7  0x0804e297 in MainProcess () at ppi_extract.pc:355
#8  0x0804e1c3 in main (argc=3, argv=0xbfffe084) at ppi_extract.pc:318
The program crash at the Write_PpiFileFor function at the fprintf line:

Code:
rec_ccd_A1_t        r_ccd_A1;

static long Write_PpiFileFor( char *Rec_Type_id)
{
    long        result = 0;
    int         i;
    
    WriteTrack("Write_PpiFileFor");
    if (pfiletoccd == (FILE *) NULL) {
        result = DCM_CANNOT_OPEN_FILE;
        Mesg_DCM_LogErr("Write_PpiFileFor", "Cannot open PPI File");
    } else {

/* ... */

if (strcmp(Rec_Type_id, "A1") == UTIL_OK) {
            req_alltrn_rec++;

            fprintf(pfiletoccd, "%2s%2s%6s%4s%3s%5s%29s%2s%3s%2s%10s%2s%12s%1018s\n", r_ccd_A1.Rec_Type_Id,
                CHAR_BLK, r_ccd_A1.POL_NUM, CHAR_BLK, r_ccd_A1.DIV_Num,
                CHAR_BLK, r_ccd_A1.Participant_Name, CHAR_BLK, r_ccd_A1.Office_Num,
                CHAR_BLK, r_ccd_A1.Registration_Num, CHAR_BLK, r_ccd_A1.Issued_Dt,CHAR_BLK);
        }

/* ... */

return result;

}
And here's the structure definition:

Code:
typedef struct rec_ccd_A1_s
{
 char   Rec_Type_Id[2+1];
 char   POL_NUM[6+1];
 char   DIV_Num[3+1];
 char   Participant_Name[29+1];
 char   Office_Num[3+1];
 char   Registration_Num[10+1];
 char   Issued_Dt[12+1];
} rec_ccd_A1_t;
I've read in another thread that there's could be a workaround with vsprintf function but our goal is to minimize source code modification because we have a lot of applications to migrate.

Any idea why this code was running fine on AIX and now with GCC it crash like this? And is there other ways than changing code with vsprintf to resolve that bug?

Any help would be appreciated, thank you,

Laurent