[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] maint: prohibit use of strncpy
From: |
Jim Meyering |
Subject: |
Re: [PATCH] maint: prohibit use of strncpy |
Date: |
Fri, 25 May 2012 17:21:25 +0200 |
Jim Meyering wrote:
> Eric Blake wrote:
>> On 05/24/2012 08:23 AM, Jim Meyering wrote:
>>> The use of strncpy is so seldom justifiable, that it is best
>>> just to avoid it altogether. Thus, we should enforce that:
>>>
>>>>From 22695d676de21d0af6d50ca8218eeb49b45608ab Mon Sep 17 00:00:00 2001
>>> From: Jim Meyering <address@hidden>
>>> Date: Thu, 24 May 2012 16:21:34 +0200
>>> Subject: [PATCH] maint: prohibit use of strncpy
>>>
>>> * cfg.mk (sc_prohibit_strncpy): New syntax-check rule.
>>> Exempt pinky.c and who.c, at least for now.
>>> ---
>>> cfg.mk | 9 +++++++++
>>> 1 file changed, 9 insertions(+)
>>>
>>> diff --git a/cfg.mk b/cfg.mk
>>> index 7a86c2a..ff5d996 100644
>>> --- a/cfg.mk
>>> +++ b/cfg.mk
>>> @@ -403,6 +403,12 @@ sc_prohibit_strncmp:
>>> { echo '$(ME): use STREQ_LEN or STRPREFIX instead of str''ncmp' \
>>> 1>&2; exit 1; } || :
>>>
>>> +# Really. You don't want to use this function.
>>> +sc_prohibit_strncpy:
>>> + @prohibit='\<str''ncpy *\(' \
>>> + halt='do not use str''ncpy, period' \
>>> + $(_sc_search_regexp)
>>
>>
>> This seems like it is worth floating into gnulib's maint.mk.
>
> That was my plan.
> I notice that libvirt has had a similar rule for a couple of years.
>
> This rule has two minor improvements over the one in coreutils:
> I removed the str''ncpy obfuscation, since it wasn't needed,
> and added comments.
BTW, thanks for the prod.
I had committed that locally for coreutils, but had not pushed.
So now I can just omit the rule addition, but I do need to keep
the exemption-adding part. Hmm... easier just to push both, I guess.