From: Daniel Barker Newsgroups: comp.os.msdos.djgpp Subject: Re: Is that bug ? Date: Sun, 7 Feb 1999 01:36:17 +0000 Organization: Edinburgh University Lines: 45 Message-ID: References: <36BC27D0 DOT 41C67EA6 AT uic DOT rnd DOT runnet DOT ru> NNTP-Posting-Host: holyrood.ed.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: scotsman.ed.ac.uk 918351249 14372 129.215.38.17 (7 Feb 1999 01:34:09 GMT) X-Complaints-To: usenet AT scotsman DOT ed DOT ac DOT uk NNTP-Posting-Date: 7 Feb 1999 01:34:09 GMT In-Reply-To: <36BC27D0.41C67EA6@uic.rnd.runnet.ru> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Sat, 6 Feb 1999, George Lugovoy wrote: > I has a program: > > ////////////////////////////////////////////////////////////////////// > #include > > int main( void ) > { > char buffer[1024]; > memcpy( buffer, NULL, sizeof( buffer ) ); > return 0; > } > ////////////////////////////////////////////////////////////////////// > > Under DOS, Unix that program is crashed, BUT > under Windows that program won't crash. > What is it ? Is that bug ? The program has undefined effect. It's trying to read 1024 bytes of memory starting at the address NULL, which is an invalid address. Such bugs typically have different effects on different systems. As I understand it, the system is allowed (in the definition of the C language) to respond however it likes. However, I think that running the above program through the debugger GDB will reveal the error, on any system. Another problem is that memcpy() is not declared in . memcpy() is declared in . This could lead to trouble on some systems, due to accidental casting of pointers to integers. Although NULL is defined in DJGPP's header , Kernighan & Ritchie (2nd edition) says it is defined in . So, to be portable, you should probably include both and , in addition to fixing the main bug in the program. Daniel Barker, Institute of Cell and Molecular Biology, Swann Building, King's Buildings, Mayfield Road, Edinburgh EH9 3JR UK