delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/22/12:52:10

Date: Thu, 22 Jan 1998 19:16:41 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Jamie Love <jamie DOT love AT clear DOT net DOT nz>
cc: DJGPP mailing list <djgpp AT delorie DOT com>
Subject: Re: whats wromg with my file program? - HELP!
In-Reply-To: <199801220709.UAA24275@fep1-orange.clear.net.nz>
Message-ID: <Pine.SUN.3.91.980122191348.1427V-100000@is>
MIME-Version: 1.0

On Fri, 23 Jan 1998, Jamie Love wrote:

> remdefs sprites.set
> I get the djgpp.env file!!! instead of the correct sprites.set file.
[snip]
>    if((length = fread(data, 1, length, inFile)) != -1)
>     {
>       printf("Error: unable to read %d bytes from %s", length, argv[1]);
>       return 0;
>     }
> 
>    printf("%s\n", data);

You are assuming that `fread' appends an extra `\0' (null) character to
the buffer after it reads the file.  This is false.  So when `printf'
looks for the trailing `\0', which %s format requires, it happily runs
beyond the end of data[] and prints what's left from the DJGPP.ENV
processing by the startup code. 

- Raw text -


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