diff --git a/libtransmission/bencode.c b/libtransmission/bencode.c index c98db9f17..d8cdca485 100644 --- a/libtransmission/bencode.c +++ b/libtransmission/bencode.c @@ -161,12 +161,12 @@ makeroom( tr_benc * val, const int len = val->val.l.alloc + count + ( count % LIST_SIZE ? LIST_SIZE - ( count % LIST_SIZE ) : 0 ); - void * new = realloc( val->val.l.vals, len * sizeof( tr_benc ) ); - if( NULL == new ) + void * tmp = realloc( val->val.l.vals, len * sizeof( tr_benc ) ); + if( !tmp ) return 1; val->val.l.alloc = len; - val->val.l.vals = new; + val->val.l.vals = tmp; } return 0; diff --git a/libtransmission/list.h b/libtransmission/list.h index 7e80996c5..9e6b53917 100644 --- a/libtransmission/list.h +++ b/libtransmission/list.h @@ -63,10 +63,13 @@ struct __tr_list struct __tr_list * next, * prev; }; -#define __tr_list_entry(ptr, type, member) ({ \ - const struct __tr_list *__mptr = (ptr); \ - (void *)( (char *)__mptr - offsetof(type,member) ); \ -}) +/** + * Given a __tr_list node that's embedded in a struct, returns a pointer to the struct. + * @param ptr pointer to the embedded __tr_list + * @param type struct type that has contains the __tr_list + * @param field the name of the struct's _tr_list field + */ +#define __tr_list_entry(ptr,type,field) ((type*) (((char*)ptr) - offsetof(type,field))) typedef int ( *__tr_list_cmp_t ) ( const void * a, const void * b ); typedef void ( *__tr_list_free_t )( void * ); diff --git a/libtransmission/net.c b/libtransmission/net.c index fe038ec65..2657274ce 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -32,6 +32,7 @@ #ifdef WIN32 #include /* inet_addr */ + #include #else #include /* inet_addr */ #include diff --git a/libtransmission/net.h b/libtransmission/net.h index 4585aea09..2aa161908 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -32,6 +32,7 @@ #ifdef WIN32 #include #include + #include typedef int socklen_t; #else #include diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 717e12152..773b32fa5 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -11,6 +11,7 @@ */ #include +#include #include /* INT_MAX */ #include #include @@ -87,8 +88,7 @@ didWriteWrapper( tr_peerIo * io, size_t bytes_transferred ) { while( bytes_transferred ) { - struct tr_datatype * next = __tr_list_entry( io->outbuf_datatypes.next, - struct tr_datatype, head ); + struct tr_datatype * next = __tr_list_entry( io->outbuf_datatypes.next, struct tr_datatype, head ); const size_t payload = MIN( next->length, bytes_transferred ); const size_t overhead = getPacketOverhead( payload ); diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 9d6ed4588..58ace7532 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -50,6 +50,10 @@ extern "C" { #endif #include /* time_t */ +#if defined(_MSC_VER) && !defined( __cplusplus ) + #define inline __inline +#endif + #define SHA_DIGEST_LENGTH 20 #define TR_INET6_ADDRSTRLEN 46