svn commit: r194096 - head/usr.sbin/nscd

Dag-Erling Smorgrav des at FreeBSD.org
Sat Jun 13 00:56:18 UTC 2009


Author: des
Date: Sat Jun 13 00:56:17 2009
New Revision: 194096
URL: http://svn.freebsd.org/changeset/base/194096

Log:
  Fix a large number of signed - unsigned comparison warnings.
  
  MFC after:	1 week

Modified:
  head/usr.sbin/nscd/config.c
  head/usr.sbin/nscd/mp_rs_query.c
  head/usr.sbin/nscd/mp_ws_query.c
  head/usr.sbin/nscd/nscd.c
  head/usr.sbin/nscd/nscdcli.c
  head/usr.sbin/nscd/query.c

Modified: head/usr.sbin/nscd/config.c
==============================================================================
--- head/usr.sbin/nscd/config.c	Sat Jun 13 00:54:52 2009	(r194095)
+++ head/usr.sbin/nscd/config.c	Sat Jun 13 00:56:17 2009	(r194096)
@@ -569,7 +569,8 @@ fill_configuration_defaults(struct confi
 void
 destroy_configuration(struct configuration *config)
 {
-	int	i;
+	unsigned int i;
+
 	TRACE_IN(destroy_configuration);
 	assert(config != NULL);
 	free(config->pidfile_path);

Modified: head/usr.sbin/nscd/mp_rs_query.c
==============================================================================
--- head/usr.sbin/nscd/mp_rs_query.c	Sat Jun 13 00:54:52 2009	(r194095)
+++ head/usr.sbin/nscd/mp_rs_query.c	Sat Jun 13 00:56:17 2009	(r194096)
@@ -140,7 +140,7 @@ on_mp_read_session_request_read2(struct 
 	result = qstate->read_func(qstate, c_mp_rs_request->entry,
 		c_mp_rs_request->entry_length);
 
-	if (result != qstate->kevent_watermark) {
+	if (result < 0 || (size_t)result != qstate->kevent_watermark) {
 		LOG_ERR_3("on_mp_read_session_request_read2",
 			"read failed");
 		TRACE_OUT(on_mp_read_session_request_read2);
@@ -463,7 +463,7 @@ on_mp_read_session_read_response_write1(
 	if (read_response->error_code == 0) {
 		result += qstate->write_func(qstate, &read_response->data_size,
 			sizeof(size_t));
-		if (result != qstate->kevent_watermark) {
+		if (result < 0 || (size_t)result != qstate->kevent_watermark) {
 			TRACE_OUT(on_mp_read_session_read_response_write1);
 			LOG_ERR_3("on_mp_read_session_read_response_write1",
 				"write failed");
@@ -473,7 +473,7 @@ on_mp_read_session_read_response_write1(
 		qstate->kevent_watermark = read_response->data_size;
 		qstate->process_func = on_mp_read_session_read_response_write2;
 	} else {
-		if (result != qstate->kevent_watermark) {
+		if (result < 0 || (size_t)result != qstate->kevent_watermark) {
 			LOG_ERR_3("on_mp_read_session_read_response_write1",
 				"write failed");
 			TRACE_OUT(on_mp_read_session_read_response_write1);
@@ -499,7 +499,7 @@ on_mp_read_session_read_response_write2(
 		&qstate->response);
 	result = qstate->write_func(qstate, read_response->data,
 		read_response->data_size);
-	if (result != qstate->kevent_watermark) {
+	if (result < 0 || (size_t)result != qstate->kevent_watermark) {
 		LOG_ERR_3("on_mp_read_session_read_response_write2",
 			"write failed");
 		TRACE_OUT(on_mp_read_session_read_response_write2);

Modified: head/usr.sbin/nscd/mp_ws_query.c
==============================================================================
--- head/usr.sbin/nscd/mp_ws_query.c	Sat Jun 13 00:54:52 2009	(r194095)
+++ head/usr.sbin/nscd/mp_ws_query.c	Sat Jun 13 00:56:17 2009	(r194096)
@@ -145,7 +145,7 @@ on_mp_write_session_request_read2(struct
 	result = qstate->read_func(qstate, c_mp_ws_request->entry,
 		c_mp_ws_request->entry_length);
 
-	if (result != qstate->kevent_watermark) {
+	if (result < 0 || (size_t)result != qstate->kevent_watermark) {
 		LOG_ERR_3("on_mp_write_session_request_read2",
 			"read failed");
 		TRACE_OUT(on_mp_write_session_request_read2);
@@ -397,7 +397,7 @@ on_mp_write_session_write_request_read2(
 	result = qstate->read_func(qstate, write_request->data,
 		write_request->data_size);
 
-	if (result != qstate->kevent_watermark) {
+	if (result < 0 || (size_t)result != qstate->kevent_watermark) {
 		LOG_ERR_3("on_mp_write_session_write_request_read2",
 			"read failed");
 		TRACE_OUT(on_mp_write_session_write_request_read2);

Modified: head/usr.sbin/nscd/nscd.c
==============================================================================
--- head/usr.sbin/nscd/nscd.c	Sat Jun 13 00:54:52 2009	(r194095)
+++ head/usr.sbin/nscd/nscd.c	Sat Jun 13 00:56:17 2009	(r194096)
@@ -316,9 +316,9 @@ process_socket_event(struct kevent *even
 	 * operations. It also does the actual socket IO operations.
 	 */
 	if (((qstate->use_alternate_io == 0) &&
-		(qstate->kevent_watermark <= event_data->data)) ||
+		(qstate->kevent_watermark <= (size_t)event_data->data)) ||
 		((qstate->use_alternate_io != 0) &&
-		(qstate->io_buffer_watermark <= event_data->data))) {
+		(qstate->io_buffer_watermark <= (size_t)event_data->data))) {
 		if (qstate->use_alternate_io != 0) {
 			switch (qstate->io_buffer_filter) {
 			case EVFILT_READ:
@@ -500,7 +500,7 @@ processing_loop(cache the_cache, struct 
 			struct kevent *event_data;
 			event_data = &eventlist[0];
 
-			if (event_data->ident == env->sockfd) {
+			if ((int)event_data->ident == env->sockfd) {
 				for (i = 0; i < event_data->data; ++i)
 				    accept_connection(event_data, env, config);
 

Modified: head/usr.sbin/nscd/nscdcli.c
==============================================================================
--- head/usr.sbin/nscd/nscdcli.c	Sat Jun 13 00:54:52 2009	(r194095)
+++ head/usr.sbin/nscd/nscdcli.c	Sat Jun 13 00:56:17 2009	(r194096)
@@ -72,9 +72,10 @@ safe_write(struct nscd_connection_ *conn
 		nevents = kevent(connection->write_queue, NULL, 0, &eventlist,
 	    		1, &timeout);
 		if ((nevents == 1) && (eventlist.filter == EVFILT_WRITE)) {
-			s_result = write(connection->sockfd, data + result,
-				eventlist.data < data_size - result ?
-		    		eventlist.data : data_size - result);
+			s_result = write(connection->sockfd,
+				(char *)data + result,
+				(size_t)eventlist.data < data_size - result ?
+		    		(size_t)eventlist.data : data_size - result);
 			if (s_result == -1)
 				return (-1);
 			else
@@ -108,9 +109,10 @@ safe_read(struct nscd_connection_ *conne
 		nevents = kevent(connection->read_queue, NULL, 0, &eventlist, 1,
 			&timeout);
 		if ((nevents == 1) && (eventlist.filter == EVFILT_READ)) {
-			s_result = read(connection->sockfd, data + result,
-			eventlist.data <= data_size - result ? eventlist.data :
-				data_size - result);
+			s_result = read(connection->sockfd,
+				(char *)data + result,
+				(size_t)eventlist.data <= data_size - result ?
+				(size_t)eventlist.data : data_size - result);
 			if (s_result == -1)
 				return (-1);
 			else

Modified: head/usr.sbin/nscd/query.c
==============================================================================
--- head/usr.sbin/nscd/query.c	Sat Jun 13 00:54:52 2009	(r194095)
+++ head/usr.sbin/nscd/query.c	Sat Jun 13 00:56:17 2009	(r194096)
@@ -379,7 +379,7 @@ on_write_request_read2(struct query_stat
 		result += qstate->read_func(qstate, write_request->data,
 			write_request->data_size);
 
-	if (result != qstate->kevent_watermark) {
+	if (result != (ssize_t)qstate->kevent_watermark) {
 		TRACE_OUT(on_write_request_read2);
 		return (-1);
 	}
@@ -643,7 +643,7 @@ on_read_request_read2(struct query_state
 		read_request->cache_key + qstate->eid_str_length,
 		read_request->cache_key_size);
 
-	if (result != qstate->kevent_watermark) {
+	if (result != (ssize_t)qstate->kevent_watermark) {
 		TRACE_OUT(on_read_request_read2);
 		return (-1);
 	}
@@ -839,7 +839,7 @@ on_read_response_write1(struct query_sta
 	if (read_response->error_code == 0) {
 		result += qstate->write_func(qstate, &read_response->data_size,
 			sizeof(size_t));
-		if (result != qstate->kevent_watermark) {
+		if (result != (ssize_t)qstate->kevent_watermark) {
 			TRACE_OUT(on_read_response_write1);
 			return (-1);
 		}
@@ -847,7 +847,7 @@ on_read_response_write1(struct query_sta
 		qstate->kevent_watermark = read_response->data_size;
 		qstate->process_func = on_read_response_write2;
 	} else {
-		if (result != qstate->kevent_watermark) {
+		if (result != (ssize_t)qstate->kevent_watermark) {
 			TRACE_OUT(on_read_response_write1);
 			return (-1);
 		}
@@ -871,7 +871,7 @@ on_read_response_write2(struct query_sta
 	if (read_response->data_size > 0) {
 		result = qstate->write_func(qstate, read_response->data,
 			read_response->data_size);
-		if (result != qstate->kevent_watermark) {
+		if (result != (ssize_t)qstate->kevent_watermark) {
 			TRACE_OUT(on_read_response_write2);
 			return (-1);
 		}
@@ -957,7 +957,7 @@ on_transform_request_read2(struct query_
 	result = qstate->read_func(qstate, transform_request->entry,
 		transform_request->entry_length);
 
-	if (result != qstate->kevent_watermark) {
+	if (result != (ssize_t)qstate->kevent_watermark) {
 		TRACE_OUT(on_transform_request_read2);
 		return (-1);
 	}
@@ -1103,23 +1103,26 @@ check_query_eids(struct query_state *qst
 ssize_t
 query_io_buffer_read(struct query_state *qstate, void *buf, size_t nbytes)
 {
+	size_t remaining;
 	ssize_t	result;
 
 	TRACE_IN(query_io_buffer_read);
 	if ((qstate->io_buffer_size == 0) || (qstate->io_buffer == NULL))
 		return (-1);
 
-	if (nbytes < qstate->io_buffer + qstate->io_buffer_size -
-			qstate->io_buffer_p)
+	assert(qstate->io_buffer_p <=
+		qstate->io_buffer + qstate->io_buffer_size);
+	remaining = qstate->io_buffer + qstate->io_buffer_size -
+		qstate->io_buffer_p;
+	if (nbytes < remaining)
 		result = nbytes;
 	else
-		result = qstate->io_buffer + qstate->io_buffer_size -
-			qstate->io_buffer_p;
+		result = remaining;
 
 	memcpy(buf, qstate->io_buffer_p, result);
 	qstate->io_buffer_p += result;
 
-	if (qstate->io_buffer_p == qstate->io_buffer + qstate->io_buffer_size) {
+	if (remaining == 0) {
 		free(qstate->io_buffer);
 		qstate->io_buffer = NULL;
 
@@ -1139,23 +1142,26 @@ ssize_t
 query_io_buffer_write(struct query_state *qstate, const void *buf,
 	size_t nbytes)
 {
+	size_t remaining;
 	ssize_t	result;
 
 	TRACE_IN(query_io_buffer_write);
 	if ((qstate->io_buffer_size == 0) || (qstate->io_buffer == NULL))
 		return (-1);
 
-	if (nbytes < qstate->io_buffer + qstate->io_buffer_size -
-			qstate->io_buffer_p)
+	assert(qstate->io_buffer_p <=
+		qstate->io_buffer + qstate->io_buffer_size);
+	remaining = qstate->io_buffer + qstate->io_buffer_size -
+		qstate->io_buffer_p;
+	if (nbytes < remaining)
 		result = nbytes;
 	else
-		result = qstate->io_buffer + qstate->io_buffer_size -
-		qstate->io_buffer_p;
+		result = remaining;
 
 	memcpy(qstate->io_buffer_p, buf, result);
 	qstate->io_buffer_p += result;
 
-	if (qstate->io_buffer_p == qstate->io_buffer + qstate->io_buffer_size) {
+	if (remaining == 0) {
 		qstate->use_alternate_io = 1;
 		qstate->io_buffer_p = qstate->io_buffer;
 
@@ -1182,7 +1188,7 @@ query_socket_read(struct query_state *qs
 	}
 
 	result = read(qstate->sockfd, buf, nbytes);
-	if ((result == -1) || (result < nbytes))
+	if (result < 0 || (size_t)result < nbytes)
 		qstate->socket_failed = 1;
 
 	TRACE_OUT(query_socket_read);
@@ -1204,7 +1210,7 @@ query_socket_write(struct query_state *q
 	}
 
 	result = write(qstate->sockfd, buf, nbytes);
-	if ((result == -1) || (result < nbytes))
+	if (result < 0 || (size_t)result < nbytes)
 		qstate->socket_failed = 1;
 
 	TRACE_OUT(query_socket_write);


More information about the svn-src-all mailing list