Mail Archives: djgpp/2001/03/27/17:16:56
Well, I've discovered something interesting regarding SIGSEV errors and gcc
(2.953). Consider the following code fragment:
-----------------------------------------------------
#include <stdio.h>
#include <string.h>
#define LOG(a,b) fprintf(stderr, a, b);
#define ARRAYMAX 1024
#define NUL (char)0
main (int argc, char *argv[])
{
FILE *ifp, *ofp;
int i, p;
char *pos, *j;
struct hdr {
char cbs[4];
long start;
long last;
} cbs_hdr;
struct rec {
long index;
char fname[512];
} allrecs[ARRAYMAX];
LOG("Starting with argc = %d\n", argc);
-----------------------------------------------------
This code fragment will ALWAYS generate a SIGSEV before the LOG call. If it
doesn't - I get real strange behavior out of the fread() function call.
Changing the ARRAYSIZE to 512 fixes this - no more SIGSEV and no more wierd
behavior out of fread(). Looks like some sort of allocation bug or internal
limit is being reached (1024x516= ~.5M, but 512x516=~.25M).
NOTE: The rest of the above program is another 50 lines of C code - that's
all - no subroutines, etc. Just a main() module.
- Raw text -