Index: trunk/FACT++/dim/src/dis.c
===================================================================
--- trunk/FACT++/dim/src/dis.c	(revision 14575)
+++ trunk/FACT++/dim/src/dis.c	(revision 15282)
@@ -201,5 +201,5 @@
 	if(Dis_packet_size)
 		free(Dis_packet);
-	Dis_packet = (DIS_STAMPED_PACKET *)malloc(DIS_STAMPED_HEADER + size);
+	Dis_packet = (DIS_STAMPED_PACKET *)malloc((size_t)(DIS_STAMPED_HEADER + size));
 	if(Dis_packet)
 	{
@@ -213,10 +213,10 @@
 static int check_service_name(char *name)
 {
-	if(strlen(name) > (MAX_NAME - 1))
+	if((int)strlen(name) > (MAX_NAME - 1))
 		return(0);
 	return(1);
 }
 
-static void dis_init()
+void dis_init()
 {
 	int dis_hash_service_init();
@@ -266,8 +266,8 @@
 	}
 	new_serv = (SERVICE *)malloc( sizeof(SERVICE) );
-	strncpy( new_serv->name, name, MAX_NAME );
+	strncpy( new_serv->name, name, (size_t)MAX_NAME );
 	if(type != (char *)0)
 	{
-		if (strlen(type) >= MAX_NAME)
+		if ((int)strlen(type) >= MAX_NAME)
 		{
 			strcpy(str,"Format String Too Long: ");
@@ -441,5 +441,5 @@
 	}
 	new_serv = (SERVICE *)malloc(sizeof(SERVICE));
-	strncpy(new_serv->name, name, MAX_NAME);
+	strncpy(new_serv->name, name, (size_t)MAX_NAME);
 	if(type != (char *)0)
 	{
@@ -783,5 +783,5 @@
   dis_dns_p->n_services = htovl(n_services);
   dis_dns_p->size = htovl(DIS_DNS_HEADER +
-					n_services * sizeof(SERVICE_REG));
+					n_services * (int)sizeof(SERVICE_REG));
   serv_regp = dis_dns_p->services;
   strcpy( serv_regp->service_name, "DUMMY_UPDATE_PACKET" );
@@ -796,5 +796,5 @@
 }
       if( !dna_write(dnsp->dns_dis_conn_id, &(dnsp->dis_dns_packet),
-		     DIS_DNS_HEADER + n_services * sizeof(SERVICE_REG)))
+		     DIS_DNS_HEADER + n_services * (int)sizeof(SERVICE_REG)))
 	  {
 		release_conn(dnsp->dns_dis_conn_id, 0, 1);
@@ -826,5 +826,5 @@
 */
 		strncpy( dis_dns_p->task_name, dnsp->task_name,
-			MAX_TASK_NAME-4 );
+			(size_t)(MAX_TASK_NAME-4) );
 		dis_dns_p->task_name[MAX_TASK_NAME-4-1] = '\0';
 		get_node_addr( dis_dns_p->node_addr );
