On Wed, Dec 20, 2017 at 10:35:44AM -0700, Martin Sebor wrote: > On 10/27/2017 07:17 AM, Martin Liška wrote: > > Hello. > > > > It's improvement that I consider still useful even though we're not > > going to use > > it for profiled bootstrap. > > > > Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. > > For what it's worth, although it looks correct as is, I think > the code in the patch would be clearer and less prone to off > by-1 errors, while at the same time equally as efficient, if > it were written in terms of strcpy and strcat: > > char *b = XNEWVEC (char, > 2 + strlen (pwd) > + strlen (profile_data_prefix)); > > strcpy (b, profile_data_prefix); > strcat (b, "/"); > strcat (b, pwd);
I disagree. One thing is that GCC attempts to optimize even bad code; in many cases just can't as soon as there is some call in between etc., the other is that we just shouldn't give bad examples. When you know the sizes, we shouldn't be lazy and rely on compiler to figure out what we should have written. Though on this case we have a nice function for all of that, char *b = concat (profile_data_prefix, "/", pwd, NULL); Another thing is that the "/" in there is wrong, so const char dir_separator_str[] = { DIR_SEPARATOR, '\0' }; char *b = concat (profile_data_prefix, dir_separator_str, pwd, NULL); needs to be used instead. Does profile_data_prefix have any dir separators stripped from the end? Is pwd guaranteed to be relative in this case? Jakub