delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/09/03/04:18:14

Subject: RE: Non-compliant strxfrm
MIME-Version: 1.0
Date: Wed, 3 Sep 2003 09:15:37 +0100
content-class: urn:content-classes:message
X-MimeOLE: Produced By Microsoft Exchange V6.0.4417.0
Message-ID: <F1A9C8D7A58D1B45A9C16FE7E3DA83D7021892@server.HME.hme.ltd.uk>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: Non-compliant strxfrm
Thread-Index: AcNxdwxzfU/rWx4TTSu60qLSP2txhQAeuKeg
From: "Melvin Curran" <Melvin AT HME DOT Ltd DOT uk>
To: "DJ Delorie" <dj AT delorie DOT com>
Cc: <djgpp-workers AT delorie DOT com>
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id h838Ffr17761
Reply-To: djgpp-workers AT delorie DOT com

> -----Original Message-----
> From: DJ Delorie [mailto:dj AT delorie DOT com]
> > Thanks, but I think this needs some further work, since 
> this fragment:
> > 
> >      if (--n)
> >        *dst++ = c;
> > 
> > seems to dereference dst even if n is zero.  The standard forbids
> > that, see our prior discussions in this thread.
> 
> No, it can't.  That case is already detected in the preceeding if:
> 
>     if (n < 2)
>     {
>       while (*src++ != 0)
>         r++;
>       break;
>     }
>     if (--n)
>       *dst++ = c;
> 

Looking at this bit of code again, because of that first if statement
the second will always evaluate true, so we could get rid of the
second if by changing it to:

	--n;
	*dst++ = c;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019