@@ -852,5 +852,5 @@
 		dis_dns_p->n_services = htovl(n_services);
 		dis_dns_p->size = htovl( DIS_DNS_HEADER + 
-			(n_services*sizeof(SERVICE_REG)));
+			(n_services*(int)sizeof(SERVICE_REG)));
 		if(dnsp->dns_dis_conn_id > 0)
 		{
@@ -863,5 +863,5 @@
 }
 			if(!dna_write(dnsp->dns_dis_conn_id, &(dnsp->dis_dns_packet), 
-				DIS_DNS_HEADER + n_services*sizeof(SERVICE_REG)))
+				DIS_DNS_HEADER + n_services*(int)sizeof(SERVICE_REG)))
 			{
 				release_conn(dnsp->dns_dis_conn_id, 0, 1);
@@ -917,6 +917,6 @@
 		{
 			dis_dns_p->n_services = htovl(n_services);
-			dis_dns_p->size = htovl(DIS_DNS_HEADER +
-				n_services * sizeof(SERVICE_REG));
+			dis_dns_p->size = (int)htovl(DIS_DNS_HEADER +
+				n_services * (int)sizeof(SERVICE_REG));
 			if(dnsp->dns_dis_conn_id > 0)
 			{
@@ -931,5 +931,5 @@
 					   &(dnsp->dis_dns_packet), 
 					   DIS_DNS_HEADER + n_services *
-						sizeof(SERVICE_REG)) )
+						(int)sizeof(SERVICE_REG)) )
 				{
 					release_conn(dnsp->dns_dis_conn_id, 0, 1);
@@ -946,5 +946,5 @@
 		dis_dns_p->n_services = htovl(n_services);
 		dis_dns_p->size = htovl(DIS_DNS_HEADER +
-					n_services * sizeof(SERVICE_REG));
+					n_services * (int)sizeof(SERVICE_REG));
 		if(dnsp->dns_dis_conn_id > 0)
 		{
@@ -957,5 +957,5 @@
 }
 			if( !dna_write(dnsp->dns_dis_conn_id, &(dnsp->dis_dns_packet),
-				DIS_DNS_HEADER + n_services * sizeof(SERVICE_REG)))
+				DIS_DNS_HEADER + n_services * (int)sizeof(SERVICE_REG)))
 			{
 				release_conn(dnsp->dns_dis_conn_id, 0, 1);
@@ -990,5 +990,5 @@
 */
 			strncpy( dis_dns_p->task_name, dnsp->task_name,
-				MAX_TASK_NAME-4 );
+				(size_t)(MAX_TASK_NAME-4) );
 			dis_dns_p->task_name[MAX_TASK_NAME-4-1] = '\0';
 			get_node_addr( dis_dns_p->node_addr );
@@ -1001,5 +1001,5 @@
 		strcpy( serv_regp->service_name, servp->name );
 		strcpy( serv_regp->service_def, servp->def );
-		serv_regp->service_id = htovl( servp->id | 0x80000000);
+		serv_regp->service_id = (int)htovl( (unsigned)servp->id | 0x80000000);
 		serv_regp++;
 		n_services = 1;
@@ -1007,5 +1007,5 @@
 		dis_dns_p->n_services = htovl(n_services);
 		dis_dns_p->size = htovl(DIS_DNS_HEADER +
-				n_services * sizeof(SERVICE_REG));
+				n_services * (int)sizeof(SERVICE_REG));
 
 if(Debug_on)
@@ -1017,5 +1017,5 @@
 }
 		if( !dna_write(dnsp->dns_dis_conn_id, &(dnsp->dis_dns_packet), 
-			DIS_DNS_HEADER + n_services * sizeof(SERVICE_REG)) )
+			DIS_DNS_HEADER + n_services * (int)sizeof(SERVICE_REG)) )
 		{
 			release_conn(dnsp->dns_dis_conn_id, 0, 1);
@@ -1098,5 +1098,5 @@
 	extern DIS_DNS_CONN *dis_find_dns(dim_long);
 	DIS_DNS_CONN *dnsp;
-	int more_ids[10] = {0};
+	unsigned int more_ids[10] = {0};
 
 	dis_init();
@@ -1132,5 +1132,5 @@
 	if(Dis_first_time)
 	{
-		strncpy( task_name_aux, task, MAX_TASK_NAME );
+		strncpy( task_name_aux, task, (size_t)MAX_TASK_NAME );
 		task_name_aux[MAX_TASK_NAME-1] = '\0';
 		Port_number = SEEK_PORT;
@@ -1159,5 +1159,5 @@
 
 		more_ids[0] = do_dis_add_service_dns( str0, "L", &Version_number,
-				 sizeof(Version_number), 0, 0, dnsid );
+						sizeof(Version_number), 0, 0, dnsid );
 
 		more_ids[1] = do_dis_add_service_dns( str1, "C", 0, 0, client_info, (dim_long)dnsp, dnsid );
@@ -1464,5 +1464,5 @@
 		if( Dis_packet_size )
 			free( Dis_packet );
-		Dis_packet = (DIS_STAMPED_PACKET *)malloc(DIS_STAMPED_HEADER + size);
+		Dis_packet = (DIS_STAMPED_PACKET *)malloc((size_t)(DIS_STAMPED_HEADER + size));
 		if(!Dis_packet)
 		{
@@ -1487,7 +1487,7 @@
 			tz = 0;
 		        gettimeofday(&tv, tz);
-			aux = tv.tv_usec / 1000;
+			aux = (int)tv.tv_usec / 1000;
 			Dis_packet->time_stamp[0] = htovl(aux);
-			Dis_packet->time_stamp[1] = htovl(tv.tv_sec);
+			Dis_packet->time_stamp[1] = htovl((int)tv.tv_sec);
 #endif
 		}
@@ -1498,5 +1498,5 @@
 			Dis_packet->time_stamp[1] = htovl(servp->user_secs);
 		}
