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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Introductory Presentations, especially aimed at C++ programmers! Date: Fri, 9 Dec 2016 09:35:21 +0100 Organization: A noiseless patient Spider Message-ID: References: <1905815374.502825168.454102.laguest-archeia.com@nntp.aioe.org> <87y3zq4t05.fsf@nightsong.com> <0ad2eb12-421f-4159-8df2-5bf7e0dddf06@googlegroups.com> <87mvg551pi.fsf@nightsong.com> Reply-To: nonlegitur@notmyhomepage.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 9 Dec 2016 08:34:00 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8ad6b981c4b88663b1b5325f7a4ccd25"; logging-data="3308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Jm8zM9IvbqxnsMxxvTZWfmAZPYckHpxw=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 In-Reply-To: <87mvg551pi.fsf@nightsong.com> Cancel-Lock: sha1:afNinlnYt3+Ua4EsRKEqeIwMdlk= Xref: news.eternal-september.org comp.lang.ada:32690 Date: 2016-12-09T09:35:21+01:00 List-Id: On 09.12.16 02:30, Paul Rubin wrote: > I would say that C++ is stronger in this area than Ada, since it has > dynamically sized strings in the STL container library. You'd use those > instead of fixed-size buffers, so there's no way to overflow except OOM. But can you pass std::string to the functions of Win32? (I'm curious about the specifics in this example, since, e.g., RegQueryValueEx has a usage protocol associated with it and seems to not produce an overflow of the BYTE far* buffer.) Also, I think that the STL still requires discipline when one uses indexing. This little playground can produce a number of results that only prompt a cliché: "any competent programmer will avoid any of these mistakes"... void reorder(std::string& s) { using str = std::string; const str::const_iterator right_end = s.end(); const str::const_reverse_iterator left_end = s.rend(); str::iterator lr; str::reverse_iterator rl; for (lr = s.begin(), rl = s.rbegin() - 1; lr != right_end && rl != left_end; lr += 2, rl += 2) // or try `rl -= 2` { *(lr + 2) = *lr; *(rl + 2) = *rl; // and `rl - 2` } } Segfaults, null characters, and some harder to test algorithmic errors, depending on variation. -- "HOTDOGS ARE NOT BOOKMARKS" Springfield Elementary teaching staff