From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news3.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeds.phibee-telecom.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Sun, 6 Feb 2011 17:49:43 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <31c357bd-c8dc-4583-a454-86d9c579e5f4@m13g2000yqb.googlegroups.com> <05a3673e-fb97-449c-94ed-1139eb085c32@x1g2000yqb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 6 Feb 2011 17:49:43 +0000 (UTC) Injection-Info: mx03.eternal-september.org; posting-host="4pjzwDT2MPp9AkNxUo/C4Q"; logging-data="30617"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AdsUrabAUkJfzKjT9r0NdQ0Whp6x/BA0=" User-Agent: slrn/0.9.8.1 (VMS/Multinet) Cancel-Lock: sha1:l6N2uBjHC6cggLn8aeNCRxD2tVM= Xref: g2news1.google.com comp.lang.ada:16897 Date: 2011-02-06T17:49:43+00:00 List-Id: On 2011-02-04, Ludovic Brenta wrote: > Ludovic Brenta wrote: >> Syntax Issues wrote on comp.lang.ada: >>> ... >>> unsigned int print(char *message, unsigned int line) >>> { >>> � � � � char *vidmem = (char *) 0xb8000; >>> � � � � unsigned int i= 0; >>> >>> � � � � i=(line*80*2); >>> >>> � � � � while(*message!=0) // 24h > > Did I mention that *every* time I look at C code I see a bug? > Sometimes, looking twice at the same code reveals two bugs! Here you > do not check that message != NULL; the condition should be: > > while (message && *message != 0) > That still isn't good enough unless you can guarantee that the compiler generated code will not evaluate the second condition if the first condition is false. The reason is that this code will attempt to examine the contents of address 0 when message is null and on some operating systems page 0 is unmapped in order to catch these kinds of bugs. Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world