-		Dis_packet->reserved[0] = htovl(0xc0dec0de);
+		Dis_packet->reserved[0] = (int)htovl(0xc0dec0de);
 		Dis_packet->quality = htovl(servp->quality);
 	}
@@ -1566,8 +1566,8 @@
 		return;
 	if( !packet_size ) {
-		dis_packet = (DIS_PACKET *)malloc(DIS_HEADER);
+		dis_packet = (DIS_PACKET *)malloc((size_t)DIS_HEADER);
 		packet_size = DIS_HEADER;
 	}
-	service_id = (reqp->service_id | 0x80000000);
+	service_id = (int)((unsigned)reqp->service_id | 0x80000000);
 	dis_packet->service_id = htovl(service_id);
 	dis_packet->size = htovl(DIS_HEADER);
@@ -1599,5 +1599,5 @@
 	if(!buffer_size)
 	{
-		buffer = (int *)malloc(add_size);
+		buffer = (int *)malloc((size_t)add_size);
 		buffer_size = add_size;
 	} 
@@ -1607,5 +1607,5 @@
 		{
 			free(buffer);
-			buffer = (int *)malloc(add_size);
+			buffer = (int *)malloc((size_t)add_size);
 			buffer_size = add_size;
 		}
@@ -1622,6 +1622,6 @@
 			{
 				if(formatp->flags & IT_IS_FLOAT)
-					formatp->flags |= (format & 0xf0);
-				formatp->flags &= 0xFFF0;	/* NOSWAP */
+					formatp->flags |= ((short)format & (short)0xf0);
+				formatp->flags &= (short)0xFFF0;	/* NOSWAP */
 			}
 		}
@@ -1631,5 +1631,5 @@
 			{
 				if(formatp->flags & IT_IS_FLOAT)
-					formatp->flags |= (format & 0xf0);
+					formatp->flags |= ((short)format & (short)0xf0);
 			}
 		}
@@ -1992,6 +1992,6 @@
 			tz = 0;
 		    gettimeofday(&tv, tz);
-			servp->user_secs = tv.tv_sec;
-			servp->user_millisecs = tv.tv_usec / 1000;
+			servp->user_secs = (int)tv.tv_sec;
+			servp->user_millisecs = (int)tv.tv_usec / 1000;
 #endif
 	}
@@ -2074,5 +2074,5 @@
 	if(!packet_size)
 	{
-		dis_packet = (DIS_PACKET *)malloc(DIS_HEADER+size);
+		dis_packet = (DIS_PACKET *)malloc((size_t)(DIS_HEADER+size));
 		packet_size = DIS_HEADER + size;
 	} 
@@ -2082,5 +2082,5 @@
 		{
 			free(dis_packet);
-			dis_packet = (DIS_PACKET *)malloc(DIS_HEADER+size);
+			dis_packet = (DIS_PACKET *)malloc((size_t)(DIS_HEADER+size));
 			packet_size = DIS_HEADER+size;
 		}
