Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #163290

Re: memcpy with NULL pointer

From Manfred <noname@add.invalid>
Newsgroups comp.lang.c
Subject Re: memcpy with NULL pointer
Date 2021-11-03 17:46 +0100
Organization Aioe.org NNTP Server
Message-ID <sluede$u71$1@gioia.aioe.org> (permalink)
References <slgdn2$1v7q$1@gioia.aioe.org> <86ee84f70q.fsf@linuxsc.com> <ue195i-892.ln1@aretha.foo> <slu7mp$v2k$1@dont-email.me>

Show all headers | View raw


On 11/3/2021 3:52 PM, James Kuyper wrote:
> On 11/2/21 8:24 PM, Peter 'Shaggy' Haywood wrote:
>> Groovy hepcat Tim Rentsch was jivin' in comp.lang.c on Fri, 29 Oct 2021
>> 09:40 pm. It's a cool scene! Dig it.
>>
>>> Steve Keller <keller.steve@gmx.de> writes:
>>>
>>>> I wonder whether calling the mem* and str* functions with a NULL
>>>> pointer has defined bahavior if the count parameter is also 0,
>>>> like in this call
>>
>>    [Snip.]
>>
>>>> Since no memory access via the NULL pointer is done I'd assume
>>>> this should not result in undefined behavior.
>>>
>>> That's a plausible assumption but not one that the C standard
>>> supports.
>>
>>    But, of course, undefined behaviour could be perfectly benign. Just
>> don't count on it in every case.
> 
> "undefined behavior" means only that the C standard imposes no
> requirements - if some other document does impose requirements, it's
> fine to rely upon those requirements being met - so long as you know
> that the document has authority over all of the systems to which you
> might need to port your code. However, if you know of no such document,
> or at least none that has authority over a particular system of interest
> to you, you should not count on it, at all.
> 

Especially considering that it's easy enough to write you own memcpy 
that is robust against null pointers, although not heavily optimized.
On the other hand, aggressive optimization is the most likely motivation 
for the requirement of valid pointers in all cases.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

memcpy with NULL pointer Steve Keller <keller.steve@gmx.de> - 2021-10-29 11:08 +0200
  Re: memcpy with NULL pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-29 03:40 -0700
    Re: memcpy with NULL pointer Steve Keller <keller.steve@gmx.de> - 2021-10-29 23:06 +0200
      Re: memcpy with NULL pointer Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-29 14:23 -0700
      Re: memcpy with NULL pointer scott@slp53.sl.home (Scott Lurndal) - 2021-10-29 21:48 +0000
        Re: memcpy with NULL pointer Steve Keller <keller.steve@gmx.de> - 2021-11-23 09:58 +0100
      Re: memcpy with NULL pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-29 18:44 -0700
        Re: memcpy with NULL pointer Guillaume <message@bottle.org> - 2021-10-30 18:25 +0200
          Re: memcpy with NULL pointer Steve Keller <keller.steve@gmx.de> - 2021-11-23 10:26 +0100
            Re: memcpy with NULL pointer Dolores Filandro <dolfiland8@gmail.com> - 2021-12-20 13:32 -0800
              Re: memcpy with NULL pointer Öö Tiib <ootiib@hot.ee> - 2021-12-20 16:56 -0800
                Re: memcpy with NULL pointer Richard Damon <Richard@Damon-Family.org> - 2021-12-20 20:39 -0500
                Re: memcpy with NULL pointer Öö Tiib <ootiib@hot.ee> - 2021-12-20 18:31 -0800
    Re: memcpy with NULL pointer Peter 'Shaggy' Haywood <phaywood@alphalink.com.au> - 2021-11-03 11:24 +1100
      Re: memcpy with NULL pointer James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-11-03 10:52 -0400
        Re: memcpy with NULL pointer Manfred <noname@add.invalid> - 2021-11-03 17:46 +0100
      Re: memcpy with NULL pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-11-06 14:57 -0700

csiph-web