Article View: comp.os.linux.help
Article #5Re: strncpy bug?
From: Tanmoy Bhattacharya
Date: Thu, 14 Mar 1996 15:25
Date: Thu, 14 Mar 1996 15:25
32 lines
1912 bytes
1912 bytes
In article <ccurtis.826776589@ee.fit.edu> ccurtis@ee.fit.edu (Christopher W. Curtis) writes: <snip> CWC: I was wondering if this is a Linux thing (kernel 1.2.1) or a CWC: more general 'problem'. If you call strncpy as such: CWC: strncpy( dest, NULL, x ); CWC: it will seg fault. Is this common among all platforms, or CWC: just with Linux? CWC: CWC: The man page says nothing about it, but I would have presumed CWC: that if str[n]cpy were passed NULL as a source, it would CWC: merely catenate the destination. Did I presume wrong? Yes. The standard library functions should usually always be passed pointers which actually point to objects of appropriate types. A null pointer points nowhere: and is therefore invalid in most of these contexts. In this context, you may pass the constant string "" instead. Some library functions specifically allow you to pass in null pointers: that is obviously different. Cheers Tanmoy -- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242) Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544 Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>, <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/ internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html> fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID:
<TANMOY.96Mar14082504@qcd.lanl.gov>Path:
arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoyReferences:
<ccurtis.826776589@ee.fit.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) Newsgroups: comp.os.linux.help,comp.lang.c Subject: Re: strncpy bug? Date: 14 Mar 1996 15:25:04 GMT Organization: Los Alamos National Laboratory Message-ID: <TANMOY.96Mar14082504@qcd.lanl.gov> References: <ccurtis.826776589@ee.fit.edu> NNTP-Posting-Host: qcd.lanl.gov Mime-Version: 1.0 Content-Type: text In-reply-to: ccurtis@ee.fit.edu's message of Thu, 14 Mar 1996 04:09:49 GMT