*BSD News Article 50661


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!agis!ns2.mainstreet.net!bug.rahul.net!a2i!rahul.net!a2i!news.clark.net!usenet
From: alweiner@clark.net (Alan Weiner)
Newsgroups: comp.unix.bsd.bsdi.misc
Subject: Major bug?  (probably programmer error :)
Date: 4 Sep 1995 18:07:18 GMT
Organization: GRYPHON Microproducts
Lines: 37
Message-ID: <42ff8m$b3d@clarknet.clark.net>
NNTP-Posting-Host: alweiner.clark.net
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: WinVN NT 0.92.6

#include "stdlib.h"
#include "stdio.h"
#include <sys/types.h>
#include <fcntl.h>

struct
{
char buf[6];
} b;

void main()
{
int fd;
strcpy(b.buf,"hello");
fd=open("test.txt",O_RDWR|O_CREAT);
write(fd,&b,sizeof(b));
lseek(fd,-1L*sizeof(b),1);
write(fd,&b,sizeof(b));
close(fd);
system("ls -l test.txt\n");
}

Try running the following program on your BSDI system.  I think you'll be
supprized at the resulting test.txt.

Am I doing something illegal here?

--TAGLINE FOLLOWS
/--------------------------------------------------------------------\
|   A man said to the Universe: "Sir, I exist!"                      |
|   "However," replied the Universe,                                 |
|   "the fact has not created in me a sense of obligation."          |
|                                -- Stephen Crane                    |
\--------------------------------------------------------------------/
Visit the W3MAGIC page for info on how to make dynamic/
browser-adaptable WWW pages:
  http://www.clark.net/pub/alweiner/cgi-bin/homepage.cgi?w3magic