gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Emgergency release of tla-1.2.1pre1


From: Matthieu Moy
Subject: Re: [Gnu-arch-users] Emgergency release of tla-1.2.1pre1
Date: Sun, 18 Apr 2004 10:56:35 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (gnu/linux)

Aaron Bentley <address@hidden> writes:

> strncpy isn't supposed to NUL-terminate the string.  The Linux man
> page reads:

Hmm, sorry. I said "a strncpy implementation" to mean "a function that
looks like strncpy, but here it is

/*(c str_cpy_n)
 * t_uchar * str_cpy_n (t_uchar * to,
 *                      const t_uchar * from,
 *                      size_t n);
 *
 * Copy up-to `n' characters from `from' to `to'.
 *
 * Add a final 0 to `to'.
 *
 * \Warning:/ This function is different from `strncpy'.  `strncpy'
 * always stores exactly `n' characters in `to', padding the result
 * with 0 if a 0 character is encountered in `from' before `n'
 * characters are written.  This function stores up to `n+1' characters:
 * up to `n' non-0 characters from `from', plus a final 0. 
                                           ^^^^^^^^^^^^^^^
 *
 * Returns `to'.
 */
t_uchar *
str_cpy_n (t_uchar * to,
           const t_uchar * from,
           size_t n)
{
  t_uchar * answer;

  answer = to;
  if (from)
    {
      while (n && *from)
        {
          *to++ = *from++;
          --n;
        }
      *to = 0; // Added by me.
    }
  while (n--)
    *to++ = 0;
  return answer;
}

I realize that the bug is in hackerlab, not tla, so I'll also submit a
bug report there.

> Perhaps you should NUL-terminate at the call site instead.

That's a temporary solution if you don't want to modify hackerlab, but
the bug is not there.

--
Matthieu




reply via email to

[Prev in Thread] Current Thread [Next in Thread]