Current-Users archive

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

Re: Possible unsafe use of strncat in sbin/sysctl/sysctl.c

On Tue, Aug 23, 2011 at 11:52:11PM +0200, Marc Balmer wrote:
> Am 23.08.11 23:44, schrieb Jimmy Johansson:
> > On Tue, Aug 23, 2011 at 11:29:32PM +0200, Marc Balmer wrote:
> >> Am 23.08.11 23:23, schrieb Jimmy Johansson:
> >>> Hi,
> >>>
> >>>
> > 
> > [snip, patch that makes eyes bleed]
> > 
> >>
> >> I don't like how functions, which return values are ignored, are casted
> >> to (void).
> >>
> >> Who invented that idiom?  What is that good for, other than making your
> >> eyes bleed?
> >>
> >> I think it is no more than quieting cc or lint.
> > 
> > I don't care either way, but it seems to be the suggested way to write
> > code for NetBSD according to KFN. I even think that it mentioned casting
> > return values from functions where you didn't handle the return value
> > specifically at some point, but it doesn't do so now.
> > 
> > I don't want the eyes of anymore NetBSD developer to bleed though, so
> > new patch. :-)
> (void)wait!  That was a pure personal remark.  I really don't know where
> that (void)bla idiom comes from, and I obviously don't (void)like it.
> Some folks seems to (void)love it.

I understood and didn't take offence. I try to do what the code does and
saw snprintf casted to void, but then I realized, after reading your
response that no other strlcat was casted to void, so the second patch
might be better.

I usually cast to void if the code I'm modifying does that, otherwise

I can sort of see that it might give a person modifying a piece of code
some information like "ok, the person that wrote this bit of code has
read the manpage at least far enough to know that the function returns a
value and then chose to not handle it".

I guess it comes down to personal preference, and discussing stuff like
that on a mailing list tend to get religious pretty fast! :-)

[snip, other patch]


If you don't shoot the bearers of bad news, people will keep bringing it to you.

Home | Main Index | Thread Index | Old Index