www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/26/03:52:15

From: Luke Lee <comforth AT ms2 DOT hinet DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: ??? LIBC BUG ??? int write(...)
Date: Wed, 26 Feb 1997 15:14:51 +0800
Organization: Computing Center, Academia Sinica
Lines: 68
Message-ID: <3313E2EB.3D97@ms2.hinet.net>
Reply-To: comforth AT ms2 DOT hinet DOT net
NNTP-Posting-Host: @140.109.249.56
Mime-Version: 1.0
CC: comforth AT ms2 DOT hinet DOT net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi, 
   After a looooong debugging, I've found such a problem : INCORRECT
   size written to a file with 'int write(...)' function !!! Could  
   this be libc's bug ? Or anything wrong in my program ?

   Here is a testing program which have been tested under :
    1. Win95 DOS 7.0
    2. Win95 DOS box
    3. DOS 6.22
   And the results are all the same :

**** PART I : SOURCE ****

// ---------------------  START  BUG.CC  -----------------------------
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>

char garbage[96679];

int main(void)
{  int fd, size;
   // correct -------------------------------
     fd = creat("newfile1",S_IRUSR|S_IWUSR);
     printf(" fd = %d ; ", fd );
     size = write( fd, garbage, 96679 );
     printf(" size = %d\n" , size );
     close( fd );
   // error ! -------------------------------
     fd = creat("newfile2",S_IRUSR|S_IWUSR);
     printf(" fd = %d ; ", fd );
     size = write( fd, (char*)&main, 96679 );  // <<<<----- HERE !!
     printf(" size = %d\n" , size );
     close( fd );
   return 0;
}
// ---------------------  END  BUG.CC  -----------------------------

**** PART II : compile ****

  Compile it with   gcc bug.cc -o bug -Wl,-Map,bug.map
  then execute bug.exe :

**** PART III : execute ****

G:/GCC/TEST>bug.exe
 fd = 5 ;  size = 96679
 fd = 5 ;  size = 96679

  Ok, this is fine, let's see the dir result :
G:/GCC/TEST> DIR NEWFILE*
 ......
 Directory of G:\GCC\TEST
NEWFILE1            96,679  02-26-97  14:53 NEWFILE1
NEWFILE2            96,820  02-26-97  14:53 NEWFILE2   <<<--- HERE !!
         2 file(s)        193,499 bytes

**** PART IV : Question ?  ****

   ????? How could this be possible ????
   Anyway, this might due to a '.text' address writing, ok, let's see
   bug.map , I found that the (&main + 96679) never exceed '_end' .
   Could anyone tell me what's going on ? Aren't '.text' and '.data'
   all map to the same linear address ? Even if not, how could 'size'
   be different ?

- Luke -

- Raw text -


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