IO Overflow via putc() in GCC v2.6.3, Slackware v2.x Linux v1.2.11

IO Overflow via putc() in GCC v2.6.3, Slackware v2.x Linux v1.2.11

Post by John D. Mitche » Sat, 16 Dec 1995 04:00:00



I'm getting a segmentation fault when running a program compiled by gcc
(v2.6.3 i486-linux-aout) using 'gcc -o sor -I. -Ih -g sor.c' on a 486 which
has 16 MB RAM, all scsi, and running Linux v1.2.11 based on the Slackware
v2.2/v2.3 distribution (I know, I know, I'm planning on upgrading RSN :-).

The Slackware v2.3 distribution was missing the g++ include files so I
snarfed that binary package ('disk') from the Slackware v2.3 archive on
ftp.cdrom.com and installed that.

The problem is a segmentation fault (gdb output):
[...]
Program received signal SIGSEGV, Segmentation fault.
I've not had this problem with any other programs that I've built with this
setup.  0x1d323 in _IO_file_overflow (f=0x65d00, ch=9) at fileops.c:350
fileops.c:350: No such file or directory.
(gdb) bt
#0  0x1d323 in _IO_file_overflow (f=0x65d00, ch=9) at fileops.c:350
#1  0x1b71a in __overflow (f=0x65d00, ch=9) at genops.c:160
[[I assume those first two are in the C/C++ library]]

#2  0x1cd1c in putc (c=9, stream=0x65d00) at putc.c:11
[[That's a function because I tried forcing the use of the function putc
rather than the macro but it makes no difference.]]

#3  0x15ff7 in dumpAction (
    s=0x66c03 "\n   SymbolTable* _current;", ' ' <repeats 13 times>, "// most current symbol table\n   AST* _currClass;", ' ' <repeats 19 times>, "// current class, for recurs. detect\n   RWTPtrDlist<ErrorMsg>* _errorList;  // errorMsgs owned"..., output=0x65d00, tabs=1, file=-1, line=0, final_newline=1) at gen.c:906
[[This is in the actual 'sor' program.  The string is a few hundred bytes
long.  See the print below...]]

#4  0x1a9c8 in GenCPPClassHeader () at cpp.c:94
#5  0x109c6 in main (argc=3, argv=0xbffffb2c) at main.c:311

(gdb) printf "%500s", s

SymbolTable* _current;             // most current symbol table
AST* _currClass;                   // current class, for recurs. detect
RWTPtrDlist<ErrorMsg>* _errorList;  // errorMsgs owned by Linker!

void initialize();
void initScope(AST* n);
void initFuncScope(AST* n);
void addUnique(AST* id,AST* n);
void addNonUnique(AST* id,AST* n);
void addConstructor(AST* id,AST* n);
void addInheritedScopes(AST* classNode, AST* nteList);
RWTPtrDlist<ErrorMsg>* errorList()  { return _errorList; }
void rptErr(ErrorCode e, AST* n);
void rptErr(ErrorCode e, AST* n, String str);
(gdb)

The application code is pretty simple the offending source line is:
906             if ( *s!='#' ) {TAB;}

where 'TAB' is a macro defined as:
#define TAB     {int i=1; for (;i<=tabs;i++) {putc('\t', output);}}

and 'output' is an argument to dumpAction():
FILE *output

which has been passed 'stdout' by the callers.

I put explicit fflush(output) in the code but that didn't help any either.

I have not had this problem with any of the myriad other programs that I've
built with this system so, I'd really appreciate learning what stupid thing
I'm missing/doing/etc.

Thanks,
        John