Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Jim Meyering
Richard Guenther wrote: ... >>> The patch is ok with caching strlen and using memcpy. >> >> Like this, I presume: >> [alternatively, declare and compute m_len on a separate line, >>  just before the comparison: >>   size_t m_len = strlen (m->name); >>  I'd actually prefer that, but don't know if de

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Richard Guenther
On Thu, Apr 19, 2012 at 3:01 PM, Jim Meyering wrote: > Richard Guenther wrote: >> On Thu, Apr 19, 2012 at 2:13 PM, Jim Meyering wrote: >>> Richard Guenther wrote: On Thu, Apr 19, 2012 at 12:42 PM, Jim Meyering wrote: > Found by inspection. > Seeing this strncpy use without the usual

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Jim Meyering
Richard Guenther wrote: > On Thu, Apr 19, 2012 at 2:13 PM, Jim Meyering wrote: >> Richard Guenther wrote: >>> On Thu, Apr 19, 2012 at 12:42 PM, Jim Meyering wrote: Found by inspection. Seeing this strncpy use without the usual following NUL-termination, my reflex was that it was a

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Jakub Jelinek
On Thu, Apr 19, 2012 at 02:38:11PM +0200, Richard Guenther wrote: > On Thu, Apr 19, 2012 at 2:34 PM, Jakub Jelinek wrote: > > On Thu, Apr 19, 2012 at 02:31:37PM +0200, Richard Guenther wrote: > >> That's better.  Or even cache the strlen result and use memcpy here > >> as Jakub suggested. > > > >

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Richard Guenther
On Thu, Apr 19, 2012 at 2:34 PM, Jakub Jelinek wrote: > On Thu, Apr 19, 2012 at 02:31:37PM +0200, Richard Guenther wrote: >> That's better.  Or even cache the strlen result and use memcpy here >> as Jakub suggested. > > tree-ssa-strlen.c will do that for you when optimizing in this case ;) Does i

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Jakub Jelinek
On Thu, Apr 19, 2012 at 02:31:37PM +0200, Richard Guenther wrote: > That's better. Or even cache the strlen result and use memcpy here > as Jakub suggested. tree-ssa-strlen.c will do that for you when optimizing in this case ;) Jakub

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Richard Guenther
On Thu, Apr 19, 2012 at 2:13 PM, Jim Meyering wrote: > Richard Guenther wrote: >> On Thu, Apr 19, 2012 at 12:42 PM, Jim Meyering wrote: >>> Found by inspection. >>> Seeing this strncpy use without the usual following NUL-termination, >>> my reflex was that it was a buffer overrun candidate, but t

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Jim Meyering
Richard Guenther wrote: > On Thu, Apr 19, 2012 at 12:42 PM, Jim Meyering wrote: >> Found by inspection. >> Seeing this strncpy use without the usual following NUL-termination, >> my reflex was that it was a buffer overrun candidate, but then I >> realized this is gcc, so that's not very likely. >>

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Jakub Jelinek
On Thu, Apr 19, 2012 at 02:01:36PM +0200, Richard Guenther wrote: > strncpy -> strcpy definitely looks like premature optimization to me. I disagree. Almost all uses of strncpy are wrong. If the string length is smaller, than it is unlikely useful that it clears all remaining bytes (sometimes ma

Re: [PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Richard Guenther
On Thu, Apr 19, 2012 at 12:42 PM, Jim Meyering wrote: > Found by inspection. > Seeing this strncpy use without the usual following NUL-termination, > my reflex was that it was a buffer overrun candidate, but then I > realized this is gcc, so that's not very likely. > Looking a little harder, I saw

[PATCH] genmodes: remove misleading use of strncpy

2012-04-19 Thread Jim Meyering
Found by inspection. Seeing this strncpy use without the usual following NUL-termination, my reflex was that it was a buffer overrun candidate, but then I realized this is gcc, so that's not very likely. Looking a little harder, I saw the preceding strlen >= sizeof buf test, which means there is no