Re: safe strcpy()?

From: Ben Pfaff (blpat_private)
Date: Wed Jan 29 2003 - 15:40:16 PST

  • Next message: Ed Carp: "Re: safe strcpy()?"

    "Michael Howard" <mikehowat_private> writes:
    
    > The point I'm making is people seem to think they can write crap code,
    > then bindly replace the calls to strcpy with strncpy and all of a sudden
    > their code is safe.  [...]
    
    The usual reason cited not to use strncpy() is that it doesn't
    necessarily null-terminate its output buffer.  But there's at
    least one other reason: using strncpy() into a large buffer can
    be very inefficient.  strncpy() always writes to every byte in
    the destination buffer, which can waste a lot of time if the
    destination buffer is much longer than the source string.
    
    As a result, strncpy() is hardly ever the right function to use.
    strlcpy() from OpenBSD is usually a better choice.
    -- 
    "If a person keeps faithfully busy each hour of the working day, he
     can count on waking up some morning to find himself one of the
     competent ones of his generation."
    --William James
    



    This archive was generated by hypermail 2b30 : Wed Jan 29 2003 - 15:56:01 PST