[patch] Use snprintf to implement concat in etc.c

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch] Use snprintf to implement concat in etc.c

Nan Xiao-2
HI tech@,

I think maybe one snprintf is more efficient and concise. Sorry if I am
wrong, thanks!

Index: etc.c
===================================================================
RCS file: /cvs/src/libexec/ld.so/ldconfig/etc.c,v
retrieving revision 1.7
diff -u -p -r1.7 etc.c
--- etc.c 12 May 2006 23:35:16 -0000 1.7
+++ etc.c 7 Jun 2018 07:10:30 -0000
@@ -5,6 +5,7 @@
 #include <sys/types.h>

 #include <err.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "ld.h"
@@ -61,9 +62,7 @@ concat(const char *s1, const char *s2, c
  len = strlen(s1) + strlen(s2) + strlen(s3) + 1;
  str = xmalloc(len);

- strlcpy(str, s1, len);
- strlcat(str, s2, len);
- strlcat(str, s3, len);
+ snprintf(str, len, "%s%s%s", s1, s2, s3);

  return (str);
 }

--
Best Regards
Nan Xiao

Reply | Threaded
Open this post in threaded view
|

Re: [patch] Use snprintf to implement concat in etc.c

Philip Guenther-2
On Thu, Jun 7, 2018 at 12:34 AM Nan Xiao <[hidden email]> wrote:

> I think maybe one snprintf is more efficient and concise. Sorry if I am
> wrong, thanks!
>

Seems unlikely.  More productive would be to go up a level and look at
whether concat() is carrying its weight as an abstraction.  One of the
calls is completely superfluous, to my eye.

But really, ldconfig is pretty uninteresting, being run very, very rarely,
so polishing it is like sanding the rough spots on the bottoms of table
legs, where they touch the floor.  We've spent more cycles talking about it
then it'll use in a year...



Philip Guenther
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Use snprintf to implement concat in etc.c

Nan Xiao-2
Hi Philip,

Thanks for your comments!

On 6/9/2018 12:35 PM, Philip Guenther wrote:

> On Thu, Jun 7, 2018 at 12:34 AM Nan Xiao <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     I think maybe one snprintf is more efficient and concise. Sorry if I am
>     wrong, thanks!
>
>
> Seems unlikely.  More productive would be to go up a level and look at
> whether concat() is carrying its weight as an abstraction.  One of the
> calls is completely superfluous, to my eye.
>
> But really, ldconfig is pretty uninteresting, being run very, very
> rarely, so polishing it is like sanding the rough spots on the bottoms
> of table legs, where they touch the floor.  We've spent more cycles
> talking about it then it'll use in a year...
>
>
>
> Philip Guenther
>

--
Best Regards
Nan Xiao(肖楠)