[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: possible undefined behaviour in openldap-19981116



On Mon, Dec 07, 1998 at 23:07:12 +0100, Jorg Pietschmann wrote:
> Hi,
> 
> there are quite some occurances where strcpy is applied to
> overlapping, source and desitnation, like this from slapd/config.c
> (strtok_quote):
> 
>  strcpy( next, next + 1 );
> 
> I don't have the standard right in front of me but i vaguely remember
> that this may lead to undefined behaviour. In order to be on the
> sure side, a test might be added to configure whether this really
> works.

ISO/IEC 9899, i.e. the ISO (and ansi) C standard has the following
sentence in section 7.11.2.3 about strcpy:

   "If copying takes place between objects that overlap, the
    behavior is undefined."

Suggestion: use memmove instead.

- Erik