]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/dntest.c
Fix typo in comment
[openldap] / libraries / libldap / dntest.c
index a3696c20284597ed436f350a85094bb4b615d9ab..82e97cc6084e971cb580dfe2e6dd9c148771fa61 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -81,11 +81,9 @@ main( int argc, char *argv[] )
        }
 
        if ( strcmp( argv[ 1 ], "-" ) == 0 ) {
-               size_t len;
-               
-               fgets( buf, sizeof( buf ), stdin );
-               len = strlen( buf );
-               if ( len > 0 && buf[ --len ] == '\n' ) {
+               size_t len = fgets( buf, sizeof( buf ), stdin ) ? strlen( buf ) : 0;
+
+               if ( len == 0 || buf[ --len ] == '\n' ) {
                        buf[ len ] = '\0';
                }
                strin = buf;
@@ -171,31 +169,32 @@ main( int argc, char *argv[] )
                case LDAP_DN_FORMAT_LDAPV3:
                case LDAP_DN_FORMAT_LDAPV2:
                        n = ldap_dn2domain( strin, &tmp );
-                       if( n ) {
+                       if ( n ) {
                                fprintf( stdout, "\nldap_dn2domain(\"%s\") FAILED\n", strin );
                        } else {
                                fprintf( stdout, "\nldap_dn2domain(\"%s\")\n"
-                                       "\t= \"%s\"\n", strin, tmp );
+                                       "\t= \"%s\"\n", strin, tmp ? tmp : "" );
                        }
                        ldap_memfree( tmp );
 
                        tmp = ldap_dn2ufn( strin );
                        fprintf( stdout, "\nldap_dn2ufn(\"%s\")\n"
-                                       "\t= \"%s\"\n", strin, tmp );
+                                       "\t= \"%s\"\n", strin, tmp ? tmp : "" );
                        ldap_memfree( tmp );
 
                        tmp = ldap_dn2dcedn( strin );
                        fprintf( stdout, "\nldap_dn2dcedn(\"%s\")\n"
-                                       "\t= \"%s\"\n", strin, tmp );
+                                       "\t= \"%s\"\n", strin, tmp ? tmp : "" );
                        tmp2 = ldap_dcedn2dn( tmp );
                        fprintf( stdout, "\nldap_dcedn2dn(\"%s\")\n"
-                                       "\t= \"%s\"\n", tmp, tmp2 );
+                                       "\t= \"%s\"\n",
+                                       tmp ? tmp : "", tmp2 ? tmp2 : "" );
                        ldap_memfree( tmp );
                        ldap_memfree( tmp2 );
 
                        tmp = ldap_dn2ad_canonical( strin );
                        fprintf( stdout, "\nldap_dn2ad_canonical(\"%s\")\n"
-                                       "\t= \"%s\"\n", strin, tmp );
+                                       "\t= \"%s\"\n", strin, tmp ? tmp : "" );
                        ldap_memfree( tmp );
 
                        fprintf( stdout, "\nldap_explode_dn(\"%s\"):\n", str );
@@ -295,4 +294,3 @@ main( int argc, char *argv[] )
 
        return( 0 );
 }
-