www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/29/01:46:09

Date: Mon, 29 Apr 1996 08:33:57 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Jag <gaghon AT nevada DOT edu>
Cc: Samuel Vincent <svincent AT zippy DOT sonoma DOT edu>, djgpp AT delorie DOT com
Subject: Re: problem with DJGPP and arrays.
In-Reply-To: <Pine.OSF.3.91.960427095740.31084A-100000@pioneer.nevada.edu>
Message-Id: <Pine.SUN.3.91.960429082409.472C-100000@is>
Mime-Version: 1.0

On Sat, 27 Apr 1996, Jag wrote:

> > Could you post the contents of function read_t2?
> > 
> 
> void fread_t2(char p_a, char *s_a, int l_c)    /* read x amount of bytes */
> {                                          /* start_addr, string, count */
>   int handle, l_a;
>   handle = _open( s_a, 0);
>   if (handle != -1)
>   {
>     l_a = _read(handle, p_a, l_c);

If the above is the EXACT copy of the actual source, then the problem is 
that you tell `fread_t2' that the address of the buffer is a char, when 
it should be a pointer to char.  That is, you should write this:

	void fread_t2 (char *p_a, char *s_a, int l_c)

(I also suggest making `l_c' a size_t, but that's another story).  The 
way you did it, `fread_t2' gets a pointer (&table[0]) which is 
32bit-wide, but because it thinks the first argument is a char 
(8bit-wide) it takes its least-significant byte and passes it to `_read' 
as an address of a buffer to move data to.  Chances are this address is 
outside your address space, and the `__dj_movedata' (which is a low-level 
function that actually moves the data being read to the buffer pointed to 
by that address) gets blown off by the memory protection.

When you add other arrays, you change the addresses in a way that can 
make the least-significant byte be a legal address, but I doubt that the 
data ends up where you think it should be even then.

- Raw text -


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