diff --git a/clients/tools/common.c b/clients/tools/common.c
index c1c489a4758f0cb86758377c99040ba33c7813fe..4d7b038c6935e1f748fb6884a5ee87235cc08691 100644
--- a/clients/tools/common.c
+++ b/clients/tools/common.c
@@ -2012,22 +2012,15 @@ print_deref( LDAP *ld, LDAPControl *ctrl )
 			if ( dv->vals != NULL ) {
 				int j;
 				for ( j = 0; dv->vals[ j ].bv_val != NULL; j++ ) {
-					int k;
-
-					for ( k = 0; k < dv->vals[ j ].bv_len; k++ ) {
-						if ( !isprint( dv->vals[ j ].bv_val[k] ) ) {
-							k = -1;
-							break;
-						}
-					}
+					int k = ldif_is_not_printable( dv->vals[ j ].bv_val, dv->vals[ j ].bv_len );
 
 					*ptr++ = '<';
 					ptr = lutil_strcopy( ptr, dv->type );
-					if ( k == -1 ) {
+					if ( k ) {
 						*ptr++ = ':';
 					}
 					*ptr++ = '=';
-					if ( k == -1 ) {
+					if ( k ) {
 						k = lutil_b64_ntop(
 							(unsigned char *) dv->vals[ j ].bv_val,
 							dv->vals[ j ].bv_len,
diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c
index 88e655e63aca647fc0ba901ca84ae283f3f23d34..2306e91f1b6479bc77fe22233a52ea24a6f9f339 100644
--- a/clients/tools/ldapsearch.c
+++ b/clients/tools/ldapsearch.c
@@ -1297,7 +1297,7 @@ getNextPage:
 
 	if (( rc == LDAP_SUCCESS ) && vlv ) {
 		char	buf[BUFSIZ];
-		int	i, moreEntries, tmpSize;
+		int	i, moreEntries;
 
 		/* Loop to get the next window when 
 		 * enter is pressed on the terminal.
diff --git a/libraries/libldap/tls_o.c b/libraries/libldap/tls_o.c
index 90cade8f4ef6b1639d0baf90f3b44a775efbd8de..f572d03f82abc7951ba47f12d077d75aa8b4004e 100644
--- a/libraries/libldap/tls_o.c
+++ b/libraries/libldap/tls_o.c
@@ -618,7 +618,7 @@ no_cn:
 		} else if (( cn->data[0] == '*' ) && ( cn->data[1] == '.' )) {
 			char *domain = strchr(name, '.');
 			if( domain ) {
-				size_t dlen;
+				int dlen;
 
 				dlen = nlen - (domain-name);
 
diff --git a/libraries/libldap/utf-8-conv.c b/libraries/libldap/utf-8-conv.c
index b21f011999e9709c7a30f855665794a115573fb2..09e6b8301469e2a24587e34b82cbf5c8d69f10ab 100644
--- a/libraries/libldap/utf-8-conv.c
+++ b/libraries/libldap/utf-8-conv.c
@@ -191,7 +191,10 @@ ldap_x_wc_to_utf8 ( char *utf8char, wchar_t wchar, size_t count )
 			return 4;
 		if( wchar < 0x4000000 ) 
 			return 5;
-		if( wchar < 0x80000000 )
+#if SIZEOF_WCHAR_T > 4
+		/* UL is not strictly needed by ANSI C */
+		if( wchar < (wchar_t)0x80000000UL )
+#endif /* SIZEOF_WCHAR_T > 4 */
 			return 6;
 		return -1;
 	}
@@ -235,7 +238,12 @@ ldap_x_wc_to_utf8 ( char *utf8char, wchar_t wchar, size_t count )
 			utf8char[len++] = 0x80 | ( wchar & 0x3f );
 		}
 
-	} else if( wchar < 0x80000000 ) {
+	} else
+#if SIZEOF_WCHAR_T > 4
+		/* UL is not strictly needed by ANSI C */
+		if( wchar < (wchar_t)0x80000000UL )
+#endif /* SIZEOF_WCHAR_T > 4 */
+	{
 		if (count >= 6) {
 			utf8char[len++] = 0xfc | ( wchar >> 30 );
 			utf8char[len++] = 0x80 | ( (wchar >> 24) & 0x3f );
@@ -245,8 +253,11 @@ ldap_x_wc_to_utf8 ( char *utf8char, wchar_t wchar, size_t count )
 			utf8char[len++] = 0x80 | ( wchar & 0x3f );
 		}
 
-	} else
+#if SIZEOF_WCHAR_T > 4
+	} else {
 		len = -1;
+#endif /* SIZEOF_WCHAR_T > 4 */
+	}
 	
 	return len;
 
@@ -467,4 +478,4 @@ ldap_x_mbs_to_utf8s ( char *utf8str, const char *mbstr, size_t count,
 	return n;	
 }
 
-#endif
+#endif /* SIZEOF_WCHAR_T >= 4 */
diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h
index 1ea9f84f16597616fe18b241e4b41927fa3037a8..f24a67cc1331b8ac655b7501e51c8cd52a046553 100644
--- a/servers/slapd/back-bdb/back-bdb.h
+++ b/servers/slapd/back-bdb/back-bdb.h
@@ -199,7 +199,7 @@ struct bdb_info {
 	struct re_s		*bi_txn_cp_task;
 	struct re_s		*bi_index_task;
 
-	int			bi_lock_detect;
+	u_int32_t		bi_lock_detect;
 	long		bi_shm_key;
 
 	ID			bi_lastid;
diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c
index 1228cd69038cba7b07fde5df7a11a5f6141c3804..c634b45ce63aef4789c9c62973b1c28540b44c90 100644
--- a/servers/slapd/back-bdb/config.c
+++ b/servers/slapd/back-bdb/config.c
@@ -487,7 +487,7 @@ bdb_cf_gen( ConfigArgs *c )
 			if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
 				int i;
 				for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
-					if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
+					if ( bdb->bi_lock_detect == (u_int32_t)bdb_lockd[i].mask ) {
 						value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
 						rc = 0;
 						break;
@@ -890,7 +890,7 @@ bdb_cf_gen( ConfigArgs *c )
 				c->log, c->argv[1] );
 			return 1;
 		}
-		bdb->bi_lock_detect = rc;
+		bdb->bi_lock_detect = (u_int32_t)rc;
 		break;
 
 	case BDB_SSTACK:
diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c
index cdbfcdb2d5b540c7a228656807965179e4b76312..3a29064538405ac183648ac37f191d440a5aaff4 100644
--- a/servers/slapd/back-bdb/search.c
+++ b/servers/slapd/back-bdb/search.c
@@ -326,7 +326,8 @@ bdb_search( Operation *op, SlapReply *rs )
 	slap_mask_t	mask;
 	time_t		stoptime;
 	int		manageDSAit;
-	int		tentries = 0, nentries = 0;
+	int		tentries = 0;
+	unsigned	nentries = 0;
 	int		idflag = 0;
 
 	DB_LOCK		lock;
diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c
index 7e1af12a9f966e40c5ad50bd354b2f825a5e0acd..c7458285016c94470e2e168ae306e56778d6f452 100644
--- a/servers/slapd/back-ldap/search.c
+++ b/servers/slapd/back-ldap/search.c
@@ -832,7 +832,9 @@ ldap_build_entry(
 					LBER_FREE( attr->a_nvals[i].bv_val );
 				LBER_FREE( attr->a_vals[i].bv_val );
 				attr->a_numvals--;
-				if ( i < attr->a_numvals ) {
+
+				assert( i >= 0 );
+				if ( (unsigned)i < attr->a_numvals ) {
 					attr->a_vals[i] = attr->a_vals[attr->a_numvals];
 					if ( attr->a_nvals != attr->a_vals )
 						attr->a_nvals[i] = attr->a_nvals[attr->a_numvals];