delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/09/02/09:36:26

Subject: RE: Non-compliant strxfrm
MIME-Version: 1.0
Date: Tue, 2 Sep 2003 14:36:13 +0100
content-class: urn:content-classes:message
X-MimeOLE: Produced By Microsoft Exchange V6.0.4417.0
Message-ID: <F1A9C8D7A58D1B45A9C16FE7E3DA83D7021890@server.HME.hme.ltd.uk>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: Non-compliant strxfrm
Thread-Index: AcNxU5QFz9VeiYoUR96vO74kKLcSgAAAi7UQ
From: "Melvin Curran" <Melvin AT HME DOT Ltd DOT uk>
To: <djgpp-workers AT delorie DOT com>
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id h82DaJY09535
Reply-To: djgpp-workers AT delorie DOT com

>If dst points to invalid memory there is little we can do about it.
>The OS will detect any access faults automatically.  Letting it do
>that is what most of the other libc functions do.

In that case, a couple of minor changes to the function and we are
left with the function below.

size_t
strxfrm(dst, src, n)
     char *dst;
     const char *src;
     size_t n;
{
  size_t r = 0;
  int c;

  while ((c = *src++) != 0)
  {
    r++;
    if (n < 2)
    {
      while (*src++ != 0)
        r++;
      break;
    }
    if (--n)
      *dst++ = c;
  }
  if (n)
    *dst = 0;
  return r;
}

- Raw text -


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