@@ -2091,5 +2091,5 @@
 	{
 		dis_packet->service_id = htovl(reqp->service_id);
-		memcpy(dis_packet->buffer, buffer, size);
+		memcpy(dis_packet->buffer, buffer, (size_t)size);
 		dis_packet->size = htovl(DIS_HEADER + size);
 
@@ -2263,5 +2263,5 @@
 		{
 			ENABLE_AST
-			dis_remove_service(servp->id);
+			dis_remove_service((unsigned)servp->id);
 			{
 			DISABLE_AST
@@ -2371,5 +2371,5 @@
 	{
 		ENABLE_AST
-		dis_remove_service(servp->id);
+		dis_remove_service((unsigned)servp->id);
 		{
 		DISABLE_AST
@@ -2467,5 +2467,5 @@
     int found = 0;
 	int release_request();
-	DIS_DNS_CONN *dnsp;
+	DIS_DNS_CONN *dnsp = 0;
 
 	DISABLE_AST;
@@ -2568,5 +2568,5 @@
 		if(!curr_allocated_size)
 		{
-			service_info_buffer = (char *)malloc(max_size);
+			service_info_buffer = (char *)malloc((size_t)max_size);
 			curr_allocated_size = max_size;
 		}
@@ -2574,5 +2574,5 @@
 		{
 			free(service_info_buffer);
-			service_info_buffer = (char *)malloc(max_size);
+			service_info_buffer = (char *)malloc((size_t)max_size);
 			curr_allocated_size = max_size;
 		}
@@ -2587,5 +2587,5 @@
 			strcat(buff_ptr, servp->name);
 			strcat(buff_ptr, "\n");
-			buff_ptr += strlen(buff_ptr);
+			buff_ptr += (int)strlen(buff_ptr);
 		}
 	}
@@ -2743,9 +2743,9 @@
 		sll_init((SLL *) Cmnds_head);
 	}
-	new_cmnd = (DIS_CMND *)malloc((*size)+12);
+	new_cmnd = (DIS_CMND *)malloc((size_t)((*size)+12));
 	new_cmnd->next = 0;
 	new_cmnd->tag = *tag;
 	new_cmnd->size = *size;
-	memcpy(new_cmnd->buffer, cmnd_buff, *size);
+	memcpy(new_cmnd->buffer, cmnd_buff, (size_t)*size);
 	sll_insert_queue((SLL *) Cmnds_head, (SLL *) new_cmnd);
 }
@@ -2782,5 +2782,5 @@
 			ret_val = 1;
 		}
-		memcpy(buffer, cmndp->buffer, *size);
+		memcpy(buffer, cmndp->buffer, (size_t)*size);
 		*tag = cmndp->tag;
 		free(cmndp);
@@ -2824,5 +2824,5 @@
 
 	strcpy(for_str->dsc$a_pointer, c_str);
-	for(i = strlen(c_str); i< for_str->dsc$w_length; i++)
+	for(i = (int)strlen(c_str); i< for_str->dsc$w_length; i++)
 		for_str->dsc$a_pointer[i] = ' ';
 }
@@ -2843,5 +2843,5 @@
 	if(!curr_allocated_size)
 	{
-		dns_info_buffer = malloc(max_size);
+		dns_info_buffer = malloc((size_t)max_size);
 		curr_allocated_size = max_size;
 	}
@@ -2859,9 +2859,9 @@
 			curr_conns[index++] = clip->conn_id;
 		}
-		max_size = (index+1)*sizeof(DNS_CLIENT_INFO);
+		max_size = (index+1)*(int)sizeof(DNS_CLIENT_INFO);
 		if (max_size > curr_allocated_size)
 		{
 			free(dns_info_buffer);
-			dns_info_buffer = malloc(max_size);
+			dns_info_buffer = malloc((size_t)max_size);
 			curr_allocated_size = max_size;
 		}
@@ -2892,7 +2892,7 @@
 	}
 	if(index)
-		dns_client_info[strlen(dns_client_info)-1] = '\0';
+		dns_client_info[(int)strlen(dns_client_info)-1] = '\0';
 	*bufp = (int *)dns_info_buffer;
-	*size = strlen(dns_info_buffer)+1;
+	*size = (int)strlen(dns_info_buffer)+1;
 }
 
@@ -2967,5 +2967,5 @@
 	if(!curr_allocated_size)
 	{
-		service_info_buffer = (char *)malloc(max_size);
+		service_info_buffer = (char *)malloc((size_t)max_size);
 		curr_allocated_size = max_size;
 	}
