From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fdb0e,cdca3dc8d6167cd4 X-Google-Attributes: gidfdb0e,public X-Google-Thread: f7344,a808e23c428d1184 X-Google-Attributes: gidf7344,public X-Google-Thread: 1164f8,cdca3dc8d6167cd4 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 2001-12-22 07:51:04 PST Date: Sat, 22 Dec 2001 16:51:22 +0100 Newsgroups: comp.os.vms,alt.sys.pdp10,comp.sys.dec Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va Organization: Home Message-ID: Subject: Re: Congratulations for the festive season From: Paul Sture Reply-To: paul.sture@bluewin.ch References: <1011221190540.59837B-100000@Ives.egh.com> NNTP-Posting-Host: 213.3.126.136 X-Trace: 22 Dec 2001 16:50:57 +0100, 213.3.126.136 X-Complaints-To: abuse@bluewin.ch Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.59.214.20!news-ge.switch.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!news.bluewin.ch!awk.sture.ch!nobody Xref: archiver1.google.com comp.os.vms:56804 alt.sys.pdp10:8629 comp.sys.dec:10166 In article <1011221190540.59837B-100000@Ives.egh.com>, John Santos wrote: > [snip] > This turns out not to be the case. Most VMS languages use counted > strings and the OTS routines that do string copies that check the > counts when copying to fixed-length buffers, and truncate and/or > warn you (but never, ever write past the end of the destination.) > This philosophy has been present since day one - ever notice the very > non-RISCy MOVC5 instruction in the VAX instruction set? > > Sure this hurts performance sometimes: you have to store, maintain, > check and pass around all those pesky counts, and you can't do the > cheap trick of copy bytes until you hit a in a tight loop. > Instead you have to compare source and destination sizes, set your > loop counter to the minimum, and copy. Sometimes you don't get > to stop early if the source string is short, since you may need to > fill the destination. On the other hand, is not a special > character in strings. (In-band flow control is generally a bad > idea.) > > But what's a few nano-seconds if it saves you hours of > crash/reboot/recovery time and debugging? Especially when the fix > is to manually insert code that does the same bounds checking, in > a less efficient manner? > Here's a point though. Those extra nano seconds mean that your subroutines (APIs, whatever), don't have to scan up a string themselves to determine its length. For any program dealing with fixed length records, determining the record length during its initialization phase means it's then available for any routine to use, for the program's execution lifetime. I'd suggest that the CPU consumed on a Windows machine continually scanning every buffer passed its APIs is probably many times greater than that used by a mechanism of passing the length (which you calculated once at the beginning anyway). Variable length records are only slightly harder - if you are constructing a variable string you likely know how long it is already, as part of the construction process. > Most (all?) exceptions to the above are in C programs that use > -terminated strings, and most of those were imported from > Unix, so I don't understand why the Unix users would be laughing. > I think they would be too busy fixing their own systems to be > worrying about others. > > Or maybe if the implementors of most of the public-domain software > (TCP/IP, etc., etc.) had grown up on VMS instead of Unix, they > would have been dismayed on discovering the lack of buffer overflow > protection in the usual C libraries and would have insisted on > (or implemented themselves) a standard set of counted string > functions that everyone would use, and would have soon acquired > direct support in ANSI C (for counted string literals and constants) > and buffer overflow attacks on Unix would be a thing of the past. Good point. ___ Paul Sture Switzerland