🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.linux.help
Article #4

Re: strncpy bug?

#4
From: Jochen Schoof
Date: Thu, 14 Mar 1996 11:43
38 lines
2279 bytes
Christopher W. Curtis (ccurtis@ee.fit.edu) wrote:
: I was wondering if this is a Linux thing (kernel 1.2.1) or a
: more general 'problem'.  If you call strncpy as such:
: 	strncpy( dest, NULL, x );
: it will seg fault.  Is this common among all platforms, or
: just with Linux?
:
: The man page says nothing about it, but I would have presumed
: that if str[n]cpy were passed NULL as a source, it would
: merely catenate the destination.  Did I presume wrong?

My man page says:

       The  strcpy() function copies the string pointed to be src
       (including the terminating `\0' character)  to  the  array
       pointed  to by dest.  The strings may not overlap, and the
       destination string dest must be large  enough  to  receive
       the copy.

       The  strncpy()  function  is similar, except that only the
       first n bytes of src are copied.

When passing NULL as the src pointer, it definetly does not reference
a string. Therefore NULL is not a legal parameter to strcpy() and
strncpy(). Your expectation of what should happen is true for the
empty string (i.e. ""), but this is completely different from NULL.

- Jochen

--
--------------------------------------------------------------------------
 Jochen Schoof                  mailto:schoof@informatik.uni-wuerzburg.de
 Lehrstuhl fuer Informatik II +-------------------------------------------
 Universitaet Wuerzburg       | You are just reading a .sig-light:
 D-97074 Wuerzburg (Germany)  | It is free of fat, sugar and cholesterol!
------------------------------+-------------------------------------------
 WWW-Homepage:        http://www.informatik.uni-wuerzburg.de/staff/joscho
--------------------------------------------------------------------------
Technical Details
Message-ID: <4i90oq$a3a@winx03.informatik.uni-wuerzburg.de>
Path: arc1-ca.pugleaf.net!uni-erlangen.de!winx03!sunshine!schoof
References: <ccurtis.826776589@ee.fit.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!uni-erlangen.de!winx03!sunshine!schoof
From: schoof@informatik.uni-wuerzburg.de (Jochen Schoof)
Newsgroups: comp.os.linux.help,comp.lang.c
Subject: Re: strncpy bug?
Followup-To: comp.os.linux.help,comp.lang.c
Date: 14 Mar 1996 11:43:22 GMT
Organization: University of Wuerzburg, Germany
Message-ID: <4i90oq$a3a@winx03.informatik.uni-wuerzburg.de>
References: <ccurtis.826776589@ee.fit.edu>
NNTP-Posting-Host: wi2x01.informatik.uni-wuerzburg.de
X-Newsreader: TIN [version 1.2 PL2]