[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Kill strcpy and strcat
From: |
Bastien Nocera |
Subject: |
Re: [PATCH] Kill strcpy and strcat |
Date: |
Wed, 07 Nov 2007 13:34:06 +0000 |
On Wed, 2007-11-07 at 14:26 +0100, Pawel Kot wrote:
> Hi,
>
> On 11/7/07, Daniele Forsi <address@hidden> wrote:
> > Pawel Kot wrote to Bastien Nocera:
> >
> > > For strncpy() you need also to ensure, the destination string will be
> > > null-terminated. I'm working already for the patch for whole gnokii.
> >
> > there are SAFE_STRNCPY and SAFE_STRNCPY_SIZEOF in ./include/misc.h
> > I used SAFE_STRNCPY in ./common/phones/pcsc.c
>
> Maybe somebody could tell me if there is a difference between:
> snprintf(buf, sizeof(buf), "%s", some_string);
> and
> strncpy(buf, some_string, sizeof(buf));
> buf[sizeof(buf) - 1] = 0;
There shouldn't be a difference.
> That should do essentially the same thing, but maybe I'm missing
> something. I'd like to encourage one way doing this.
I mentioned this this morning, but IMO, it would be a good idea to have
a GString-style API to avoid fixed-sized buffers all around.
http://library.gnome.org/devel/glib/stable/glib-Strings.html
We could have a reduced version of that in gnokii, as helper APIs. Most
of the gnokii code using snprintf and co. seems to be appending with a
format, or appending single chars or strings.
A helper API with variable size buffers would avoid the store of
problems we've seen so far.
Cheers
- [PATCH] Kill strcpy and strcat, Bastien Nocera, 2007/11/06
- Re: [PATCH] Kill strcpy and strcat, Philip Kendall, 2007/11/07
- Re: [PATCH] Kill strcpy and strcat, Pawel Kot, 2007/11/07
- Re: [PATCH] Kill strcpy and strcat, Ian Collier, 2007/11/07
- Re: [PATCH] Kill strcpy and strcat, Pawel Kot, 2007/11/07
- Re: [PATCH] Kill strcpy and strcat, Pawel Kot, 2007/11/07