[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new module 'strlcpy'
From: |
Jim Meyering |
Subject: |
Re: new module 'strlcpy' |
Date: |
Wed, 27 Sep 2017 17:59:45 -0700 |
On Wed, Sep 27, 2017 at 5:44 PM, Bruno Haible <address@hidden> wrote:
> I wrote:
>> In some places the users
>> will notice that strlcpy does not buy them much, compared to the
>> "avoid arbitrary limits"[1] approach, and will switch over to what
>> you call "GNU style". In other places, they will insert an abort()
>> or assert() to handle the truncation case - which is *better* than
>> the strncpy approach.
>
> For example, in gnulib's setlocale.c override. This file has fixed-size
> buffers and silent truncation - because it uses the "strncpy and set NUL byte"
> approach. As soon as someone (me) will use strlcpy with __warn_unused_result__
> there, he will change the code to do
> - either dynamic allocation and no arbitrary limits,
> - or provide a good alternative to the silent truncation.
> Either result will be better than the current one.
I have to agree that we need something, and it may even be spelled
strlcpy. It seems reasonable to allow new uses of strlcpy, given a
__warn_unused_result__ attribute -- that should prevent those new
users from ignoring that return value. I developed a strong aversion
to strncpy, and wrote this about it:
https://meyering.net/crusade-to-eliminate-strncpy/
- [PATCH 1/6] parse-datetime, posixtm: avoid uninit access, Paul Eggert, 2017/09/25
- [PATCH 2/6] parse-datetime: fix dependency, Paul Eggert, 2017/09/25
- [PATCH 3/6] sys_types: update URL, Paul Eggert, 2017/09/25
- [PATCH 4/6] maint: fix overflow checking in nap.h, Paul Eggert, 2017/09/25
- [PATCH 5/6] duplocale-tests: fix unlikely crash, Paul Eggert, 2017/09/25
- new module 'strlcpy', Bruno Haible, 2017/09/27
- Re: new module 'strlcpy', Paul Eggert, 2017/09/27
- Re: new module 'strlcpy', Bruno Haible, 2017/09/27
- Re: new module 'strlcpy', Bruno Haible, 2017/09/27
- Re: new module 'strlcpy',
Jim Meyering <=
- Re: new module 'strlcpy', Bruno Haible, 2017/09/28
- Re: new module 'strlcpy', Paul Eggert, 2017/09/28
- Re: new module 'strlcpy', Paul Eggert, 2017/09/27
- Re: new module 'strlcpy', Dmitry Selyutin, 2017/09/28
- Re: new module 'strlcpy', Tim Rühsen, 2017/09/28
- Re: new module 'strlcpy', Paul Eggert, 2017/09/28
- Re: alternatives to 'strlcpy', Bruno Haible, 2017/09/28
- Re: alternatives to 'strlcpy', Dmitry Selyutin, 2017/09/28
- Re: alternatives to 'strlcpy', Paul Eggert, 2017/09/28
- Re: alternatives to 'strlcpy', Paul Eggert, 2017/09/28