Article View: borland.public.cppbuilder.nativeapi
Article #16344Re: Are nulls required to make buffers strings?
From: Bill Carson
Date: Sat, 17 May 2003 02:05
Date: Sat, 17 May 2003 02:05
41 lines
2786 bytes
2786 bytes
Gambit: Thanks for your detailed reply to my query. You have confirmed most of my suspicions regarding the actions of ReadFile(), but I still have some nagging questions. >ReadFile() doesn't do anything with the data it reads. It is a straight >copy-to-memory operation, copying from the file into your memory buffer. >Whether or not the file data being read contains its own nulls, that is a >completely different issue. It is my understanding that ReadFile() is the same as the ANSI C fread() function. Therefore, ReadFile() does a straight binary read from the file into the memory buffer, given whatever size of bytes is asked for. So, ReadFile() has no way to tell if it has read a null character, which may or may not be in the byte stream it reads. Thus, as you said: >If the null is not present in the buffer, then SetWindowText() >will just keep reading from memory until it finally encounters >a null, or until it crashes with an access violation. Either >way, you'll be allowing SetWindowText() to potentially go outside >the bounds of your buffer, thus producing undefined results. But, after I took out the statements to append the null character to the buffer in the Petzold code, I tested it by reading several different text files to see if would crash and it didn't. I fully expected it to crash on at least one of the files I read, so that is why I started questioning what exactly was going on. Now the question I have is when a string is written to a file, does the null character also get written to the file. And if so, what is its binary form. That is, does the file maintain the sequence of strings written to it? I will continue with my research into these matters. Thanks, Bill
Technical Details
Message-ID:
<3ec5990b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ec53c62@newsgroups.borland.com> <3ec54163$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ba9583b134269b63 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-16 19:12:05 PST From: "Bill Carson" <bcarson892003atyahoodotcom> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ec53c62@newsgroups.borland.com> <3ec54163$1@newsgroups.borland.com> Subject: Re: Are nulls required to make buffers strings? Date: Fri, 16 May 2003 19:05:36 -0700 Lines: 43 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 NNTP-Posting-Host: 66.119.208.120 Message-ID: <3ec5990b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1053137163 66.119.208.120 (16 May 2003 19:06:03 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail