RE: ANSI standards


Subject: RE: ANSI standards
From: James Montgomerie (jamie@montgomerie.net)
Date: Mon Jan 24 2000 - 06:20:25 CST


> -----Original Message-----
> From: owner-abiword-dev@abisource.com
> [mailto:owner-abiword-dev@abisource.com]On Behalf Of Henrik Berg
> Sent: 24 January 2000 11:05
> Subject: RE: ANSI standards
>
>
> > Ah! I see what you mean. Is there any way around it though?
> If I check
> > the length of the string, either by using strlen(), or a
> routine of my own
> > making, won't it break on non-null-terminated strings too (the
> only way I
> > can see of doing it is to loop through the string until I find a NULL)?
>
> No, please don't. Think of this:
>
> char *str1 = "Ahrrrrggggg... -> 1000 mor chars";
> char *str2 = "Not like str1";
> strcmp(str1, str2);
>
> In this case strcmp compares one char with an other and returns.
> Adding a strlen, adds length of str1 itterations (plus length of str2).

I agree, it would be rather inefficient (and strcmp is probably performed a
lot in a word processor).

> I don't think you are missing anything. Checking the length is
> not needed it you don't write to the buffer. If out write oyou
> can overshoot the end of string and go into segfault country, but
> reading allways ends on the nul char. If someone uses strcmp
> he/she must input nul terminated stings (at least the shortest :)

Yes. Even if there was an efficient way to check that the strings were
NULL-terminated, we'd only be storing up problems for later we should never
be comparing non-NULL-terminated strings. If we are, something's already
broken).

Jamie.



This archive was generated by hypermail 2b25 : Mon Jan 24 2000 - 06:17:39 CST