@@ -2973,5 +2973,5 @@
 	{
 		free(service_info_buffer);
-		service_info_buffer = (char *)malloc(max_size);
+		service_info_buffer = (char *)malloc((size_t)max_size);
 		curr_allocated_size = max_size;
 	}
@@ -2996,5 +2996,5 @@
 				servp->registered = Last_n_clients+1;
 				append_service(buff_ptr, servp);
-				buff_ptr += strlen(buff_ptr);
+				buff_ptr += (int)strlen(buff_ptr);
 			}
 		}
@@ -3012,7 +3012,7 @@
 			{
 				strcat(buff_ptr, "-");
-				buff_ptr += strlen(buff_ptr);
+				buff_ptr += (int)strlen(buff_ptr);
 				append_service(buff_ptr, servp);
-				buff_ptr += strlen(buff_ptr);
+				buff_ptr += (int)strlen(buff_ptr);
 			}
 			else if(servp->registered < (Last_n_clients+1))
@@ -3021,9 +3021,9 @@
 				{
 					strcat(buff_ptr, "+");
-					buff_ptr += strlen(buff_ptr);
+					buff_ptr += (int)strlen(buff_ptr);
 					done = 1;
 				}
 				append_service(buff_ptr, servp);
-				buff_ptr += strlen(buff_ptr);
+				buff_ptr += (int)strlen(buff_ptr);
 /*
 				servp->registered = 2;
@@ -3034,5 +3034,5 @@
 	}
 	*bufp = (int *)service_info_buffer;
-	*size = buff_ptr - service_info_buffer+1;
+	*size = (int)(buff_ptr - service_info_buffer+1);
 	if(*size == 1)
 		*size = -1;
@@ -3235,4 +3235,5 @@
 int dis_hash_service_init()
 {
+
   int i;
   static int done = 0;
@@ -3242,10 +3243,14 @@
 	for( i = 0; i < MAX_HASH_ENTRIES; i++ ) 
 	{
+/*
 		Service_hash_table[i] = (SERVICE *) malloc(sizeof(SERVICE));
 		dll_init((DLL *) Service_hash_table[i]);
+*/
+		Service_hash_table[i] = 0;
 		Service_new_entries[i] = 0;
 	}
 	done = 1;
   }
+
   return(1);
 }
@@ -3255,4 +3260,9 @@
 	int index;
 	index = HashFunction(servp->name, MAX_HASH_ENTRIES);
+	if(!Service_hash_table[index])
+	{
+		Service_hash_table[index] = (SERVICE *) malloc(sizeof(SERVICE));
+		dll_init((DLL *) Service_hash_table[index]);
+	}
 	Service_new_entries[index]++;
 	dll_insert_queue((DLL *) Service_hash_table[index], 
@@ -3272,4 +3282,10 @@
 int dis_hash_service_remove(SERVICE *servp)
 {
+	int index;
+	index = HashFunction(servp->name, MAX_HASH_ENTRIES);
+	if(!Service_hash_table[index])
+	{
+		return(0);
+	}
 	dll_remove( (DLL *) servp );
 	return(1);
@@ -3283,7 +3299,11 @@
 
 	index = HashFunction(name, MAX_HASH_ENTRIES);
+	if(!Service_hash_table[index])
+	{
+		return((SERVICE *)0);
+	}
 	if( (servp = (SERVICE *) dll_search(
 					(DLL *) Service_hash_table[index],
-			      		name, strlen(name)+1)) )
+			      		name, (int)strlen(name)+1)) )
 	{
 		return(servp);
@@ -3314,11 +3334,14 @@
 	do
 	{
-		if((!new_entries) || (Service_new_entries[index] > 0))
-		{
-			servp = (SERVICE *) dll_get_next(
+		if(prevp)
+		{
+			if((!new_entries) || (Service_new_entries[index] > 0))
+			{
+				servp = (SERVICE *) dll_get_next(
 						(DLL *) Service_hash_table[index],
 						(DLL *) prevp);
-			if(servp)
-				break;
+				if(servp)
+					break;
+			}
 		}
 		index++;
