delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/29/22:49:42

From: richard AT NOSPAMstardate DOT bc DOT ca (Richard Sanders)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What's wrong????
Date: Tue, 30 Dec 1997 02:10:10 GMT
Organization: Rapidnet Technologies Internet
Lines: 41
Message-ID: <34a8571c.1477842@news.rapidnet.net>
References: <34A6E7A9 DOT 35B1E68D AT usa DOT net>
NNTP-Posting-Host: wlp21.rapidnet.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Mon, 29 Dec 1997 00:58:33 +0100, Rune Lanton
<please DOT mail DOT me AT usa DOT net> wrote:


->#include <stdio.h>
->
->void main(arg_counter, arg_pointers)
->int arg_counter;
->char *arg_pointers[];
->{
->
->FILE *file_pointer;
->char *file_buffer;
->int file_number;
->long int file_size;
->unsigned char end_of_file;
->char *search_word_ptr;
->char *text_ptr;
->long int word_match;
->long int a,b,c,d;
->int search_word_length;
->long int mid_match;
->char *e;
->
->file_pointer = fopen(arg_pointers[1], "rb");
->
->file_number = fileno(file_pointer);
->file_size = (filelength(file_number)) + 256;
->*file_buffer = malloc((file_size)+512);
->
->fread(file_buffer, 1, file_size, file_pointer);  <----- This is were
->it crashes!!!!
->fclose(file_pointer);
>

Hi;
   I think the problem lays with the read, tryimg to read 256 bytes
past the end of the file. 

Try
fread(file_buffer, 1, file_size-256, file_pointer);

- Raw text -


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