TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: R.WIESER
from: RICHARD HEATHFIELD
date: 2019-02-24 18:19:00
subject: Re: C is not a low level

On 24/02/2019 16:21, R.Wieser wrote:
> (too many newsgroups, had to snip a few)

(Sorry, didn't notice. But you left comp.programming in, so we're good.)

>
> Richard,
>
>> Indeed, although I'd cache the length rather than make the compiler find
>
> :-) And thats exactly the kind of thing you should try to avoid.
>
> In this simple example it will work, but you're /still/ trying to write a
> full buffers worth - when you should leave that last character untouched,
> just in case.

That last character is the null terminator. Given the choice, that's how
I like my strings to end. :-)

Okay, so that's so obvious a retort that I have to deduce you meant
something else, but I don't know what. Care to explain for the benefit
of my befuddled grey cells?

>
> Ofcourse, I would rather check the length of the to-be-copied string and
> throw an error when it doesn't fit, but maybe thats just me ... (Just
> imagine you're copying some kind of commandline string, with a few argument
> switches at the end).

Reporting an error is certainly preferable to undefined behaviour, but I
would prefer to grab the data - all of it - if that's possible and
reasonable.

(There may be times when it's *not* reasonable to try to grab all the
data - for example, if someone is deliberately throwing
complete-Shakespeare-in-one-line at you over and over again in an
attempt to make you consume the whole of memory. So of course you have
to do your threat assessment: is the program going to be used in a
context where this sort of thing is likely? If so, you need some rules
for how much data is to be considered acceptable.)

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.