[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Re: problem with strncpy

On Fri, Mar 21, 2003 at 11:26:40AM +0100, Markus Bernhardt wrote:
> Hi Bob,
> thanks for your comment.
> First, we are not calling this function zillion of times, only about 20 times.
> But the problem occured only after doing some hours some other things.
> We added the loop 
> > for(i = 0; i < TABLE_NAME_LENGTH; i++) {
> >   table->name[i] = ?\0?;
> > }
> for debugging.
> (We now replaced that for debugging by: bzero(table->name,TABLE_NAME_LENGTH);)

bzero() is deprecated these days in favour of memset().

> But you are right with your suggestion:
> > Whenever I see it in a code review I almost invariably find it there
> > by mistaken understanding of what it does.
> Never read about that 'feature' of strncpy.

No, it was news to me too.  Very interesting that, because it could be a
real performance killer, if the size of the buffer is large.


Dr Tim Cutts
Informatics Systems Group
Wellcome Trust Sanger Institute, Hinxton, Cambridge, CB10 1SA, UK

Reply to: