@@ -752,6 +752,10 @@ map_add(uptr n, unsigned char l, unsigned int p, unsigned char t)
752752 }
753753 for (i = 0 ; i < map_used ; i ++ )
754754 {
755+ if (NULL == map [i ])
756+ {
757+ break ;
758+ }
755759 if (compare (map [i ]-> name , map [i ]-> size , m -> name , m -> size ) > 0 )
756760 {
757761 int j ;
@@ -3382,22 +3386,15 @@ handle_send()
33823386
33833387 r = sendto (udp_desc , (const char * )& entry -> dat [entry -> pos ],
33843388 entry -> len - entry -> pos , 0 , (void * )& entry -> addr , sizeof (entry -> addr ));
3385- /*
3386- * 'r' is the number of bytes sent. This should be the number
3387- * of bytes we asked to send, or -1 to indicate failure.
3388- */
3389- if (r > 0 )
3390- {
3391- entry -> pos += r ;
3392- }
3393-
3394- /*
3395- * If we haven't written all the data, it should have been
3396- * because we blocked. Anything else is a major problem
3397- * so we remove the message from the queue.
3389+ /* 'r' is the number of bytes sent. This should be the number
3390+ * of bytes we asked to send, or -1 to indicate failure.
33983391 */
3399- if (entry -> pos != entry -> len )
3392+ if (r < 0 )
34003393 {
3394+ /* If we haven't written any data, it should have been
3395+ * because we blocked. Anything else is a major problem
3396+ * so we remove the message from the queue.
3397+ */
34013398#if defined(__MINGW__ )
34023399 if (WSAGetLastError () != WSAEWOULDBLOCK )
34033400#else
@@ -3416,17 +3413,17 @@ handle_send()
34163413 }
34173414 else
34183415 {
3416+ entry -> pos += r ;
34193417 udp_sent ++ ;
34203418 if (debug > 1 )
34213419 {
3422- snprintf (ebuf , sizeof (ebuf ), "performed sendto for %s" ,
3423- inet_ntoa (entry -> addr .sin_addr ));
3420+ snprintf (ebuf , sizeof (ebuf ), "performed sendto (%d bytes) for %s" ,
3421+ r , inet_ntoa (entry -> addr .sin_addr ));
34243422 gdomap_log (LOG_DEBUG );
34253423 }
3426- /*
3427- * If we have sent the entire message - remove it from queue.
3424+ /* If we have sent the entire message - remove it from queue.
34283425 */
3429- if (entry -> pos = = entry -> len )
3426+ if (entry -> pos > = entry -> len )
34303427 {
34313428 queue_pop ();
34323429 }
@@ -3897,7 +3894,7 @@ int ptype, struct sockaddr_in *addr, unsigned short *p, uptr *v)
38973894 int len = port * sizeof (struct in_addr );
38983895 uptr b ;
38993896
3900- b = (uptr )malloc (len );
3897+ b = (uptr )calloc (len , 1 );
39013898 if (tryRead (desc , 3 , b , len ) != len )
39023899 {
39033900 free (b );
@@ -3926,7 +3923,7 @@ int ptype, struct sockaddr_in *addr, unsigned short *p, uptr *v)
39263923 uptr ptr ;
39273924 uptr b ;
39283925
3929- b = (uptr )malloc (len );
3926+ b = (uptr )calloc (len , 1 );
39303927 if (tryRead (desc , 3 , b , len ) != len )
39313928 {
39323929 free (b );
0 commit comments