delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/29/21:18:03

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What's wrong????
Date: Mon, 29 Dec 1997 20:02:42 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 48
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <34A84832.CD2C01C@cornell.edu>
References: <34A6E7A9 DOT 35B1E68D AT usa DOT net>
NNTP-Posting-Host: cu-dialup-0041.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Rune Lanton wrote:
> 
> I wrote this little program in DJGPP, or at least I tried, but 
> something went wrong!!!!

for your own benefit, i would recommend using ANSI prototypes.

> This code you see here works just fine when I try to read small files,
> less than 1000 bytes I think, but when I try to read bigger files it
> doesn't work.
> WHY!!!!!!!
> 
> Here's the code:
> 
> #include <stdio.h>
> 
> void main(arg_counter, arg_pointers)
> int arg_counter;
> char *arg_pointers[];

like, using int main(int argc, char *argv[]) here would not hurt. there
is no guarantee that the non-ANSI style will continue to work. in any
case, i did not compile your program but your problem probably has to do
with file_buffer. file_buffer is an unitialized pointer. below, you do:

> *file_buffer = malloc((file_size)+512);

which converts the pointer returned by malloc into int (because you did
not include <stdlib.h> where malloc is declared. if you had done that
and turned on -Wall, you would have known about this) and writes these
four bytes into some unknown location depending on the value of
file_buffer (which you have not initialized.) that probably causes a
segmentation violation at random times.

if you had initialized file_buffer to NULL to begin with, and were
running under dos with cwsdpmi as your dpmi server, you would have
caught this error easily.

hth.

-- 
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA

mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/

- Raw text -


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