www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/18/10:19:27

From: cs3prj04 AT lion DOT cs DOT latrobe DOT edu DOT au (Cs3prj Group 04)
Newsgroups: comp.lang.c++,comp.lang.c,comp.os.msdos.djgpp
Subject: Bus error with g++.
Date: 18 Sep 1996 09:34:29 GMT
Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
Lines: 165
Distribution: world
Message-ID: <51ofn5$9do@lion.cs.latrobe.edu.au>
NNTP-Posting-Host: lion.cs.latrobe.edu.au
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am getting a bus error in t_delete immediatley after a call to malloc
(see below - look for BUS ERROR). It happens in a rather large program after 
one particular modulehas been called and terminated. This module reads a file 
into an array of strings for viewing. The module concerned is to large to 
include in here but it does execute and terminate normally.

Does this mean anything to anyone?


/*
   File message.cpp

   The message handler.
*/




#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/file.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "string.hpp"
#include "message.hpp"
#include <curses.h>




#define BufferSize 10000
#define IPath  "error.txt"
#define SIZE 80
#d[Aefine MAX_LINES 200
char *ErrorHandler(int ErrorNo);
int *TrackLines(char *Buffer, int Charsread);
void bar(char *string1);




 /**************************************************************************/
 /**************************************************************************/
 /*********This procedure handles message and error message output**********/
 /**************************************************************************/
 /**************************************************************************/
char *ErrorHandler(int ErrorNo)
{
  int fd,i, CharsRead;
  char Buffer[BufferSize], MessageBuffer[SIZE];

BUS ERROR OCCURS AFTER THIS NEXT STATEMENT.

  int *LineIndex = (int*)malloc(sizeof(int)*MAX_LINES); /*array oflineoffsets*/
  char *message = (char *)malloc(sizeof(char)*SIZE);
  fd = open(IPath, O_RDONLY); 
  CharsRead = read(fd, Buffer, BufferSize);
  LineIndex = TrackLines(Buffer, CharsRead);
  lseek(fd, LineIndex[ErrorNo], SEEK_SET);
  CharsRead = read(fd,message, LineIndex[ErrorNo+1] - LineIndex[ErrorNo]);
  write(fd,message,CharsRead);
  message[CharsRead-1] = '\0'; 
  delete LineIndex;
  return message;

}




/*****************************************************************************/
/*****************************************************************************/
/********This process stores the offsets of each line start in a buffer*******/
/*****************************************************************************/
/*****************************************************************************/
int *TrackLines (char *Buffer, int CharsRead)
{
  
  int i,j;                        /* index into buffer */
  int LineCount = 0;            /* number of lines in buffer */
  int FileOffset = 0;           /* current position in input */
  /* An array of line offsets*/
  int *LineStart= (int*)malloc(sizeof(int)*MAX_LINES);

  LineStart[0] = 0; 
  for (i = 0; i < CharsRead; i++)
    {
      ++FileOffset;           /* Update current file position */
      if (Buffer[i] == '\n')
	LineStart[++LineCount] = FileOffset; 
    }
  return LineStart;
}




/*****************************************************************************/
/*****************************************************************************/
/*******This process writes a message on the message bar**********************/
/*****************************************************************************/
/*****************************************************************************/

WINDOW *Win;

void InitMessage(const WINDOW *Win_)
{
  Win=Win_;
}
 
void DisplayMessageBar()
{
  int X;
  wattron(Win,A_REVERSE);
  wmove(Win,23,0);
  for (X=0;X<79;X++)
    waddch(Win,' ');
  wrefresh(Win);
  wattroff(Win,A_REVERSE);
}

void Message(const char *String)
{                                                          
  wattron(Win,A_REVERSE);
  mvwprintw(Win,23,0,"%-79s",String);
  wrefresh(Win);
  wattroff(Win,A_REVERSE);
}


void ErrorMessage(const int ErrorNumber)
{
  char *Nmessage;
  Nmessage=ErrorHandler(ErrorNumber);
  Message(Nmessage);
  wgetch(Win);
}


void ErrorMessage_(const int ErrorNumber,const int Lower,const int Upper)
{
  StringC NMessage;

  if (ErrorNumber==RangeError)
  {
    NMessage=ErrorHandler(ErrorNumber);
    NMessage+=Lower;
    NMessage+=" and ";
    NMessage+=Upper;
    NMessage+=" expected...";
  }
  else if (ErrorNumber)
  {
    NMessage=ErrorHandler(ErrorNumber);
    NMessage+=Lower;
    NMessage+=")...";
  }
  Message(NMessage);
  wgetch(Win);
}

- Raw text -


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