delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/28/10:02:13

From: "Greg Donnells" <gad AT donnesys DOT com>
Newsgroups: comp.os.msdos.djgpp
References: <3ac02f4b$0$14446$272ea4a1 AT news DOT execpc DOT com> <Um7w6.1128$eX4 DOT 241968 AT typhoon DOT tampabay DOT rr DOT com> <l48w6.369$083 DOT 262866 AT typhoon DOT tampabay DOT rr DOT com> <3AC1609C DOT A537E890 AT earthlink DOT net>
Subject: Re: Hunting Sigsev Errors
Lines: 202
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6600
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
Message-ID: <oSmw6.1515$083.1101438@typhoon.tampabay.rr.com>
Date: Wed, 28 Mar 2001 14:49:56 GMT
NNTP-Posting-Host: 24.164.23.148
X-Complaints-To: abuse AT rr DOT com
X-Trace: typhoon.tampabay.rr.com 985790996 24.164.23.148 (Wed, 28 Mar 2001 09:49:56 EST)
NNTP-Posting-Date: Wed, 28 Mar 2001 09:49:56 EST
Organization: RoadRunner - TampaBay
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Here is the source code (full, since this problem does not manifest itself
in a smaller program that uses the same structures) - after the code you'll
find the complier output - after the complier output, you'll find the
runtime output.... Note that if you change the ARRAYSIZE to 512 (instead of
1024) that all problems go away.

-------------------------------
gcc version
-------------------------------
Reading specs from c:/cc/lib/gcc-lib/djgpp/2.953/specs
gcc version 2.95.3 20010315/djgpp (release)

-------------------------------
source code - dumpcbs.c
-------------------------------
/*
** dumpcbs.c
**
** dumps cbs files from filename $1 - writes to fname $2
**
** Usage: dumpcbs <infile> <outfile>
**
*/

#include <stdio.h>
#include <string.h>

#define LOG(a,b) fprintf(stderr, a, b);
/*
#define LOG(a, b) /* null */

#define ARRAYMAX 1024
#define NUL (char)0

void main (int argc, char *argv[])
{
 FILE *ifp, *ofp;
 int  i;
 char *pos;

 /*
 ** header structure
 */

 struct hdr {
  char cbs[4];
  long start;
  long last;
 } cbs_hdr;

 /*
 ** record structure
 ** make it an array so we can read the whole thing in and
 ** determine the number of files in the CBS file before
 ** writing them out
 */

 struct rec {
  long index;
  char fname[512];
 } allrecs[ARRAYMAX];

 LOG("Starting: argc is %d\n", argc)

 if (argc != 3)
 {
  fprintf(stderr, "\nUsage: %s <infile> <outfile>\n\n", argv[0]);
  exit(1);
 }

 /*
 ** open input .cbs file
 */

 LOG("opening '%s' for read\n", argv[1])
 if ((ifp=fopen(argv[1],"rb"))==NULL)
 {
  fprintf(stderr, "\nError -2: Could not open '%s' for reading.\n\n",
    argv[1]);
  exit(-2);
 }

 /*
 ** open output file
 */

 LOG("opening '%s' for write\n", argv[2])
 if ((ofp=fopen(argv[2],"wb"))==NULL)
 {
  fprintf(stderr, "\nError -2: Could not open '%s' for writing.\n\n",
    argv[2]);
  exit(-2);
 }

 /*
 ** read header
 */
 LOG("Reading header size: %d\n", sizeof(struct hdr))

 if (fread(&cbs_hdr, sizeof(struct hdr), 1, ifp)!=1)
 {
  fprintf(stderr,"\nError %d: input file header read error\n\n", -3);
  exit(-3);
 }
 LOG("...header is: %s\n", cbs_hdr.cbs);
 LOG("...start is: %d\n", cbs_hdr.start);
 LOG("...last is: %d\n", cbs_hdr.last);

 /*
 ** read all records in infile into structures
 */

 /*
 for(i=0;i<cbs_hdr.last;i++)
 {
  fread(&allrecs[i], sizeof(struct rec), 1, ifp);
  LOG("read record %d\n", i)
  printf("read %d: %s\n",allrecs[i].index,allrecs[i].fname);
 }
 */

 i=fread(allrecs, sizeof(struct rec), cbs_hdr.last, ifp);

 if (i!=cbs_hdr.last)
 {
  fprintf(stderr,"\nError %d: badly formed record count (%d) in header\n",
    -4, cbs_hdr.last);
  exit(-4);
 }

 /*
 ** print all records in a form that mkcbs can read
 */
 for (i=0;i<cbs_hdr.last;i++)
 {
  LOG("loop %d\n",i)
  /*
  ** find the strings in fname - change the null terminators to separators
  ** Don't change the strings of null to separators
  */

  for (pos=allrecs[i].fname;pos<allrecs[i].fname+510;pos++)
  {
   if (*pos == NUL && *(pos+1) != NUL)
   {
    *pos=';';
   }
  }

  /*
  ** print the result to the output file
  */
  fprintf(ofp,"%d;%s\n",allrecs[i].index, allrecs[i].fname);
 }

 fclose(ifp);
 fclose(ofp);
 exit(0);

}
-------------------------------------------
gcc output
-------------------------------------------

dumpcbs.c:15: warning: `/*' within comment
dumpcbs.c: In function `main':
dumpcbs.c:83: warning: int format, long int arg (arg 3)
dumpcbs.c:91: warning: int format, long int arg (arg 3)
dumpcbs.c:92: warning: int format, long int arg (arg 3)
dumpcbs.c:112: warning: int format, long int arg (arg 4)
dumpcbs.c:138: warning: int format, long int arg (arg 3)

-------------------------------------------
dumpcbs register dump
-------------------------------------------

Starting: argc is 1
Exiting due to signal SIGSEGV
General Protection Fault at eip=0000af05
eax=1583e500 ebx=0000c570 ecx=0000000a edx=0000000d esi=0000000a edi=0000ef7
0
ebp=00009b3c esp=00009b28 program=C:\gad\dumpcbs.exe
cs: sel=00a7  base=8396d000  limit=0009ffff
ds: sel=00af  base=8396d000  limit=0009ffff
es: sel=00af  base=8396d000  limit=0009ffff
fs: sel=0087  base=00010af0  limit=0000ffff
gs: sel=00bf  base=00000000  limit=0010ffff
ss: sel=00af  base=8396d000  limit=0009ffff
App stack: [0008ffc4..0000ffc4]  Exceptn stack: [0000ff20..0000dfe0]

Call frame traceback EIPs:
  0x0000af05










- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019