diff --git a/libtransmission/JSON_parser.c b/libtransmission/JSON_parser.c index e9b17f52b..998bdbdb2 100644 --- a/libtransmission/JSON_parser.c +++ b/libtransmission/JSON_parser.c @@ -154,7 +154,7 @@ enum classes { NR_CLASSES }; -static int ascii_class[128] = { +static const int ascii_class[128] = { /* This array maps the 128 ASCII characters into character classes. The remaining Unicode characters should be mapped to C_ETC. @@ -243,7 +243,7 @@ enum actions }; -static int state_transition_table[NR_STATES][NR_CLASSES] = { +static const int state_transition_table[NR_STATES][NR_CLASSES] = { /* The state transition table takes the current state and the current symbol, and returns either a new state or an action. An action is represented as a @@ -523,7 +523,7 @@ static int parse_parse_buffer(JSON_parser jc) #define IS_HIGH_SURROGATE(uc) (((uc) & 0xFC00) == 0xD800) #define IS_LOW_SURROGATE(uc) (((uc) & 0xFC00) == 0xDC00) #define DECODE_SURROGATE_PAIR(hi,lo) ((((hi) & 0x3FF) << 10) + ((lo) & 0x3FF) + 0x10000) -static unsigned char utf8_lead_bits[4] = { 0x00, 0xC0, 0xE0, 0xF0 }; +static const unsigned char utf8_lead_bits[4] = { 0x00, 0xC0, 0xE0, 0xF0 }; static int decode_unicode_char(JSON_parser jc) { diff --git a/libtransmission/bitfield.c b/libtransmission/bitfield.c index 523e57422..463894b73 100644 --- a/libtransmission/bitfield.c +++ b/libtransmission/bitfield.c @@ -190,7 +190,7 @@ tr_bitfieldCountTrueBits( const tr_bitfield* b ) { size_t ret = 0; const uint8_t * it, *end; - static const int trueBitCount[512] = { + static const int trueBitCount[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2,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6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, 5, 6, 6, 7, 6, 7, 7, 8, 6, 7, 7, 8, 7, 8, 8, 9 + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; if( !b ) diff --git a/libtransmission/crypto.c b/libtransmission/crypto.c index a2cd1d408..66a987b0d 100644 --- a/libtransmission/crypto.c +++ b/libtransmission/crypto.c @@ -375,8 +375,8 @@ tr_ssha1( const void * plaintext ) "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "./"; - static const size_t salter_len = 64; - static const size_t saltval_len = 8; + const size_t salter_len = 64; + const size_t saltval_len = 8; size_t i; char salt[saltval_len]; diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index 5b37de8bc..cd22bac44 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -90,9 +90,9 @@ getFiles( const char * dir, static int bestPieceSize( uint64_t totalSize ) { - static const uint64_t GiB = 1073741824; - static const uint64_t MiB = 1048576; - static const uint64_t KiB = 1024; + const uint64_t GiB = 1073741824; + const uint64_t MiB = 1048576; + const uint64_t KiB = 1024; if( totalSize >= ( 2 * GiB ) ) return 2 * MiB; if( totalSize >= ( 1 * GiB ) ) return 1 * MiB; diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 3f1fd89b9..4d1ac7333 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -57,7 +57,7 @@ guessPacketOverhead( size_t d ) * (1500-72)/(38+1500) = 92.8479 % IPv6, TCP timestamps * (1500-72)/(42+1500) = 92.6070 % 802.1q, IPv6, ICP timestamps */ - static const double assumed_payload_data_rate = 94.0; + const double assumed_payload_data_rate = 94.0; return (size_t)( d * ( 100.0 / assumed_payload_data_rate ) - d ); } diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index ffbc50c94..7541a0547 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1120,22 +1120,24 @@ refillUpkeep( int foo UNUSED, short bar UNUSED, void * vmgr ) { int keepCount = 0; int cancelCount = 0; - struct block_request * keep = tr_new( struct block_request, n ); struct block_request * cancel = tr_new( struct block_request, n ); const struct block_request * it; const struct block_request * end; for( it=t->requests, end=it+n; it!=end; ++it ) + { if( it->sentAt <= too_old ) cancel[cancelCount++] = *it; else - keep[keepCount++] = *it; + { + if( it != &t->requests[keepCount] ) + t->requests[keepCount] = *it; + keepCount++; + } + } /* prune out the ones we aren't keeping */ - tr_free( t->requests ); - t->requests = keep; t->requestCount = keepCount; - t->requestAlloc = n; /* send cancel messages for all the "cancel" ones */ for( it=cancel, end=it+cancelCount; it!=end; ++it ) diff --git a/libtransmission/stats.c b/libtransmission/stats.c index 68b9659a9..fe4e4ba5c 100644 --- a/libtransmission/stats.c +++ b/libtransmission/stats.c @@ -21,7 +21,7 @@ **** ***/ -static struct tr_session_stats STATS_INIT = { 0.0f, 0, 0, 0, 0, 0 }; +static const struct tr_session_stats STATS_INIT = { 0.0f, 0, 0, 0, 0, 0 }; /** @brief Opaque, per-session data structure for bandwidth use statistics */ struct tr_stats_handle