[PATCH] simplify ldap URL construction
Jim Meyering
jim at meyering.net
Wed Apr 25 17:44:46 CEST 2012
* dirmngr/ldap-url.c (ldap_charray2str): Remove unwarranted uses of
strncpy, and simplify.
---
Looking at the other strncpy uses, I found these two and saw that they
are unnecessary, since we know in each case that the specified length
is also the length of the source string. Using stpcpy makes it
simpler/clearer.
dirmngr/ldap-url.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/dirmngr/ldap-url.c b/dirmngr/ldap-url.c
index 7b27a30..47441b1 100644
--- a/dirmngr/ldap-url.c
+++ b/dirmngr/ldap-url.c
@@ -342,16 +342,11 @@ char * ldap_charray2str( char **a, const char *sep )
p = s;
for ( v = a; *v != NULL; v++ ) {
if ( v != a ) {
- strncpy( p, sep, slen );
- p += slen;
+ p = stpncpy( p, sep, slen );
}
-
- len = strlen( *v );
- strncpy( p, *v, len );
- p += len;
+ p = stpcpy( p, *v );
}
- *p = '\0';
return s;
}
--
1.7.10.335.g879d8
More information about the Gnupg-devel
mailing list