Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: GnuPG: devel

[PATCH] simplify ldap URL construction

 

 

GnuPG devel RSS feed   Index | Next | Previous | View Threaded


jim at meyering

Apr 25, 2012, 8:44 AM

Post #1 of 5 (491 views)
Permalink
[PATCH] simplify ldap URL construction

* 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

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel


wk at gnupg

Apr 25, 2012, 11:37 AM

Post #2 of 5 (468 views)
Permalink
Re: [PATCH] simplify ldap URL construction [In reply to]

On Wed, 25 Apr 2012 17:44, jim [at] meyering said:

> - strncpy( p, sep, slen );
> - p += slen;
> + p = stpncpy( p, sep, slen );

Well, stpncpy is not portable. However it looks very useful.


Shalom-Salam,

Werner

--
Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.


_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel


jim at meyering

Apr 25, 2012, 11:44 AM

Post #3 of 5 (466 views)
Permalink
Re: [PATCH] simplify ldap URL construction [In reply to]

Werner Koch wrote:
> On Wed, 25 Apr 2012 17:44, jim [at] meyering said:
>
>> - strncpy( p, sep, slen );
>> - p += slen;
>> + p = stpncpy( p, sep, slen );
>
> Well, stpncpy is not portable. However it looks very useful.

Good catch.

But gnupg uses gnulib, and there's a stpncpy module to ensure
that it's available.

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel


jim at meyering

Apr 26, 2012, 6:57 AM

Post #4 of 5 (463 views)
Permalink
Re: [PATCH] simplify ldap URL construction [In reply to]

Jim Meyering wrote:
> Werner Koch wrote:
>> On Wed, 25 Apr 2012 17:44, jim [at] meyering said:
>>> - strncpy( p, sep, slen );
>>> - p += slen;
>>> + p = stpncpy( p, sep, slen );
>>
>> Well, stpncpy is not portable. However it looks very useful.
>
> Good catch.
>
> But gnupg uses gnulib, and there's a stpncpy module to ensure
> that it's available.

gnulib's stpcpy module is also good to use, since some systems lack it:

[from doc/posix-functions/stpcpy.texi]

This function is missing on some platforms:

AIX 4.3.2
Cygwin 1.5.x
HP-UX 11
IRIX 6.5
Interix 3.5.
MSVC 9
Minix 3.1.8
NetBSD 5.0
OSF/1 5.1
OpenBSD 3.8
Solaris 10
mingw

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel


wk at gnupg

Apr 26, 2012, 10:21 AM

Post #5 of 5 (463 views)
Permalink
Re: [PATCH] simplify ldap URL construction [In reply to]

On Thu, 26 Apr 2012 15:57, jim [at] meyering said:

> gnulib's stpcpy module is also good to use, since some systems lack it:

We have a simple stpcpy replacement in common/stringhelp.h. Adding
stpncpy is straightforward.

For historic reasons GnuPG does not use gnulib properly. I also don't
care about performance on platforms which don't support a certain new
function; the simple replacements do their job.


Salam-Shalom,

Werner

--
Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.


_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel

GnuPG devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.