git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Implement safe_strncpy() as strlcpy() and use it more. [Take 2]

From
RRRocco Rutte <pdmef@gmx.net>
Date
Jun 11, 2006, 12:33 UTC
Message-ID
<20060611123332.GA3832@robert.daprodeges.fqdn.th-h.de>
In-Reply-To
<20060611120328.GC10430@bohr.gbar.dtu.dk>
Hi,
* Peter Eriksen [06-06-11 14:03:28 +0200] wrote:
Show 6 quoted lines
>-char *safe_strncpy(char *dest, const char *src, size_t n)
>+size_t safe_strncpy(char *dest, const char *src, size_t size)
> {
>-	strncpy(dest, src, n);
>-	dest[n - 1] = '\0';
>+	size_t ret = strlen(src);

At least FreeBSD's strlen() requires a non-NULL argument, i.e. with src==NULL, this will segfault.

If you can ensure that src!=NULL, then it's okay, but the safe_ prefix implies something different.

   bye, Rocco
-- 
:wq!
Previous: Peter EriksenNext: Peter Eriksen
Message 2 of 3 in “Implement safe_strncpy() as strlcpy() and use it more. [Take 2]”
  1. Implement safe_strncpy() as strlcpy() and use it more. [Take 2]Peter Eriksen, Jun 11, 2006
  2. Rocco RutteJun 11, 2006
  3. Peter EriksenJun 11, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.