Introduce our own assertion macros with finer control

This commit is contained in:
Mike Gelfand 2017-06-08 10:24:12 +03:00
parent 5f7bc801c8
commit 98695fe3c1
69 changed files with 1137 additions and 1048 deletions

View File

@ -53,6 +53,7 @@ set(${PROJECT_NAME}_SOURCES
torrent-magnet.c
tr-dht.c
trevent.c
tr-assert.c
tr-getopt.c
tr-lpd.c
tr-udp.c
@ -107,6 +108,7 @@ set(${PROJECT_NAME}_PUBLIC_HEADERS
quark.h
rpcimpl.h
session-id.h
tr-assert.h
tr-getopt.h
transmission.h
utils.h

View File

@ -61,6 +61,7 @@ libtransmission_a_SOURCES = \
torrent.c \
torrent-ctor.c \
torrent-magnet.c \
tr-assert.c \
tr-dht.c \
tr-lpd.c \
tr-udp.c \
@ -159,6 +160,7 @@ noinst_HEADERS = \
torrent-magnet.h \
tr-getopt.h \
transmission.h \
tr-assert.h \
tr-dht.h \
tr-udp.h \
tr-utp.h \

View File

@ -23,6 +23,7 @@
#include "peer-io.h"
#include "peer-mgr.h" /* tr_peerMgrCompactToPex() */
#include "ptrarray.h"
#include "tr-assert.h"
#include "tr-udp.h"
#include "utils.h"
@ -460,7 +461,7 @@ static void tau_tracker_upkeep(struct tau_tracker*);
static void tau_tracker_free(struct tau_tracker* t)
{
assert(t->dns_request == NULL);
TR_ASSERT(t->dns_request == NULL);
if (t->addr != NULL)
{
@ -538,10 +539,10 @@ static void tau_tracker_send_reqs(struct tau_tracker* tracker)
tr_ptrArray* reqs;
time_t const now = tr_time();
assert(tracker->dns_request == NULL);
assert(tracker->connecting_at == 0);
assert(tracker->addr != NULL);
assert(tracker->connection_expiration_time > now);
TR_ASSERT(tracker->dns_request == NULL);
TR_ASSERT(tracker->connecting_at == 0);
TR_ASSERT(tracker->addr != NULL);
TR_ASSERT(tracker->connection_expiration_time > now);
reqs = &tracker->announces;

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <limits.h> /* INT_MAX */
#include <stdio.h>
#include <stdlib.h> /* qsort() */
@ -26,6 +25,7 @@
#include "ptrarray.h"
#include "session.h"
#include "torrent.h"
#include "tr-assert.h"
#include "utils.h"
struct tr_tier;
@ -164,7 +164,7 @@ void tr_announcerInit(tr_session* session)
{
tr_announcer* a;
assert(tr_isSession(session));
TR_ASSERT(tr_isSession(session));
a = tr_new0(tr_announcer, 1);
a->stops = TR_PTR_ARRAY_INIT;
@ -718,7 +718,7 @@ tr_torrent_tiers* tr_announcerAddTorrent(tr_torrent* tor, tr_tracker_callback ca
{
tr_torrent_tiers* tiers;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tiers = tiersNew();
tiers->callback = callback;
@ -742,8 +742,8 @@ bool tr_announcerCanManualAnnounce(tr_torrent const* tor)
{
struct tr_torrent_tiers* tt = NULL;
assert(tr_isTorrent(tor));
assert(tor->tiers != NULL);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tor->tiers != NULL);
if (tor->isRunning)
{
@ -812,7 +812,7 @@ static void tier_announce_remove_trailing(tr_tier* tier, tr_announce_event e)
static void tier_announce_event_push(tr_tier* tier, tr_announce_event e, time_t announceAt)
{
assert(tier != NULL);
TR_ASSERT(tier != NULL);
dbgmsg_tier_announce_queue(tier);
dbgmsg(tier, "queued \"%s\"", tr_announce_event_get_string(e));
@ -914,8 +914,8 @@ void tr_announcerAddBytes(tr_torrent* tor, int type, uint32_t byteCount)
{
struct tr_torrent_tiers* tt = tor->tiers;
assert(tr_isTorrent(tor));
assert(type == TR_ANN_UP || type == TR_ANN_DOWN || type == TR_ANN_CORRUPT);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(type == TR_ANN_UP || type == TR_ANN_DOWN || type == TR_ANN_CORRUPT);
for (int i = 0; i < tt->tier_count; ++i)
{
@ -1276,8 +1276,8 @@ static void tierAnnounce(tr_announcer* announcer, tr_tier* tier)
tr_torrent* tor = tier->tor;
time_t const now = tr_time();
assert(!tier->isAnnouncing);
assert(tier->announce_event_count > 0);
TR_ASSERT(!tier->isAnnouncing);
TR_ASSERT(tier->announce_event_count > 0);
announce_event = tier_announce_event_pull(tier);
req = announce_request_new(announcer, tor, tier, announce_event);
@ -1664,7 +1664,7 @@ tr_tracker_stat* tr_announcerStats(tr_torrent const* torrent, int* setmeTrackerC
struct tr_torrent_tiers* tt;
time_t const now = tr_time();
assert(tr_isTorrent(torrent));
TR_ASSERT(tr_isTorrent(torrent));
tt = torrent->tiers;
@ -1786,8 +1786,8 @@ static void copy_tier_attributes_impl(struct tr_tier* tgt, int trackerIndex, tr_
tr_tier const keep = *tgt;
/* sanity clause */
assert(trackerIndex < tgt->tracker_count);
assert(tr_strcmp0(tgt->trackers[trackerIndex].announce, src->currentTracker->announce) == 0);
TR_ASSERT(trackerIndex < tgt->tracker_count);
TR_ASSERT(tr_strcmp0(tgt->trackers[trackerIndex].announce, src->currentTracker->announce) == 0);
/* bitwise copy will handle most of tr_tier's fields... */
*tgt = *src;
@ -1830,7 +1830,7 @@ void tr_announcerResetTorrent(tr_announcer* announcer UNUSED, tr_torrent* tor)
struct tr_torrent_tiers* tt = tor->tiers;
tr_torrent_tiers old = *tt;
assert(tt != NULL);
TR_ASSERT(tt != NULL);
/* remove the old tiers / trackers */
tt->tiers = NULL;

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <string.h> /* memset() */
#include "transmission.h"
@ -14,6 +13,7 @@
#include "crypto-utils.h" /* tr_rand_int_weak() */
#include "log.h"
#include "peer-io.h"
#include "tr-assert.h"
#include "utils.h"
#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
@ -109,7 +109,7 @@ void tr_bandwidthConstruct(tr_bandwidth* b, tr_session* session, tr_bandwidth* p
void tr_bandwidthDestruct(tr_bandwidth* b)
{
assert(tr_isBandwidth(b));
TR_ASSERT(tr_isBandwidth(b));
tr_bandwidthSetParent(b, NULL);
tr_ptrArrayDestruct(&b->children, NULL);
@ -123,24 +123,24 @@ void tr_bandwidthDestruct(tr_bandwidth* b)
void tr_bandwidthSetParent(tr_bandwidth* b, tr_bandwidth* parent)
{
assert(tr_isBandwidth(b));
assert(b != parent);
TR_ASSERT(tr_isBandwidth(b));
TR_ASSERT(b != parent);
if (b->parent != NULL)
{
assert(tr_isBandwidth(b->parent));
TR_ASSERT(tr_isBandwidth(b->parent));
tr_ptrArrayRemoveSortedPointer(&b->parent->children, b, compareBandwidth);
b->parent = NULL;
}
if (parent != NULL)
{
assert(tr_isBandwidth(parent));
assert(parent->parent != b);
TR_ASSERT(tr_isBandwidth(parent));
TR_ASSERT(parent->parent != b);
assert(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == NULL);
TR_ASSERT(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == NULL);
tr_ptrArrayInsertSorted(&parent->children, b, compareBandwidth);
assert(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == b);
TR_ASSERT(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == b);
b->parent = parent;
}
}
@ -154,8 +154,8 @@ static void allocateBandwidth(tr_bandwidth* b, tr_priority_t parent_priority, tr
{
tr_priority_t const priority = MAX(parent_priority, b->priority);
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isBandwidth(b));
TR_ASSERT(tr_isDirection(dir));
/* set the available bandwidth */
if (b->band[dir].isLimited)
@ -287,8 +287,8 @@ void tr_bandwidthAllocate(tr_bandwidth* b, tr_direction dir, unsigned int period
void tr_bandwidthSetPeer(tr_bandwidth* b, tr_peerIo* peer)
{
assert(tr_isBandwidth(b));
assert(peer == NULL || tr_isPeerIo(peer));
TR_ASSERT(tr_isBandwidth(b));
TR_ASSERT(peer == NULL || tr_isPeerIo(peer));
b->peer = peer;
}
@ -299,8 +299,8 @@ void tr_bandwidthSetPeer(tr_bandwidth* b, tr_peerIo* peer)
static unsigned int bandwidthClamp(tr_bandwidth const* b, uint64_t now, tr_direction dir, unsigned int byteCount)
{
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isBandwidth(b));
TR_ASSERT(tr_isDirection(dir));
if (b != NULL)
{
@ -356,16 +356,16 @@ unsigned int tr_bandwidthClamp(tr_bandwidth const* b, tr_direction dir, unsigned
unsigned int tr_bandwidthGetRawSpeed_Bps(tr_bandwidth const* b, uint64_t const now, tr_direction const dir)
{
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isBandwidth(b));
TR_ASSERT(tr_isDirection(dir));
return getSpeed_Bps(&b->band[dir].raw, HISTORY_MSEC, now);
}
unsigned int tr_bandwidthGetPieceSpeed_Bps(tr_bandwidth const* b, uint64_t const now, tr_direction const dir)
{
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isBandwidth(b));
TR_ASSERT(tr_isDirection(dir));
return getSpeed_Bps(&b->band[dir].piece, HISTORY_MSEC, now);
}
@ -374,8 +374,8 @@ void tr_bandwidthUsed(tr_bandwidth* b, tr_direction dir, size_t byteCount, bool
{
struct tr_band* band;
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isBandwidth(b));
TR_ASSERT(tr_isDirection(dir));
band = &b->band[dir];

View File

@ -12,10 +12,9 @@
#pragma once
#include <assert.h>
#include "transmission.h"
#include "ptrarray.h"
#include "tr-assert.h"
#include "utils.h" /* tr_new(), tr_free() */
struct tr_peerIo;
@ -225,8 +224,8 @@ static inline bool tr_bandwidthHonorParentLimits(tr_bandwidth* bandwidth, tr_dir
static inline bool tr_bandwidthAreParentLimitsHonored(tr_bandwidth const* bandwidth, tr_direction direction)
{
assert(tr_isBandwidth(bandwidth));
assert(tr_isDirection(direction));
TR_ASSERT(tr_isBandwidth(bandwidth));
TR_ASSERT(tr_isDirection(direction));
return bandwidth->band[direction].honorParentLimits;
}

View File

@ -6,11 +6,11 @@
*
*/
#include <assert.h>
#include <string.h> /* memset */
#include "transmission.h"
#include "bitfield.h"
#include "tr-assert.h"
#include "utils.h" /* tr_new0() */
tr_bitfield const TR_BITFIELD_INIT = { NULL, 0, 0, 0, false, false };
@ -68,8 +68,8 @@ static size_t countRange(tr_bitfield const* b, size_t begin, size_t end)
return 0;
}
assert(begin < end);
assert(b->bits != NULL);
TR_ASSERT(begin < end);
TR_ASSERT(b->bits != NULL);
if (first_byte == last_byte)
{
@ -114,7 +114,7 @@ static size_t countRange(tr_bitfield const* b, size_t begin, size_t end)
}
}
assert(ret <= (begin - end));
TR_ASSERT(ret <= (begin - end));
return ret;
}
@ -157,13 +157,13 @@ bool tr_bitfieldHas(tr_bitfield const* b, size_t n)
****
***/
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
static bool tr_bitfieldIsValid(tr_bitfield const* b)
{
assert(b != NULL);
assert((b->alloc_count == 0) == (b->bits == NULL));
assert(b->bits == NULL || b->true_count == countArray(b));
TR_ASSERT(b != NULL);
TR_ASSERT((b->alloc_count == 0) == (b->bits == NULL));
TR_ASSERT(b->bits == NULL || b->true_count == countArray(b));
return true;
}
@ -172,7 +172,7 @@ static bool tr_bitfieldIsValid(tr_bitfield const* b)
size_t tr_bitfieldCountTrueBits(tr_bitfield const* b)
{
assert(tr_bitfieldIsValid(b));
TR_ASSERT(tr_bitfieldIsValid(b));
return b->true_count;
}
@ -200,11 +200,11 @@ void* tr_bitfieldGetRaw(tr_bitfield const* b, size_t* byte_count)
size_t const n = get_bytes_needed(b->bit_count);
uint8_t* bits = tr_new0(uint8_t, n);
assert(b->bit_count > 0);
TR_ASSERT(b->bit_count > 0);
if (b->alloc_count != 0)
{
assert(b->alloc_count <= n);
TR_ASSERT(b->alloc_count <= n);
memcpy(bits, b->bits, b->alloc_count);
}
else if (tr_bitfieldHasAll(b))
@ -264,7 +264,7 @@ static void tr_bitfieldFreeArray(tr_bitfield* b)
static void tr_bitfieldSetTrueCount(tr_bitfield* b, size_t n)
{
assert(b->bit_count == 0 || n <= b->bit_count);
TR_ASSERT(b->bit_count == 0 || n <= b->bit_count);
b->true_count = n;
@ -273,7 +273,7 @@ static void tr_bitfieldSetTrueCount(tr_bitfield* b, size_t n)
tr_bitfieldFreeArray(b);
}
assert(tr_bitfieldIsValid(b));
TR_ASSERT(tr_bitfieldIsValid(b));
}
static void tr_bitfieldRebuildTrueCount(tr_bitfield* b)
@ -283,16 +283,16 @@ static void tr_bitfieldRebuildTrueCount(tr_bitfield* b)
static void tr_bitfieldIncTrueCount(tr_bitfield* b, size_t i)
{
assert(b->bit_count == 0 || i <= b->bit_count);
assert(b->bit_count == 0 || b->true_count <= b->bit_count - i);
TR_ASSERT(b->bit_count == 0 || i <= b->bit_count);
TR_ASSERT(b->bit_count == 0 || b->true_count <= b->bit_count - i);
tr_bitfieldSetTrueCount(b, b->true_count + i);
}
static void tr_bitfieldDecTrueCount(tr_bitfield* b, size_t i)
{
assert(b->bit_count == 0 || i <= b->bit_count);
assert(b->bit_count == 0 || b->true_count >= i);
TR_ASSERT(b->bit_count == 0 || i <= b->bit_count);
TR_ASSERT(b->bit_count == 0 || b->true_count >= i);
tr_bitfieldSetTrueCount(b, b->true_count - i);
}
@ -310,7 +310,7 @@ void tr_bitfieldConstruct(tr_bitfield* b, size_t bit_count)
b->have_all_hint = false;
b->have_none_hint = false;
assert(tr_bitfieldIsValid(b));
TR_ASSERT(tr_bitfieldIsValid(b));
}
void tr_bitfieldSetHasNone(tr_bitfield* b)
@ -320,7 +320,7 @@ void tr_bitfieldSetHasNone(tr_bitfield* b)
b->have_all_hint = false;
b->have_none_hint = true;
assert(tr_bitfieldIsValid(b));
TR_ASSERT(tr_bitfieldIsValid(b));
}
void tr_bitfieldSetHasAll(tr_bitfield* b)
@ -330,7 +330,7 @@ void tr_bitfieldSetHasAll(tr_bitfield* b)
b->have_all_hint = true;
b->have_none_hint = false;
assert(tr_bitfieldIsValid(b));
TR_ASSERT(tr_bitfieldIsValid(b));
}
void tr_bitfieldSetFromBitfield(tr_bitfield* b, tr_bitfield const* src)
@ -366,8 +366,8 @@ void tr_bitfieldSetRaw(tr_bitfield* b, void const* bits, size_t byte_count, bool
{
/* ensure the excess bits are set to '0' */
int const excess_bit_count = byte_count * 8 - b->bit_count;
assert(excess_bit_count >= 0);
assert(excess_bit_count <= 7);
TR_ASSERT(excess_bit_count >= 0);
TR_ASSERT(excess_bit_count <= 7);
if (excess_bit_count)
{
@ -457,7 +457,7 @@ void tr_bitfieldAddRange(tr_bitfield* b, size_t begin, size_t end)
void tr_bitfieldRem(tr_bitfield* b, size_t nth)
{
assert(tr_bitfieldIsValid(b));
TR_ASSERT(tr_bitfieldIsValid(b));
if (tr_bitfieldHas(b, nth) && tr_bitfieldEnsureNthBitAlloced(b, nth))
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <stdio.h>
#include <string.h> /* strlen() */

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> /* bsearch(), qsort() */
@ -18,6 +17,7 @@
#include "file.h"
#include "log.h"
#include "net.h"
#include "tr-assert.h"
#include "utils.h"
/***
@ -183,7 +183,7 @@ bool tr_blocklistFileIsEnabled(tr_blocklistFile* b)
void tr_blocklistFileSetEnabled(tr_blocklistFile* b, bool isEnabled)
{
assert(b != NULL);
TR_ASSERT(b != NULL);
b->isEnabled = isEnabled;
}
@ -193,7 +193,7 @@ bool tr_blocklistFileHasAddress(tr_blocklistFile* b, tr_address const* addr)
uint32_t needle;
struct tr_ipv4_range const* range;
assert(tr_address_is_valid(addr));
TR_ASSERT(tr_address_is_valid(addr));
if (!b->isEnabled || addr->type == TR_AF_INET6)
{
@ -405,19 +405,19 @@ int tr_blocklistFileSetContent(tr_blocklistFile* b, char const* filename)
ranges_count = keep + 1 - ranges;
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
/* sanity checks: make sure the rules are sorted
* in ascending order and don't overlap */
{
for (size_t i = 0; i < ranges_count; ++i)
{
assert(ranges[i].begin <= ranges[i].end);
TR_ASSERT(ranges[i].begin <= ranges[i].end);
}
for (size_t i = 1; i < ranges_count; ++i)
{
assert(ranges[i - 1].end < ranges[i].begin);
TR_ASSERT(ranges[i - 1].end < ranges[i].begin);
}
}

View File

@ -17,6 +17,7 @@
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "ptrarray.h"
#include "torrent.h"
#include "tr-assert.h"
#include "trevent.h"
#include "utils.h"
@ -277,7 +278,7 @@ tr_cache* tr_cacheNew(int64_t max_bytes)
void tr_cacheFree(tr_cache* cache)
{
assert(tr_ptrArrayEmpty(&cache->blocks));
TR_ASSERT(tr_ptrArrayEmpty(&cache->blocks));
tr_ptrArrayDestruct(&cache->blocks, NULL);
tr_free(cache);
}
@ -320,7 +321,7 @@ int tr_cacheWriteBlock(tr_cache* cache, tr_torrent* torrent, tr_piece_index_t pi
{
struct cache_block* cb = findBlock(cache, torrent, piece, offset);
assert(tr_amInEventThread(torrent->session));
TR_ASSERT(tr_amInEventThread(torrent->session));
if (cb == NULL)
{
@ -336,7 +337,7 @@ int tr_cacheWriteBlock(tr_cache* cache, tr_torrent* torrent, tr_piece_index_t pi
cb->time = tr_time();
assert(cb->length == length);
TR_ASSERT(cb->length == length);
evbuffer_drain(cb->evbuf, evbuffer_get_length(cb->evbuf));
evbuffer_remove_buffer(writeme, cb->evbuf, cb->length);

View File

@ -6,11 +6,10 @@
*
*/
#include <assert.h>
#include "transmission.h"
#include "completion.h"
#include "torrent.h"
#include "tr-assert.h"
#include "utils.h"
/***
@ -41,7 +40,7 @@ void tr_cpBlockInit(tr_completion* cp, tr_bitfield const* b)
/* set sizeNow */
cp->sizeNow = tr_bitfieldCountTrueBits(&cp->blockBitfield);
assert(cp->sizeNow <= cp->tor->blockCount);
TR_ASSERT(cp->sizeNow <= cp->tor->blockCount);
cp->sizeNow *= cp->tor->blockSize;
if (tr_bitfieldHas(b, cp->tor->blockCount - 1))
@ -49,7 +48,7 @@ void tr_cpBlockInit(tr_completion* cp, tr_bitfield const* b)
cp->sizeNow -= (cp->tor->blockSize - cp->tor->lastBlockSize);
}
assert(cp->sizeNow <= cp->tor->info.totalSize);
TR_ASSERT(cp->sizeNow <= cp->tor->info.totalSize);
}
/***
@ -192,13 +191,13 @@ uint64_t tr_cpSizeWhenDone(tr_completion const* ccp)
}
}
assert(n <= tr_torPieceCountBytes(tor, p));
TR_ASSERT(n <= tr_torPieceCountBytes(tor, p));
size += n;
}
}
assert(size <= inf->totalSize);
assert(size >= cp->sizeNow);
TR_ASSERT(size <= inf->totalSize);
TR_ASSERT(size >= cp->sizeNow);
cp->sizeWhenDoneLazy = size;
cp->sizeWhenDoneIsDirty = false;
@ -211,7 +210,7 @@ uint64_t tr_cpLeftUntilDone(tr_completion const* cp)
{
uint64_t const sizeWhenDone = tr_cpSizeWhenDone(cp);
assert(sizeWhenDone >= cp->sizeNow);
TR_ASSERT(sizeWhenDone >= cp->sizeNow);
return sizeWhenDone - cp->sizeNow;
}
@ -281,7 +280,7 @@ size_t tr_cpMissingBytesInPiece(tr_completion const* cp, tr_piece_index_t piece)
haveBytes += tr_torBlockCountBytes(cp->tor, l);
}
assert(haveBytes <= pieceByteSize);
TR_ASSERT(haveBytes <= pieceByteSize);
return pieceByteSize - haveBytes;
}
}
@ -307,7 +306,7 @@ void* tr_cpCreatePieceBitfield(tr_completion const* cp, size_t* byte_count)
tr_piece_index_t n;
tr_bitfield pieces;
assert(tr_torrentHasMetadata(cp->tor));
TR_ASSERT(tr_torrentHasMetadata(cp->tor));
n = cp->tor->info.pieceCount;
tr_bitfieldConstruct(&pieces, n);

View File

@ -18,8 +18,6 @@
#define API_VERSION_HEX LIBCYASSL_VERSION_HEX
#endif
#include <assert.h>
#include API_HEADER_CRYPT(arc4.h)
#include API_HEADER_CRYPT(dh.h)
#include API_HEADER_CRYPT(error-crypt.h)
@ -31,6 +29,7 @@
#include "crypto-utils.h"
#include "log.h"
#include "platform.h"
#include "tr-assert.h"
#include "utils.h"
#define TR_CRYPTO_DH_SECRET_FALLBACK
@ -134,14 +133,14 @@ tr_sha1_ctx_t tr_sha1_init(void)
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
if (data_length == 0)
{
return true;
}
assert(data != NULL);
TR_ASSERT(data != NULL);
return check_result(API(ShaUpdate)(handle, data, data_length));
}
@ -152,7 +151,7 @@ bool tr_sha1_final(tr_sha1_ctx_t handle, uint8_t* hash)
if (hash != NULL)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
ret = check_result(API(ShaFinal)(handle, hash));
}
@ -177,23 +176,23 @@ void tr_rc4_free(tr_rc4_ctx_t handle)
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
assert(handle != NULL);
assert(key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(key != NULL);
API(Arc4SetKey)(handle, key, key_length);
}
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
if (length == 0)
{
return;
}
assert(input != NULL);
assert(output != NULL);
TR_ASSERT(input != NULL);
TR_ASSERT(output != NULL);
API(Arc4Process)(handle, output, input, length);
}
@ -207,8 +206,8 @@ tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t
{
struct tr_dh_ctx* handle = tr_new0(struct tr_dh_ctx, 1);
assert(prime_num != NULL);
assert(generator_num != NULL);
TR_ASSERT(prime_num != NULL);
TR_ASSERT(generator_num != NULL);
API(InitDhKey)(&handle->dh);
@ -244,8 +243,8 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length UNUSED, ui
word32 my_public_key_length;
tr_lock* rng_lock = get_rng_lock();
assert(handle != NULL);
assert(public_key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(public_key != NULL);
if (handle->private_key == NULL)
{
@ -281,8 +280,8 @@ tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, uint8_t const* other_public_k
struct tr_dh_secret* ret;
word32 my_secret_key_length;
assert(handle != NULL);
assert(other_public_key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(other_public_key != NULL);
ret = tr_dh_secret_new(handle->key_length);
@ -309,7 +308,7 @@ bool tr_rand_buffer(void* buffer, size_t length)
bool ret;
tr_lock* rng_lock = get_rng_lock();
assert(buffer != NULL);
TR_ASSERT(buffer != NULL);
tr_lockLock(rng_lock);
ret = check_result(API(RNG_GenerateBlock)(get_rng(), buffer, length));

View File

@ -10,10 +10,9 @@
implement missing (or duplicate) functionality without exposing internal
details in header files. */
#include <assert.h>
#include "transmission.h"
#include "crypto-utils.h"
#include "tr-assert.h"
#include "utils.h"
/***
@ -48,8 +47,8 @@ bool tr_dh_secret_derive(tr_dh_secret_t raw_handle, void const* prepend_data, si
{
struct tr_dh_secret* handle = raw_handle;
assert(handle != NULL);
assert(hash != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(hash != NULL);
return tr_sha1(hash, prepend_data == NULL ? "" : prepend_data, prepend_data == NULL ? 0 : (int)prepend_data_size,
handle->key, (int)handle->key_length, append_data, append_data == NULL ? 0 : (int)append_data_size, NULL);

View File

@ -11,8 +11,6 @@
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include <assert.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/dh.h>
@ -24,6 +22,7 @@
#include "transmission.h"
#include "crypto-utils.h"
#include "log.h"
#include "tr-assert.h"
#include "utils.h"
#define TR_CRYPTO_DH_SECRET_FALLBACK
@ -116,14 +115,14 @@ tr_sha1_ctx_t tr_sha1_init(void)
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
if (data_length == 0)
{
return true;
}
assert(data != NULL);
TR_ASSERT(data != NULL);
return check_result(EVP_DigestUpdate(handle, data, data_length));
}
@ -136,11 +135,11 @@ bool tr_sha1_final(tr_sha1_ctx_t handle, uint8_t* hash)
{
unsigned int hash_length;
assert(handle != NULL);
TR_ASSERT(handle != NULL);
ret = check_result(EVP_DigestFinal_ex(handle, hash, &hash_length));
assert(!ret || hash_length == SHA_DIGEST_LENGTH);
TR_ASSERT(!ret || hash_length == SHA_DIGEST_LENGTH);
}
EVP_MD_CTX_destroy(handle);
@ -206,8 +205,8 @@ void tr_rc4_free(tr_rc4_ctx_t handle)
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
assert(handle != NULL);
assert(key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(key != NULL);
if (!check_result(EVP_CIPHER_CTX_set_key_length(handle, key_length)))
{
@ -221,15 +220,15 @@ void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t
{
int output_length;
assert(handle != NULL);
TR_ASSERT(handle != NULL);
if (length == 0)
{
return;
}
assert(input != NULL);
assert(output != NULL);
TR_ASSERT(input != NULL);
TR_ASSERT(output != NULL);
check_result(EVP_CipherUpdate(handle, output, &output_length, input, length));
}
@ -304,8 +303,8 @@ tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t
BIGNUM* p;
BIGNUM* g;
assert(prime_num != NULL);
assert(generator_num != NULL);
TR_ASSERT(prime_num != NULL);
TR_ASSERT(generator_num != NULL);
p = BN_bin2bn(prime_num, prime_num_length, NULL);
g = BN_bin2bn(generator_num, generator_num_length, NULL);
@ -338,8 +337,8 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length, uint8_t*
int my_public_key_length;
BIGNUM const* my_public_key;
assert(handle != NULL);
assert(public_key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(public_key != NULL);
DH_set_length(handle, private_key_length * 8);
@ -370,8 +369,8 @@ tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t handle, uint8_t const* other_public_key,
int secret_key_length;
BIGNUM* other_key;
assert(handle != NULL);
assert(other_public_key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(other_public_key != NULL);
if (!check_pointer(other_key = BN_bin2bn(other_public_key, other_public_key_length, NULL)))
{
@ -403,7 +402,7 @@ tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t handle, uint8_t const* other_public_key,
bool tr_rand_buffer(void* buffer, size_t length)
{
assert(buffer != NULL);
TR_ASSERT(buffer != NULL);
return check_result(RAND_bytes(buffer, (int)length));
}

View File

@ -16,8 +16,6 @@
#define API_VERSION_NUMBER POLARSSL_VERSION_NUMBER
#endif
#include <assert.h>
#include API_HEADER(arc4.h)
#include API_HEADER(base64.h)
#include API_HEADER(ctr_drbg.h)
@ -30,6 +28,7 @@
#include "crypto-utils.h"
#include "log.h"
#include "platform.h"
#include "tr-assert.h"
#include "utils.h"
#define TR_CRYPTO_DH_SECRET_FALLBACK
@ -145,14 +144,14 @@ tr_sha1_ctx_t tr_sha1_init(void)
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
if (data_length == 0)
{
return true;
}
assert(data != NULL);
TR_ASSERT(data != NULL);
API(sha1_update)(handle, data, data_length);
return true;
@ -162,7 +161,7 @@ bool tr_sha1_final(tr_sha1_ctx_t handle, uint8_t* hash)
{
if (hash != NULL)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
API(sha1_finish)(handle, hash);
}
@ -201,23 +200,23 @@ void tr_rc4_free(tr_rc4_ctx_t handle)
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
assert(handle != NULL);
assert(key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(key != NULL);
API(arc4_setup)(handle, key, key_length);
}
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
if (length == 0)
{
return;
}
assert(input != NULL);
assert(output != NULL);
TR_ASSERT(input != NULL);
TR_ASSERT(output != NULL);
API(arc4_crypt)(handle, length, input, output);
}
@ -231,8 +230,8 @@ tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t
{
API(dhm_context)* handle = tr_new0(API(dhm_context), 1);
assert(prime_num != NULL);
assert(generator_num != NULL);
TR_ASSERT(prime_num != NULL);
TR_ASSERT(generator_num != NULL);
#if API_VERSION_NUMBER >= 0x01030800
API(dhm_init)(handle);
@ -264,8 +263,8 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length, uint8_t*
{
API(dhm_context)* handle = raw_handle;
assert(handle != NULL);
assert(public_key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(public_key != NULL);
if (public_key_length != NULL)
{
@ -281,8 +280,8 @@ tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, uint8_t const* other_public_k
struct tr_dh_secret* ret;
size_t secret_key_length;
assert(handle != NULL);
assert(other_public_key != NULL);
TR_ASSERT(handle != NULL);
TR_ASSERT(other_public_key != NULL);
if (!check_result(API(dhm_read_public)(handle, other_public_key, other_public_key_length)))
{
@ -322,7 +321,7 @@ bool tr_rand_buffer(void* buffer, size_t length)
bool ret;
tr_lock* rng_lock = get_rng_lock();
assert(buffer != NULL);
TR_ASSERT(buffer != NULL);
tr_lockLock(rng_lock);
ret = check_result(API(ctr_drbg_random)(get_rng(), buffer, length));

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h> /* abs(), srand(), rand() */
#include <string.h> /* memcpy(), memmove(), memset(), strcmp(), strlen() */
@ -16,6 +15,7 @@
#include "transmission.h"
#include "crypto-utils.h"
#include "tr-assert.h"
#include "utils.h"
/***
@ -24,7 +24,7 @@
void tr_dh_align_key(uint8_t* key_buffer, size_t key_size, size_t buffer_size)
{
assert(key_size <= buffer_size);
TR_ASSERT(key_size <= buffer_size);
/* DH can generate key sizes that are smaller than the size of
key buffer with exponentially decreasing probability, in which case
@ -60,7 +60,7 @@ bool tr_sha1(uint8_t* hash, void const* data1, int data1_length, ...)
while ((data = va_arg(vl, void const*)) != NULL)
{
int const data_length = va_arg(vl, int);
assert(data_length >= 0);
TR_ASSERT(data_length >= 0);
if (!tr_sha1_update(sha, data, data_length))
{
@ -89,7 +89,7 @@ int tr_rand_int(int upper_bound)
{
int noise;
assert(upper_bound > 0);
TR_ASSERT(upper_bound > 0);
while (tr_rand_buffer(&noise, sizeof(noise)))
{
@ -110,7 +110,7 @@ int tr_rand_int_weak(int upper_bound)
{
static bool init = false;
assert(upper_bound > 0);
TR_ASSERT(upper_bound > 0);
if (!init)
{
@ -139,7 +139,7 @@ char* tr_ssha1(char const* plain_text)
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"./";
assert(plain_text != NULL);
TR_ASSERT(plain_text != NULL);
unsigned char salt[saltval_len];
uint8_t sha[SHA_DIGEST_LENGTH];
@ -163,8 +163,8 @@ char* tr_ssha1(char const* plain_text)
bool tr_ssha1_matches(char const* ssha1, char const* plain_text)
{
assert(ssha1 != NULL);
assert(plain_text != NULL);
TR_ASSERT(ssha1 != NULL);
TR_ASSERT(plain_text != NULL);
size_t const brace_len = 1;
size_t const brace_and_hash_len = brace_len + 2 * SHA_DIGEST_LENGTH;

View File

@ -6,12 +6,12 @@
*
*/
#include <assert.h>
#include <string.h> /* memcpy(), memmove(), memset() */
#include "transmission.h"
#include "crypto.h"
#include "crypto-utils.h"
#include "tr-assert.h"
#include "utils.h"
/**
@ -48,7 +48,7 @@ static void ensureKeyExists(tr_crypto* crypto)
crypto->dh = tr_dh_new(dh_P, sizeof(dh_P), dh_G, sizeof(dh_G));
tr_dh_make_key(crypto->dh, DH_PRIVKEY_LEN, crypto->myPublicKey, &public_key_length);
assert(public_key_length == KEY_LEN);
TR_ASSERT(public_key_length == KEY_LEN);
}
}
@ -94,7 +94,7 @@ static void initRC4(tr_crypto* crypto, tr_rc4_ctx_t* setme, char const* key)
{
uint8_t buf[SHA_DIGEST_LENGTH];
assert(crypto->torrentHashIsSet);
TR_ASSERT(crypto->torrentHashIsSet);
if (*setme == NULL)
{
@ -160,8 +160,8 @@ void tr_cryptoEncrypt(tr_crypto* crypto, size_t buf_len, void const* buf_in, voi
bool tr_cryptoSecretKeySha1(tr_crypto const* crypto, void const* prepend_data, size_t prepend_data_size,
void const* append_data, size_t append_data_size, uint8_t* hash)
{
assert(crypto != NULL);
assert(crypto->mySecret != NULL);
TR_ASSERT(crypto != NULL);
TR_ASSERT(crypto->mySecret != NULL);
return tr_dh_secret_derive(crypto->mySecret, prepend_data, prepend_data_size, append_data, append_data_size, hash);
}
@ -186,14 +186,14 @@ void tr_cryptoSetTorrentHash(tr_crypto* crypto, uint8_t const* hash)
uint8_t const* tr_cryptoGetTorrentHash(tr_crypto const* crypto)
{
assert(crypto);
TR_ASSERT(crypto != NULL);
return crypto->torrentHashIsSet ? crypto->torrentHash : NULL;
}
bool tr_cryptoHasTorrentHash(tr_crypto const* crypto)
{
assert(crypto);
TR_ASSERT(crypto != NULL);
return crypto->torrentHashIsSet;
}

View File

@ -6,10 +6,9 @@
*
*/
#include <assert.h>
#include "transmission.h"
#include "error.h"
#include "tr-assert.h"
#include "utils.h"
tr_error* tr_error_new(int code, char const* message_format, ...)
@ -17,7 +16,7 @@ tr_error* tr_error_new(int code, char const* message_format, ...)
tr_error* error;
va_list args;
assert(message_format != NULL);
TR_ASSERT(message_format != NULL);
va_start(args, message_format);
error = tr_error_new_valist(code, message_format, args);
@ -30,7 +29,7 @@ tr_error* tr_error_new_literal(int code, char const* message)
{
tr_error* error;
assert(message != NULL);
TR_ASSERT(message != NULL);
error = tr_new(tr_error, 1);
error->code = code;
@ -43,7 +42,7 @@ tr_error* tr_error_new_valist(int code, char const* message_format, va_list args
{
tr_error* error;
assert(message_format != NULL);
TR_ASSERT(message_format != NULL);
error = tr_new(tr_error, 1);
error->code = code;
@ -72,8 +71,8 @@ void tr_error_set(tr_error** error, int code, char const* message_format, ...)
return;
}
assert(*error == NULL);
assert(message_format != NULL);
TR_ASSERT(*error == NULL);
TR_ASSERT(message_format != NULL);
va_start(args, message_format);
*error = tr_error_new_valist(code, message_format, args);
@ -87,20 +86,20 @@ void tr_error_set_literal(tr_error** error, int code, char const* message)
return;
}
assert(*error == NULL);
assert(message != NULL);
TR_ASSERT(*error == NULL);
TR_ASSERT(message != NULL);
*error = tr_error_new_literal(code, message);
}
void tr_error_propagate(tr_error** new_error, tr_error** old_error)
{
assert(old_error != NULL);
assert(*old_error != NULL);
TR_ASSERT(old_error != NULL);
TR_ASSERT(*old_error != NULL);
if (new_error != NULL)
{
assert(*new_error == NULL);
TR_ASSERT(*new_error == NULL);
*new_error = *old_error;
*old_error = NULL;
@ -128,9 +127,9 @@ static void error_prefix_valist(tr_error** error, char const* prefix_format, va_
char* prefix;
char* new_message;
assert(error != NULL);
assert(*error != NULL);
assert(prefix_format != NULL);
TR_ASSERT(error != NULL);
TR_ASSERT(*error != NULL);
TR_ASSERT(prefix_format != NULL);
prefix = tr_strdup_vprintf(prefix_format, args);
@ -145,7 +144,7 @@ void tr_error_prefix(tr_error** error, char const* prefix_format, ...)
{
va_list args;
assert(prefix_format != NULL);
TR_ASSERT(prefix_format != NULL);
if (error == NULL || *error == NULL)
{
@ -161,7 +160,7 @@ void tr_error_propagate_prefixed(tr_error** new_error, tr_error** old_error, cha
{
va_list args;
assert(prefix_format != NULL);
TR_ASSERT(prefix_format != NULL);
tr_error_propagate(new_error, old_error);

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <string.h>
@ -24,6 +23,7 @@
#include "log.h"
#include "session.h"
#include "torrent.h" /* tr_isTorrent() */
#include "tr-assert.h"
#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
@ -130,14 +130,14 @@ struct tr_cached_file
static inline bool cached_file_is_open(struct tr_cached_file const* o)
{
assert(o != NULL);
TR_ASSERT(o != NULL);
return o->fd != TR_BAD_SYS_FILE;
}
static void cached_file_close(struct tr_cached_file* o)
{
assert(cached_file_is_open(o));
TR_ASSERT(cached_file_is_open(o));
tr_sys_file_close(o->fd, NULL);
o->fd = TR_BAD_SYS_FILE;
@ -212,7 +212,7 @@ static int cached_file_open(struct tr_cached_file* o, char const* filename, bool
type = _("sparse");
}
assert(type != NULL);
TR_ASSERT(type != NULL);
if (!success)
{
@ -371,7 +371,7 @@ struct tr_fdInfo
static void ensureSessionFdInfoExists(tr_session* session)
{
assert(tr_isSession(session));
TR_ASSERT(tr_isSession(session));
if (session->fdInfo == NULL)
{
@ -478,7 +478,7 @@ bool tr_fdFileGetCachedMTime(tr_session* s, int torrent_id, tr_file_index_t i, t
void tr_fdTorrentClose(tr_session* session, int torrent_id)
{
assert(tr_sessionIsLocked(session));
TR_ASSERT(tr_sessionIsLocked(session));
fileset_close_torrent(get_fileset(session), torrent_id);
}
@ -530,7 +530,7 @@ tr_socket_t tr_fdSocketCreate(tr_session* session, int domain, int type)
{
tr_socket_t s = TR_BAD_SOCKET;
struct tr_fdInfo* gFd;
assert(tr_isSession(session));
TR_ASSERT(tr_isSession(session));
ensureSessionFdInfoExists(session);
gFd = session->fdInfo;
@ -552,7 +552,7 @@ tr_socket_t tr_fdSocketCreate(tr_session* session, int domain, int type)
++gFd->peerCount;
}
assert(gFd->peerCount >= 0);
TR_ASSERT(gFd->peerCount >= 0);
if (s != TR_BAD_SOCKET)
{
@ -590,9 +590,9 @@ tr_socket_t tr_fdSocketAccept(tr_session* s, tr_socket_t sockfd, tr_address* add
struct tr_fdInfo* gFd;
struct sockaddr_storage sock;
assert(tr_isSession(s));
assert(addr != NULL);
assert(port != NULL);
TR_ASSERT(tr_isSession(s));
TR_ASSERT(addr != NULL);
TR_ASSERT(port != NULL);
ensureSessionFdInfoExists(s);
gFd = s->fdInfo;
@ -618,7 +618,7 @@ tr_socket_t tr_fdSocketAccept(tr_session* s, tr_socket_t sockfd, tr_address* add
void tr_fdSocketClose(tr_session* session, tr_socket_t fd)
{
assert(tr_isSession(session));
TR_ASSERT(tr_isSession(session));
if (session->fdInfo != NULL)
{
@ -630,6 +630,6 @@ void tr_fdSocketClose(tr_session* session, tr_socket_t fd)
--gFd->peerCount;
}
assert(gFd->peerCount >= 0);
TR_ASSERT(gFd->peerCount >= 0);
}
}

View File

@ -9,7 +9,6 @@
#undef _GNU_SOURCE
#define _GNU_SOURCE
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h> /* O_LARGEFILE, posix_fadvise(), [posix_]fallocate() */
@ -33,6 +32,7 @@
#include "file.h"
#include "log.h"
#include "platform.h"
#include "tr-assert.h"
#include "utils.h"
#ifndef O_LARGEFILE
@ -221,7 +221,7 @@ bool tr_sys_path_exists(char const* path, tr_error** error)
{
bool ret;
assert(path != NULL);
TR_ASSERT(path != NULL);
ret = access(path, F_OK) != -1;
@ -238,8 +238,8 @@ bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, t
bool ret;
struct stat sb;
assert(path != NULL);
assert(info != NULL);
TR_ASSERT(path != NULL);
TR_ASSERT(info != NULL);
if ((flags & TR_SYS_PATH_NO_FOLLOW) == 0)
{
@ -264,7 +264,7 @@ bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, t
bool tr_sys_path_is_relative(char const* path)
{
assert(path != NULL);
TR_ASSERT(path != NULL);
return path[0] != '/';
}
@ -275,8 +275,8 @@ bool tr_sys_path_is_same(char const* path1, char const* path2, tr_error** error)
struct stat sb1;
struct stat sb2;
assert(path1 != NULL);
assert(path2 != NULL);
TR_ASSERT(path1 != NULL);
TR_ASSERT(path2 != NULL);
if (stat(path1, &sb1) != -1 && stat(path2, &sb2) != -1)
{
@ -295,7 +295,7 @@ char* tr_sys_path_resolve(char const* path, tr_error** error)
char* ret = NULL;
char* tmp = NULL;
assert(path != NULL);
TR_ASSERT(path != NULL);
#if defined(HAVE_CANONICALIZE_FILE_NAME)
@ -341,7 +341,7 @@ char* tr_sys_path_basename(char const* path, tr_error** error)
char* ret = NULL;
char* tmp;
assert(path != NULL);
TR_ASSERT(path != NULL);
tmp = tr_strdup(path);
ret = basename(tmp);
@ -365,7 +365,7 @@ char* tr_sys_path_dirname(char const* path, tr_error** error)
char* ret = NULL;
char* tmp;
assert(path != NULL);
TR_ASSERT(path != NULL);
tmp = tr_strdup(path);
ret = dirname(tmp);
@ -388,8 +388,8 @@ bool tr_sys_path_rename(char const* src_path, char const* dst_path, tr_error** e
{
bool ret;
assert(src_path != NULL);
assert(dst_path != NULL);
TR_ASSERT(src_path != NULL);
TR_ASSERT(dst_path != NULL);
ret = rename(src_path, dst_path) != -1;
@ -405,7 +405,7 @@ bool tr_sys_path_remove(char const* path, tr_error** error)
{
bool ret;
assert(path != NULL);
TR_ASSERT(path != NULL);
ret = remove(path) != -1;
@ -436,7 +436,7 @@ tr_sys_file_t tr_sys_file_get_std(tr_std_sys_file_t std_file, tr_error** error)
break;
default:
assert(0 && "Unknown standard file");
TR_ASSERT_MSG(false, "unknown standard file %d", (int)std_file);
set_system_error(error, EINVAL);
}
@ -448,8 +448,8 @@ tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, tr_
tr_sys_file_t ret;
int native_flags = 0;
assert(path != NULL);
assert((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
TR_ASSERT(path != NULL);
TR_ASSERT((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
if ((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) == (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE))
{
@ -493,7 +493,7 @@ tr_sys_file_t tr_sys_file_open_temp(char* path_template, tr_error** error)
{
tr_sys_file_t ret;
assert(path_template != NULL);
TR_ASSERT(path_template != NULL);
ret = mkstemp(path_template);
@ -511,7 +511,7 @@ bool tr_sys_file_close(tr_sys_file_t handle, tr_error** error)
{
bool ret;
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = close(handle) != -1;
@ -528,8 +528,8 @@ bool tr_sys_file_get_info(tr_sys_file_t handle, tr_sys_path_info* info, tr_error
bool ret;
struct stat sb;
assert(handle != TR_BAD_SYS_FILE);
assert(info != NULL);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(info != NULL);
ret = fstat(handle, &sb) != -1;
@ -556,8 +556,8 @@ bool tr_sys_file_seek(tr_sys_file_t handle, int64_t offset, tr_seek_origin_t ori
TR_STATIC_ASSERT(sizeof(*new_offset) >= sizeof(my_new_offset), "");
assert(handle != TR_BAD_SYS_FILE);
assert(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
my_new_offset = lseek(handle, offset, origin);
@ -585,8 +585,8 @@ bool tr_sys_file_read(tr_sys_file_t handle, void* buffer, uint64_t size, uint64_
TR_STATIC_ASSERT(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
my_bytes_read = read(handle, buffer, size);
@ -615,10 +615,10 @@ bool tr_sys_file_read_at(tr_sys_file_t handle, void* buffer, uint64_t size, uint
TR_STATIC_ASSERT(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
/* seek requires signed offset, so it should be in mod range */
assert(offset < UINT64_MAX / 2);
TR_ASSERT(offset < UINT64_MAX / 2);
#ifdef HAVE_PREAD
@ -661,8 +661,8 @@ bool tr_sys_file_write(tr_sys_file_t handle, void const* buffer, uint64_t size,
TR_STATIC_ASSERT(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
my_bytes_written = write(handle, buffer, size);
@ -691,10 +691,10 @@ bool tr_sys_file_write_at(tr_sys_file_t handle, void const* buffer, uint64_t siz
TR_STATIC_ASSERT(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
/* seek requires signed offset, so it should be in mod range */
assert(offset < UINT64_MAX / 2);
TR_ASSERT(offset < UINT64_MAX / 2);
#ifdef HAVE_PWRITE
@ -734,7 +734,7 @@ bool tr_sys_file_flush(tr_sys_file_t handle, tr_error** error)
{
bool ret;
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = fsync(handle) != -1;
@ -750,7 +750,7 @@ bool tr_sys_file_truncate(tr_sys_file_t handle, uint64_t size, tr_error** error)
{
bool ret;
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = ftruncate(handle, size) != -1;
@ -770,8 +770,8 @@ bool tr_sys_file_prefetch(tr_sys_file_t handle, uint64_t offset, uint64_t size,
int code;
assert(handle != TR_BAD_SYS_FILE);
assert(size > 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(size > 0);
code = posix_fadvise(handle, offset, size, POSIX_FADV_WILLNEED);
@ -788,8 +788,8 @@ bool tr_sys_file_prefetch(tr_sys_file_t handle, uint64_t offset, uint64_t size,
struct radvisory radv;
assert(handle != TR_BAD_SYS_FILE);
assert(size > 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(size > 0);
radv.ra_offset = offset;
radv.ra_count = size;
@ -810,7 +810,7 @@ bool tr_sys_file_preallocate(tr_sys_file_t handle, uint64_t size, int flags, tr_
{
bool ret = false;
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
errno = 0;
@ -914,8 +914,8 @@ void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_
{
void* ret;
assert(handle != TR_BAD_SYS_FILE);
assert(size > 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(size > 0);
ret = mmap(NULL, size, PROT_READ, MAP_SHARED, handle, offset);
@ -932,8 +932,8 @@ bool tr_sys_file_unmap(void const* address, uint64_t size, tr_error** error)
{
bool ret;
assert(address != NULL);
assert(size > 0);
TR_ASSERT(address != NULL);
TR_ASSERT(size > 0);
ret = munmap((void*)address, size) != -1;
@ -950,9 +950,9 @@ bool tr_sys_file_lock(tr_sys_file_t handle, int operation, tr_error** error)
bool ret;
int native_operation = 0;
assert(handle != TR_BAD_SYS_FILE);
assert((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
assert(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
TR_ASSERT(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
!!(operation & TR_SYS_FILE_LOCK_UN) == 1);
if ((operation & TR_SYS_FILE_LOCK_SH) != 0)
@ -1031,7 +1031,7 @@ bool tr_sys_dir_create(char const* path, int flags, int permissions, tr_error**
bool ret;
tr_error* my_error = NULL;
assert(path != NULL);
TR_ASSERT(path != NULL);
if ((flags & TR_SYS_DIR_CREATE_PARENTS) != 0)
{
@ -1080,7 +1080,7 @@ bool tr_sys_dir_create_temp(char* path_template, tr_error** error)
{
bool ret;
assert(path_template != NULL);
TR_ASSERT(path_template != NULL);
#ifdef HAVE_MKDTEMP
@ -1109,7 +1109,7 @@ tr_sys_dir_t tr_sys_dir_open(char const* path, tr_error** error)
TR_STATIC_ASSERT(TR_BAD_SYS_DIR == NULL, "values should match");
#endif
assert(path != NULL);
TR_ASSERT(path != NULL);
ret = opendir(path);
@ -1126,7 +1126,7 @@ char const* tr_sys_dir_read_name(tr_sys_dir_t handle, tr_error** error)
char const* ret = NULL;
struct dirent* entry;
assert(handle != TR_BAD_SYS_DIR);
TR_ASSERT(handle != TR_BAD_SYS_DIR);
errno = 0;
entry = readdir(handle);
@ -1147,7 +1147,7 @@ bool tr_sys_dir_close(tr_sys_dir_t handle, tr_error** error)
{
bool ret;
assert(handle != TR_BAD_SYS_DIR);
TR_ASSERT(handle != TR_BAD_SYS_DIR);
ret = closedir(handle) != -1;

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <ctype.h> /* isalpha() */
#include <shlobj.h> /* SHCreateDirectoryEx() */
@ -16,6 +15,7 @@
#include "crypto-utils.h" /* tr_rand_int() */
#include "error.h"
#include "file.h"
#include "tr-assert.h"
#include "utils.h"
#ifndef MAXSIZE_T
@ -68,7 +68,7 @@ static time_t filetime_to_unix_time(FILETIME const* t)
{
uint64_t tmp = 0;
assert(t != NULL);
TR_ASSERT(t != NULL);
tmp |= t->dwHighDateTime;
tmp <<= 32;
@ -82,8 +82,8 @@ static time_t filetime_to_unix_time(FILETIME const* t)
static void stat_to_sys_path_info(DWORD attributes, DWORD size_low, DWORD size_high, FILETIME const* mtime,
tr_sys_path_info* info)
{
assert(mtime != NULL);
assert(info != NULL);
TR_ASSERT(mtime != NULL);
TR_ASSERT(info != NULL);
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
{
@ -156,7 +156,7 @@ static wchar_t* path_to_native_path_ex(char const* path, int extra_chars_after,
/* `-2` for UNC since we overwrite existing prefix slashes */
int const extra_chars_before = is_relative ? 0 : (is_unc ? TR_N_ELEMENTS(unc_prefix) - 2 : TR_N_ELEMENTS(local_prefix));
/* TODO (?): assert(!is_relative); */
/* TODO (?): TR_ASSERT(!is_relative); */
wchar_t* const wide_path = tr_win32_utf8_to_native_ex(path, -1, extra_chars_before, extra_chars_after, real_result_size);
@ -207,7 +207,7 @@ static tr_sys_file_t open_file(char const* path, DWORD access, DWORD disposition
tr_sys_file_t ret = TR_BAD_SYS_FILE;
wchar_t* wide_path;
assert(path != NULL);
TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
@ -233,7 +233,7 @@ static bool create_dir(char const* path, int flags, int permissions, bool okay_i
wchar_t* wide_path;
DWORD error_code = ERROR_SUCCESS;
assert(path != NULL);
TR_ASSERT(path != NULL);
(void)permissions;
@ -282,13 +282,13 @@ static void create_temp_path(char* path_template, void (* callback)(char const*
size_t path_size;
tr_error* my_error = NULL;
assert(path_template != NULL);
assert(callback != NULL);
TR_ASSERT(path_template != NULL);
TR_ASSERT(callback != NULL);
path = tr_strdup(path_template);
path_size = strlen(path);
assert(path_size > 0);
TR_ASSERT(path_size > 0);
for (int attempt = 0; attempt < 100; ++attempt)
{
@ -301,7 +301,7 @@ static void create_temp_path(char* path_template, void (* callback)(char const*
--i;
}
assert(path_size >= i + 6);
TR_ASSERT(path_size >= i + 6);
tr_error_clear(&my_error);
@ -331,7 +331,7 @@ bool tr_sys_path_exists(char const* path, tr_error** error)
wchar_t* wide_path;
HANDLE handle = INVALID_HANDLE_VALUE;
assert(path != NULL);
TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
@ -373,8 +373,8 @@ bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, t
bool ret = false;
wchar_t* wide_path;
assert(path != NULL);
assert(info != NULL);
TR_ASSERT(path != NULL);
TR_ASSERT(info != NULL);
wide_path = path_to_native_path(path);
@ -431,7 +431,7 @@ bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, t
bool tr_sys_path_is_relative(char const* path)
{
assert(path != NULL);
TR_ASSERT(path != NULL);
/* UNC path: `\\...`. */
if (is_unc_path(path))
@ -457,8 +457,8 @@ bool tr_sys_path_is_same(char const* path1, char const* path2, tr_error** error)
HANDLE handle2 = INVALID_HANDLE_VALUE;
BY_HANDLE_FILE_INFORMATION fi1, fi2;
assert(path1 != NULL);
assert(path2 != NULL);
TR_ASSERT(path1 != NULL);
TR_ASSERT(path2 != NULL);
wide_path1 = path_to_native_path(path1);
@ -521,7 +521,7 @@ char* tr_sys_path_resolve(char const* path, tr_error** error)
HANDLE handle = INVALID_HANDLE_VALUE;
DWORD wide_ret_size;
assert(path != NULL);
TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
@ -681,8 +681,8 @@ bool tr_sys_path_rename(char const* src_path, char const* dst_path, tr_error** e
wchar_t* wide_src_path;
wchar_t* wide_dst_path;
assert(src_path != NULL);
assert(dst_path != NULL);
TR_ASSERT(src_path != NULL);
TR_ASSERT(dst_path != NULL);
wide_src_path = path_to_native_path(src_path);
wide_dst_path = path_to_native_path(dst_path);
@ -727,7 +727,7 @@ bool tr_sys_path_remove(char const* path, tr_error** error)
bool ret = false;
wchar_t* wide_path;
assert(path != NULL);
TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
@ -777,7 +777,7 @@ tr_sys_file_t tr_sys_file_get_std(tr_std_sys_file_t std_file, tr_error** error)
break;
default:
assert(0 && "Unknown standard file");
TR_ASSERT_MSG(false, "unknown standard file %d", (int)std_file);
set_system_error(error, ERROR_INVALID_PARAMETER);
return TR_BAD_SYS_FILE;
}
@ -802,8 +802,8 @@ tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, tr_
DWORD native_flags = FILE_ATTRIBUTE_NORMAL;
bool success;
assert(path != NULL);
assert((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
TR_ASSERT(path != NULL);
TR_ASSERT((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
(void)permissions;
@ -862,7 +862,7 @@ static void file_open_temp_callback(char const* path, void* param, tr_error** er
{
tr_sys_file_t* result = (tr_sys_file_t*)param;
assert(result != NULL);
TR_ASSERT(result != NULL);
*result = open_file(path, GENERIC_READ | GENERIC_WRITE, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY, error);
}
@ -871,7 +871,7 @@ tr_sys_file_t tr_sys_file_open_temp(char* path_template, tr_error** error)
{
tr_sys_file_t ret = TR_BAD_SYS_FILE;
assert(path_template != NULL);
TR_ASSERT(path_template != NULL);
create_temp_path(path_template, file_open_temp_callback, &ret, error);
@ -882,7 +882,7 @@ bool tr_sys_file_close(tr_sys_file_t handle, tr_error** error)
{
bool ret;
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = CloseHandle(handle);
@ -899,8 +899,8 @@ bool tr_sys_file_get_info(tr_sys_file_t handle, tr_sys_path_info* info, tr_error
bool ret;
BY_HANDLE_FILE_INFORMATION attributes;
assert(handle != TR_BAD_SYS_FILE);
assert(info != NULL);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(info != NULL);
ret = GetFileInformationByHandle(handle, &attributes);
@ -926,8 +926,8 @@ bool tr_sys_file_seek(tr_sys_file_t handle, int64_t offset, tr_seek_origin_t ori
TR_STATIC_ASSERT(TR_SEEK_CUR == FILE_CURRENT, "values should match");
TR_STATIC_ASSERT(TR_SEEK_END == FILE_END, "values should match");
assert(handle != TR_BAD_SYS_FILE);
assert(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
native_offset.QuadPart = offset;
@ -953,8 +953,8 @@ bool tr_sys_file_read(tr_sys_file_t handle, void* buffer, uint64_t size, uint64_
bool ret = false;
DWORD my_bytes_read;
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
@ -986,8 +986,8 @@ bool tr_sys_file_read_at(tr_sys_file_t handle, void* buffer, uint64_t size, uint
OVERLAPPED overlapped;
DWORD my_bytes_read;
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
@ -1022,8 +1022,8 @@ bool tr_sys_file_write(tr_sys_file_t handle, void const* buffer, uint64_t size,
bool ret = false;
DWORD my_bytes_written;
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
@ -1055,8 +1055,8 @@ bool tr_sys_file_write_at(tr_sys_file_t handle, void const* buffer, uint64_t siz
OVERLAPPED overlapped;
DWORD my_bytes_written;
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL || size == 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
@ -1090,7 +1090,7 @@ bool tr_sys_file_flush(tr_sys_file_t handle, tr_error** error)
{
bool ret;
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = FlushFileBuffers(handle);
@ -1107,7 +1107,7 @@ bool tr_sys_file_truncate(tr_sys_file_t handle, uint64_t size, tr_error** error)
bool ret = false;
FILE_END_OF_FILE_INFO info;
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
info.EndOfFile.QuadPart = size;
@ -1125,8 +1125,8 @@ bool tr_sys_file_prefetch(tr_sys_file_t handle, uint64_t offset, uint64_t size,
{
bool ret = false;
assert(handle != TR_BAD_SYS_FILE);
assert(size > 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(size > 0);
(void)handle;
(void)offset;
@ -1140,7 +1140,7 @@ bool tr_sys_file_prefetch(tr_sys_file_t handle, uint64_t offset, uint64_t size,
bool tr_sys_file_preallocate(tr_sys_file_t handle, uint64_t size, int flags, tr_error** error)
{
assert(handle != TR_BAD_SYS_FILE);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
if ((flags & TR_SYS_FILE_PREALLOC_SPARSE) != 0)
{
@ -1161,8 +1161,8 @@ void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_
void* ret = NULL;
HANDLE mappingHandle;
assert(handle != TR_BAD_SYS_FILE);
assert(size > 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(size > 0);
if (size > MAXSIZE_T)
{
@ -1195,8 +1195,8 @@ bool tr_sys_file_unmap(void const* address, uint64_t size, tr_error** error)
{
bool ret;
assert(address != NULL);
assert(size > 0);
TR_ASSERT(address != NULL);
TR_ASSERT(size > 0);
(void)size;
@ -1215,9 +1215,9 @@ bool tr_sys_file_lock(tr_sys_file_t handle, int operation, tr_error** error)
bool ret;
OVERLAPPED overlapped = { .Pointer = 0, .hEvent = NULL };
assert(handle != TR_BAD_SYS_FILE);
assert((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
assert(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
TR_ASSERT(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
!!(operation & TR_SYS_FILE_LOCK_UN) == 1);
if ((operation & TR_SYS_FILE_LOCK_UN) == 0)
@ -1286,7 +1286,7 @@ static void dir_create_temp_callback(char const* path, void* param, tr_error** e
{
bool* result = (bool*)param;
assert(result != NULL);
TR_ASSERT(result != NULL);
*result = create_dir(path, 0, 0, false, error);
}
@ -1295,7 +1295,7 @@ bool tr_sys_dir_create_temp(char* path_template, tr_error** error)
{
bool ret = false;
assert(path_template != NULL);
TR_ASSERT(path_template != NULL);
create_temp_path(path_template, dir_create_temp_callback, &ret, error);
@ -1312,7 +1312,7 @@ tr_sys_dir_t tr_sys_dir_open(char const* path, tr_error** error)
TR_STATIC_ASSERT(TR_BAD_SYS_DIR == NULL, "values should match");
#endif
assert(path != NULL);
TR_ASSERT(path != NULL);
ret = tr_new(struct tr_sys_dir_win32, 1);
ret->pattern = path_to_native_path_ex(path, 2, &pattern_size);
@ -1343,7 +1343,7 @@ char const* tr_sys_dir_read_name(tr_sys_dir_t handle, tr_error** error)
char* ret;
DWORD error_code = ERROR_SUCCESS;
assert(handle != TR_BAD_SYS_DIR);
TR_ASSERT(handle != TR_BAD_SYS_DIR);
if (handle->find_handle == INVALID_HANDLE_VALUE)
{
@ -1387,7 +1387,7 @@ bool tr_sys_dir_close(tr_sys_dir_t handle, tr_error** error)
{
bool ret;
assert(handle != TR_BAD_SYS_DIR);
TR_ASSERT(handle != TR_BAD_SYS_DIR);
ret = FindClose(handle->find_handle);

View File

@ -6,12 +6,12 @@
*
*/
#include <assert.h>
#include <string.h> /* strlen() */
#include "transmission.h"
#include "error.h"
#include "file.h"
#include "tr-assert.h"
#include "utils.h"
bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_size, tr_error** error)
@ -20,9 +20,9 @@ bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_siz
size_t offset = 0;
uint64_t bytes_read;
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL);
assert(buffer_size > 0);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL);
TR_ASSERT(buffer_size > 0);
while (buffer_size > 0)
{
@ -77,8 +77,8 @@ bool tr_sys_file_write_line(tr_sys_file_t handle, char const* buffer, tr_error**
{
bool ret;
assert(handle != TR_BAD_SYS_FILE);
assert(buffer != NULL);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(buffer != NULL);
ret = tr_sys_file_write(handle, buffer, strlen(buffer), NULL, error);
@ -96,8 +96,8 @@ bool tr_sys_file_write_fmt(tr_sys_file_t handle, char const* format, tr_error**
char* buffer;
va_list args;
assert(handle != TR_BAD_SYS_FILE);
assert(format != NULL);
TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT(format != NULL);
va_start(args, error);
buffer = tr_strdup_vprintf(format, args);

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <string.h> /* strcmp(), strlen(), strncmp() */
@ -22,6 +21,7 @@
#include "peer-mgr.h"
#include "session.h"
#include "torrent.h"
#include "tr-assert.h"
#include "tr-dht.h"
#include "utils.h"
@ -214,7 +214,7 @@ static bool buildHandshakeMessage(tr_handshake* handshake, uint8_t* buf)
memcpy(walk, peer_id, PEER_ID_LEN);
walk += PEER_ID_LEN;
assert(walk - buf == HANDSHAKE_SIZE);
TR_ASSERT(walk - buf == HANDSHAKE_SIZE);
success = true;
}
@ -260,7 +260,7 @@ static handshake_parse_err_t parseHandshake(tr_handshake* handshake, struct evbu
/* torrent hash */
tr_peerIoReadBytes(handshake->io, inbuf, hash, sizeof(hash));
assert(tr_peerIoHasTorrentHash(handshake->io));
TR_ASSERT(tr_peerIoHasTorrentHash(handshake->io));
if (!tr_torrentExists(handshake->session, hash) ||
memcmp(hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH) != 0)
@ -312,8 +312,8 @@ static void sendYa(tr_handshake* handshake)
/* add our public key (Ya) */
public_key = tr_cryptoGetMyPublicKey(handshake->crypto, &len);
assert(len == KEY_LEN);
assert(public_key != NULL);
TR_ASSERT(len == KEY_LEN);
TR_ASSERT(public_key != NULL);
memcpy(walk, public_key, len);
walk += len;
@ -643,7 +643,7 @@ static ReadState readHandshake(tr_handshake* handshake, struct evbuffer* inbuf)
evbuffer_drain(inbuf, 1);
/* pstr (BitTorrent) */
assert(pstrlen == 19);
TR_ASSERT(pstrlen == 19);
tr_peerIoReadBytes(handshake->io, inbuf, pstr, pstrlen);
pstr[pstrlen] = '\0';
@ -675,13 +675,13 @@ static ReadState readHandshake(tr_handshake* handshake, struct evbuffer* inbuf)
}
else
{
assert(!tr_peerIoHasTorrentHash(handshake->io));
TR_ASSERT(!tr_peerIoHasTorrentHash(handshake->io));
tr_peerIoSetTorrentHash(handshake->io, hash);
}
}
else /* outgoing */
{
assert(tr_peerIoHasTorrentHash(handshake->io));
TR_ASSERT(tr_peerIoHasTorrentHash(handshake->io));
if (memcmp(hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH) != 0)
{
@ -1019,7 +1019,7 @@ static ReadState canRead(struct tr_peerIo* io, void* arg, size_t* piece)
struct evbuffer* inbuf = tr_peerIoGetReadBuffer(io);
bool readyForMore = true;
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
/* no piece data in handshake */
*piece = 0;
@ -1079,7 +1079,7 @@ static ReadState canRead(struct tr_peerIo* io, void* arg, size_t* piece)
break;
default:
assert(0);
TR_ASSERT_MSG(false, "unhandled handshake state %d", (int)handshake->state);
}
if (ret != READ_NOW)
@ -1253,8 +1253,8 @@ tr_handshake* tr_handshakeNew(tr_peerIo* io, tr_encryption_mode encryptionMode,
struct tr_peerIo* tr_handshakeGetIO(tr_handshake* handshake)
{
assert(handshake != NULL);
assert(handshake->io != NULL);
TR_ASSERT(handshake != NULL);
TR_ASSERT(handshake->io != NULL);
return handshake->io;
}
@ -1263,8 +1263,8 @@ struct tr_peerIo* tr_handshakeStealIO(tr_handshake* handshake)
{
struct tr_peerIo* io;
assert(handshake != NULL);
assert(handshake->io != NULL);
TR_ASSERT(handshake != NULL);
TR_ASSERT(handshake->io != NULL);
io = handshake->io;
handshake->io = NULL;
@ -1273,8 +1273,8 @@ struct tr_peerIo* tr_handshakeStealIO(tr_handshake* handshake)
tr_address const* tr_handshakeGetAddr(struct tr_handshake const* handshake, tr_port* port)
{
assert(handshake != NULL);
assert(handshake->io != NULL);
TR_ASSERT(handshake != NULL);
TR_ASSERT(handshake->io != NULL);
return tr_peerIoGetAddress(handshake->io, port);
}

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <string.h> /* memset() */
#include "transmission.h"

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdlib.h> /* bsearch() */
#include <string.h> /* memcmp() */
@ -22,6 +21,7 @@
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "stats.h" /* tr_statsFileCreated() */
#include "torrent.h"
#include "tr-assert.h"
#include "utils.h"
/****
@ -46,9 +46,9 @@ static int readOrWriteBytes(tr_session* session, tr_torrent* tor, int ioMode, tr
tr_info const* const info = &tor->info;
tr_file const* const file = &info->files[fileIndex];
assert(fileIndex < info->fileCount);
assert(file->length == 0 || fileOffset < file->length);
assert(fileOffset + buflen <= file->length);
TR_ASSERT(fileIndex < info->fileCount);
TR_ASSERT(file->length == 0 || fileOffset < file->length);
TR_ASSERT(fileOffset + buflen <= file->length);
if (file->length == 0)
{
@ -169,19 +169,19 @@ void tr_ioFindFileLocation(tr_torrent const* tor, tr_piece_index_t pieceIndex, u
uint64_t const offset = tr_pieceOffset(tor, pieceIndex, pieceOffset, 0);
tr_file const* file;
assert(tr_isTorrent(tor));
assert(offset < tor->info.totalSize);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(offset < tor->info.totalSize);
file = bsearch(&offset, tor->info.files, tor->info.fileCount, sizeof(tr_file), compareOffsetToFile);
assert(file != NULL);
TR_ASSERT(file != NULL);
*fileIndex = file - tor->info.files;
*fileOffset = offset - file->offset;
assert(*fileIndex < tor->info.fileCount);
assert(*fileOffset < file->length);
assert(tor->info.files[*fileIndex].offset + *fileOffset == offset);
TR_ASSERT(*fileIndex < tor->info.fileCount);
TR_ASSERT(*fileOffset < file->length);
TR_ASSERT(tor->info.files[*fileIndex].offset + *fileOffset == offset);
}
/* returns 0 on success, or an errno on failure */
@ -250,11 +250,11 @@ static bool recalculateHash(tr_torrent* tor, tr_piece_index_t pieceIndex, uint8_
void* buffer = tr_valloc(buflen);
tr_sha1_ctx_t sha;
assert(tor != NULL);
assert(pieceIndex < tor->info.pieceCount);
assert(buffer != NULL);
assert(buflen > 0);
assert(setme != NULL);
TR_ASSERT(tor != NULL);
TR_ASSERT(pieceIndex < tor->info.pieceCount);
TR_ASSERT(buffer != NULL);
TR_ASSERT(buflen > 0);
TR_ASSERT(setme != NULL);
sha = tr_sha1_init();
bytesLeft = tr_torPieceCountBytes(tor, pieceIndex);

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> /* mkstemp() */
@ -22,6 +21,7 @@
#include "file.h"
#include "platform.h" /* TR_PATH_DELIMETER */
#include "torrent.h"
#include "tr-assert.h"
#include "trevent.h"
#include "variant.h"
#include "libtransmission-test.h"
@ -416,9 +416,9 @@ tr_torrent* libttest_zero_torrent_init(tr_session* session)
/* create the torrent ctor */
metainfo = tr_base64_decode_str(metainfo_base64, &metainfo_len);
assert(metainfo != NULL);
assert(metainfo_len > 0);
assert(session != NULL);
TR_ASSERT(metainfo != NULL);
TR_ASSERT(metainfo_len > 0);
TR_ASSERT(session != NULL);
ctor = tr_ctorNew(session);
tr_ctorSetMetainfo(ctor, (uint8_t*)metainfo, metainfo_len);
tr_ctorSetPaused(ctor, TR_FORCE, true);
@ -426,7 +426,7 @@ tr_torrent* libttest_zero_torrent_init(tr_session* session)
/* create the torrent */
err = 0;
tor = tr_torrentNew(ctor, &err, NULL);
assert(err == 0);
TR_ASSERT(err == 0);
/* cleanup */
tr_free(metainfo);
@ -468,9 +468,9 @@ void libttest_zero_torrent_populate(tr_torrent* tor, bool complete)
tr_free(path);
path = tr_torrentFindFile(tor, i);
assert(path != NULL);
TR_ASSERT(path != NULL);
err = errno;
assert(tr_sys_path_exists(path, NULL));
TR_ASSERT(tr_sys_path_exists(path, NULL));
errno = err;
tr_free(path);
}
@ -480,11 +480,11 @@ void libttest_zero_torrent_populate(tr_torrent* tor, bool complete)
if (complete)
{
assert(tr_torrentStat(tor)->leftUntilDone == 0);
TR_ASSERT(tr_torrentStat(tor)->leftUntilDone == 0);
}
else
{
assert(tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
TR_ASSERT(tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
}
}
@ -501,8 +501,8 @@ void libttest_blockingTorrentVerify(tr_torrent* tor)
{
bool done = false;
assert(tor->session != NULL);
assert(!tr_amInEventThread(tor->session));
TR_ASSERT(tor->session != NULL);
TR_ASSERT(!tr_amInEventThread(tor->session));
tr_torrentVerify(tor, onVerifyDone, &done);
@ -520,7 +520,7 @@ static void build_parent_dir(char const* path)
dir = tr_sys_path_dirname(path, NULL);
tr_sys_dir_create(dir, TR_SYS_DIR_CREATE_PARENTS, 0700, &error);
assert(error == NULL);
TR_ASSERT(error == NULL);
tr_free(dir);
errno = tmperr;

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@ -16,6 +15,7 @@
#include "file.h"
#include "log.h"
#include "platform.h" /* tr_lock */
#include "tr-assert.h"
#include "utils.h"
tr_log_level __tr_message_level = TR_LOG_ERROR;
@ -270,7 +270,7 @@ void tr_logAddMessage(char const* file, int line, tr_log_level level, char const
old->next = NULL;
tr_logFreeQueue(old);
--myQueueLength;
assert(myQueueLength == TR_LOG_MAX_QUEUE_LENGTH);
TR_ASSERT(myQueueLength == TR_LOG_MAX_QUEUE_LENGTH);
}
}
else

View File

@ -6,13 +6,13 @@
*
*/
#include <assert.h>
#include <string.h> /* strchr() */
#include <stdio.h> /* sscanf() */
#include "transmission.h"
#include "crypto-utils.h" /* tr_hex_to_sha1() */
#include "magnet.h"
#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "web.h"
@ -46,7 +46,7 @@ static void base32_to_sha1(uint8_t* out, char const* in, size_t const inlen)
memset(out, 0, 20);
assert(inlen == 32);
TR_ASSERT(inlen == 32);
for (size_t i = 0, index = 0, offset = 0; i < inlen; ++i)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdlib.h> /* qsort */
#include <string.h> /* strcmp, strlen */
@ -21,6 +20,7 @@
#include "session.h"
#include "makemeta.h"
#include "platform.h" /* threads, locks */
#include "tr-assert.h"
#include "utils.h" /* buildpath */
#include "variant.h"
#include "version.h"
@ -278,7 +278,7 @@ static uint8_t* getHashInfo(tr_metainfo_builder* b)
uint32_t const thisPieceSize = (uint32_t)MIN(b->pieceSize, totalRemain);
uint64_t leftInPiece = thisPieceSize;
assert(b->pieceIndex < b->pieceCount);
TR_ASSERT(b->pieceIndex < b->pieceCount);
while (leftInPiece != 0)
{
@ -313,8 +313,8 @@ static uint8_t* getHashInfo(tr_metainfo_builder* b)
}
}
assert(bufptr - buf == (int)thisPieceSize);
assert(leftInPiece == 0);
TR_ASSERT(bufptr - buf == (int)thisPieceSize);
TR_ASSERT(leftInPiece == 0);
tr_sha1(walk, buf, (int)thisPieceSize, NULL);
walk += SHA_DIGEST_LENGTH;
@ -328,8 +328,8 @@ static uint8_t* getHashInfo(tr_metainfo_builder* b)
++b->pieceIndex;
}
assert(b->abortFlag || walk - ret == (int)(SHA_DIGEST_LENGTH * b->pieceCount));
assert(b->abortFlag || !totalRemain);
TR_ASSERT(b->abortFlag || walk - ret == (int)(SHA_DIGEST_LENGTH * b->pieceCount));
TR_ASSERT(b->abortFlag || !totalRemain);
if (fd != TR_BAD_SYS_FILE)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <string.h> /* strlen() */
#include <event2/buffer.h>
@ -18,6 +17,7 @@
#include "metainfo.h"
#include "platform.h" /* tr_getTorrentDir() */
#include "session.h"
#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
@ -79,7 +79,7 @@ static bool getfile(char** setme, char const* root, tr_variant* path, struct evb
*setme = NULL;
/* root's already been checked by caller */
assert(!path_component_is_suspicious(root));
TR_ASSERT(!path_component_is_suspicious(root));
if (tr_variantIsList(path))
{
@ -235,7 +235,7 @@ static char* tr_convertAnnounceToScrape(char const* announce)
memcpy(walk, suffix, suffix_len);
walk += suffix_len;
*walk++ = '\0';
assert(walk - scrape == (int)alloc_len);
TR_ASSERT(walk - scrape == (int)alloc_len);
}
/* Some torrents with UDP annouce URLs don't have /announce. */
else if (strncmp(announce, "udp:", 4) == 0)

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <string.h> /* strcmp() */
#include <stdio.h>

View File

@ -22,7 +22,6 @@
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
@ -38,11 +37,12 @@
#include "transmission.h"
#include "fdlimit.h" /* tr_fdSocketClose() */
#include "log.h"
#include "net.h"
#include "peer-io.h" /* tr_peerIoAddrStr() FIXME this should be moved to net.h */
#include "session.h" /* tr_sessionGetPublicAddress() */
#include "tr-assert.h"
#include "tr-utp.h" /* tr_utpSendTo() */
#include "log.h"
#include "utils.h" /* tr_time(), tr_logAddDebug() */
#ifndef IN_MULTICAST
@ -76,7 +76,7 @@ char* tr_net_strerror(char* buf, size_t buflen, int err)
char const* tr_address_to_string_with_buf(tr_address const* addr, char* buf, size_t buflen)
{
assert(tr_address_is_valid(addr));
TR_ASSERT(tr_address_is_valid(addr));
if (addr->type == TR_AF_INET)
{
@ -206,7 +206,7 @@ bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_por
static socklen_t setup_sockaddr(tr_address const* addr, tr_port port, struct sockaddr_storage* sockaddr)
{
assert(tr_address_is_valid(addr));
TR_ASSERT(tr_address_is_valid(addr));
if (addr->type == TR_AF_INET)
{
@ -242,7 +242,7 @@ tr_socket_t tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr
struct sockaddr_storage source_sock;
char err_buf[512];
assert(tr_address_is_valid(addr));
TR_ASSERT(tr_address_is_valid(addr));
if (!tr_address_is_valid_for_peers(addr, port))
{
@ -278,7 +278,7 @@ tr_socket_t tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr
/* set source address */
source_addr = tr_sessionGetPublicAddress(session, addr->type, NULL);
assert(source_addr);
TR_ASSERT(source_addr);
sourcelen = setup_sockaddr(source_addr, 0, &source_sock);
if (bind(s, (struct sockaddr*)&source_sock, sourcelen) == -1)
@ -336,7 +336,7 @@ static tr_socket_t tr_netBindTCPImpl(tr_address const* addr, tr_port port, bool
int addrlen;
int optval;
assert(tr_address_is_valid(addr));
TR_ASSERT(tr_address_is_valid(addr));
fd = socket(domains[addr->type], SOCK_STREAM, 0);
@ -686,7 +686,7 @@ static bool isMartianAddr(struct tr_address const* a)
{
static unsigned char const zeroes[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
assert(tr_address_is_valid(a));
TR_ASSERT(tr_address_is_valid(a));
switch (a->type)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <string.h>
@ -23,8 +22,9 @@
#include "net.h"
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "peer-io.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "tr-assert.h"
#include "tr-utp.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
#ifdef _WIN32
@ -245,7 +245,7 @@ static void canReadWrapper(tr_peerIo* io)
break;
}
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
}
tr_sessionUnlock(session);
@ -266,8 +266,8 @@ static void event_read_cb(evutil_socket_t fd, short event UNUSED, void* vio)
tr_direction const dir = TR_DOWN;
unsigned int const max = 256 * 1024;
assert(tr_isPeerIo(io));
assert(io->socket != TR_BAD_SOCKET);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(io->socket != TR_BAD_SOCKET);
io->pendingEvents &= ~EV_READ;
@ -349,8 +349,8 @@ static void event_write_cb(evutil_socket_t fd, short event UNUSED, void* vio)
tr_direction const dir = TR_UP;
char errstr[1024];
assert(tr_isPeerIo(io));
assert(io->socket != TR_BAD_SOCKET);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(io->socket != TR_BAD_SOCKET);
io->pendingEvents &= ~EV_WRITE;
@ -437,7 +437,7 @@ static void utp_on_read(void* closure, unsigned char const* buf, size_t buflen)
{
int rc;
tr_peerIo* io = closure;
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
rc = evbuffer_add(io->inbuf, buf, buflen);
dbgmsg(io, "utp_on_read got %zu bytes", buflen);
@ -456,11 +456,11 @@ static void utp_on_write(void* closure, unsigned char* buf, size_t buflen)
{
int rc;
tr_peerIo* io = closure;
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
rc = evbuffer_remove(io->outbuf, buf, buflen);
dbgmsg(io, "utp_on_write sending %zu bytes... evbuffer_remove returned %d", buflen, rc);
assert(rc == (int)buflen); /* if this fails, we've corrupted our bookkeeping somewhere */
TR_ASSERT(rc == (int)buflen); /* if this fails, we've corrupted our bookkeeping somewhere */
if (rc < (long)buflen)
{
@ -474,7 +474,7 @@ static size_t utp_get_rb_size(void* closure)
{
size_t bytes;
tr_peerIo* io = closure;
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
bytes = tr_bandwidthClamp(&io->bandwidth, TR_DOWN, UTP_READ_BUFFER_SIZE);
@ -497,7 +497,7 @@ static void utp_on_writable(tr_peerIo* io)
static void utp_on_state_change(void* closure, int state)
{
tr_peerIo* io = closure;
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
if (state == UTP_STATE_CONNECT)
{
@ -534,7 +534,7 @@ static void utp_on_state_change(void* closure, int state)
static void utp_on_error(void* closure, int errcode)
{
tr_peerIo* io = closure;
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "utp_on_error -- errcode is %d", errcode);
@ -548,7 +548,7 @@ static void utp_on_error(void* closure, int errcode)
static void utp_on_overhead(void* closure, uint8_t /* bool */ send, size_t count, int type UNUSED)
{
tr_peerIo* io = closure;
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "utp_on_overhead -- count is %zu", count);
@ -617,12 +617,12 @@ static tr_peerIo* tr_peerIoNew(tr_session* session, tr_bandwidth* parent, tr_add
{
tr_peerIo* io;
assert(session != NULL);
assert(session->events != NULL);
assert(tr_amInEventThread(session));
assert((socket == TR_BAD_SOCKET) == (utp_socket != NULL));
TR_ASSERT(session != NULL);
TR_ASSERT(session->events != NULL);
TR_ASSERT(tr_amInEventThread(session));
TR_ASSERT((socket == TR_BAD_SOCKET) == (utp_socket != NULL));
#ifndef WITH_UTP
assert(socket != TR_BAD_SOCKET);
TR_ASSERT(socket != TR_BAD_SOCKET);
#endif
if (socket != TR_BAD_SOCKET)
@ -679,8 +679,8 @@ static tr_peerIo* tr_peerIoNew(tr_session* session, tr_bandwidth* parent, tr_add
tr_peerIo* tr_peerIoNewIncoming(tr_session* session, tr_bandwidth* parent, tr_address const* addr, tr_port port, tr_socket_t fd,
struct UTPSocket* utp_socket)
{
assert(session != NULL);
assert(tr_address_is_valid(addr));
TR_ASSERT(session != NULL);
TR_ASSERT(tr_address_is_valid(addr));
return tr_peerIoNew(session, parent, addr, port, NULL, true, false, fd, utp_socket);
}
@ -691,9 +691,9 @@ tr_peerIo* tr_peerIoNewOutgoing(tr_session* session, tr_bandwidth* parent, tr_ad
tr_socket_t fd = TR_BAD_SOCKET;
struct UTPSocket* utp_socket = NULL;
assert(session != NULL);
assert(tr_address_is_valid(addr));
assert(torrentHash != NULL);
TR_ASSERT(session != NULL);
TR_ASSERT(tr_address_is_valid(addr));
TR_ASSERT(torrentHash != NULL);
if (utp)
{
@ -720,14 +720,14 @@ tr_peerIo* tr_peerIoNewOutgoing(tr_session* session, tr_bandwidth* parent, tr_ad
static void event_enable(tr_peerIo* io, short event)
{
assert(tr_amInEventThread(io->session));
assert(io->session != NULL);
assert(io->session->events != NULL);
TR_ASSERT(tr_amInEventThread(io->session));
TR_ASSERT(io->session != NULL);
TR_ASSERT(io->session->events != NULL);
if (io->socket != TR_BAD_SOCKET)
{
assert(event_initialized(io->event_read));
assert(event_initialized(io->event_write));
TR_ASSERT(event_initialized(io->event_read));
TR_ASSERT(event_initialized(io->event_write));
}
if ((event & EV_READ) != 0 && (io->pendingEvents & EV_READ) == 0)
@ -757,14 +757,14 @@ static void event_enable(tr_peerIo* io, short event)
static void event_disable(struct tr_peerIo* io, short event)
{
assert(tr_amInEventThread(io->session));
assert(io->session != NULL);
assert(io->session->events != NULL);
TR_ASSERT(tr_amInEventThread(io->session));
TR_ASSERT(io->session != NULL);
TR_ASSERT(io->session->events != NULL);
if (io->socket != TR_BAD_SOCKET)
{
assert(event_initialized(io->event_read));
assert(event_initialized(io->event_write));
TR_ASSERT(event_initialized(io->event_read));
TR_ASSERT(event_initialized(io->event_write));
}
if ((event & EV_READ) != 0 && (io->pendingEvents & EV_READ) != 0)
@ -796,10 +796,10 @@ void tr_peerIoSetEnabled(tr_peerIo* io, tr_direction dir, bool isEnabled)
{
short const event = dir == TR_UP ? EV_WRITE : EV_READ;
assert(tr_isPeerIo(io));
assert(tr_isDirection(dir));
assert(tr_amInEventThread(io->session));
assert(io->session->events != NULL);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(tr_isDirection(dir));
TR_ASSERT(tr_amInEventThread(io->session));
TR_ASSERT(io->session->events != NULL);
if (isEnabled)
{
@ -852,9 +852,9 @@ static void io_dtor(void* vio)
{
tr_peerIo* io = vio;
assert(tr_isPeerIo(io));
assert(tr_amInEventThread(io->session));
assert(io->session->events != NULL);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(tr_amInEventThread(io->session));
TR_ASSERT(io->session->events != NULL);
dbgmsg(io, "in tr_peerIo destructor");
event_disable(io, EV_READ | EV_WRITE);
@ -887,7 +887,7 @@ static void tr_peerIoFree(tr_peerIo* io)
void tr_peerIoRefImpl(char const* file, int line, tr_peerIo* io)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "%s:%d is incrementing the IO's refcount from %d to %d", file, line, io->refCount, io->refCount + 1);
@ -896,7 +896,7 @@ void tr_peerIoRefImpl(char const* file, int line, tr_peerIo* io)
void tr_peerIoUnrefImpl(char const* file, int line, tr_peerIo* io)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "%s:%d is decrementing the IO's refcount from %d to %d", file, line, io->refCount, io->refCount - 1);
@ -908,7 +908,7 @@ void tr_peerIoUnrefImpl(char const* file, int line, tr_peerIo* io)
tr_address const* tr_peerIoGetAddress(tr_peerIo const* io, tr_port* port)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
if (port != NULL)
{
@ -950,8 +950,8 @@ int tr_peerIoReconnect(tr_peerIo* io)
short int pendingEvents;
tr_session* session;
assert(tr_isPeerIo(io));
assert(!tr_peerIoIsIncoming(io));
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(!tr_peerIoIsIncoming(io));
session = tr_peerIoGetSession(io);
@ -981,21 +981,21 @@ int tr_peerIoReconnect(tr_peerIo* io)
void tr_peerIoSetTorrentHash(tr_peerIo* io, uint8_t const* hash)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
tr_cryptoSetTorrentHash(&io->crypto, hash);
}
uint8_t const* tr_peerIoGetTorrentHash(tr_peerIo* io)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
return tr_cryptoGetTorrentHash(&io->crypto);
}
bool tr_peerIoHasTorrentHash(tr_peerIo const* io)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
return tr_cryptoHasTorrentHash(&io->crypto);
}
@ -1006,7 +1006,7 @@ bool tr_peerIoHasTorrentHash(tr_peerIo const* io)
void tr_peerIoSetPeersId(tr_peerIo* io, uint8_t const* peer_id)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
if ((io->peerIdIsSet = peer_id != NULL))
{
@ -1055,8 +1055,8 @@ size_t tr_peerIoGetWriteBufferSpace(tr_peerIo const* io, uint64_t now)
void tr_peerIoSetEncryption(tr_peerIo* io, tr_encryption_type encryption_type)
{
assert(tr_isPeerIo(io));
assert(encryption_type == PEER_ENCRYPTION_NONE || encryption_type == PEER_ENCRYPTION_RC4);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(encryption_type == PEER_ENCRYPTION_NONE || encryption_type == PEER_ENCRYPTION_RC4);
io->encryption_type = encryption_type;
}
@ -1082,12 +1082,12 @@ static inline void processBuffer(tr_crypto* crypto, struct evbuffer* buffer, siz
callback(crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base);
assert(size >= iovec.iov_len);
TR_ASSERT(size >= iovec.iov_len);
size -= iovec.iov_len;
}
while (!evbuffer_ptr_set(buffer, &pos, iovec.iov_len, EVBUFFER_PTR_ADD));
assert(size == 0);
TR_ASSERT(size == 0);
}
static void addDatatype(tr_peerIo* io, size_t byteCount, bool isPieceData)
@ -1180,8 +1180,8 @@ void tr_peerIoReadBytesToBuf(tr_peerIo* io, struct evbuffer* inbuf, struct evbuf
struct evbuffer* tmp;
size_t const old_length = evbuffer_get_length(outbuf);
assert(tr_isPeerIo(io));
assert(evbuffer_get_length(inbuf) >= byteCount);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(evbuffer_get_length(inbuf) >= byteCount);
/* append it to outbuf */
tmp = evbuffer_new();
@ -1194,8 +1194,8 @@ void tr_peerIoReadBytesToBuf(tr_peerIo* io, struct evbuffer* inbuf, struct evbuf
void tr_peerIoReadBytes(tr_peerIo* io, struct evbuffer* inbuf, void* bytes, size_t byteCount)
{
assert(tr_isPeerIo(io));
assert(evbuffer_get_length(inbuf) >= byteCount);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(evbuffer_get_length(inbuf) >= byteCount);
switch (io->encryption_type)
{
@ -1209,7 +1209,7 @@ void tr_peerIoReadBytes(tr_peerIo* io, struct evbuffer* inbuf, void* bytes, size
break;
default:
assert(false);
TR_ASSERT_MSG(false, "unhandled encryption type %d", (int)io->encryption_type);
}
}
@ -1347,8 +1347,8 @@ int tr_peerIoFlush(tr_peerIo* io, tr_direction dir, size_t limit)
{
int bytesUsed = 0;
assert(tr_isPeerIo(io));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(tr_isDirection(dir));
if (dir == TR_DOWN)
{

View File

@ -176,8 +176,8 @@ static inline bool tr_peerIoSupportsUTP(tr_peerIo const* io)
static inline tr_session* tr_peerIoGetSession(tr_peerIo* io)
{
assert(tr_isPeerIo(io));
assert(io->session != NULL);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(io->session != NULL);
return io->session;
}
@ -214,8 +214,8 @@ void tr_peerIoSetPeersId(tr_peerIo* io, uint8_t const* peer_id);
static inline uint8_t const* tr_peerIoGetPeersId(tr_peerIo const* io)
{
assert(tr_isPeerIo(io));
assert(io->peerIdIsSet);
TR_ASSERT(tr_isPeerIo(io));
TR_ASSERT(io->peerIdIsSet);
return io->peerId;
}
@ -295,7 +295,7 @@ size_t tr_peerIoGetWriteBufferSpace(tr_peerIo const* io, uint64_t now);
static inline void tr_peerIoSetParent(tr_peerIo* io, struct tr_bandwidth* parent)
{
assert(tr_isPeerIo(io));
TR_ASSERT(tr_isPeerIo(io));
tr_bandwidthSetParent(&io->bandwidth, parent);
}

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h> /* error codes ERANGE, ... */
#include <limits.h> /* INT_MAX */
#include <string.h> /* memcpy, memcmp, strstr */
@ -34,6 +33,7 @@
#include "session.h"
#include "stats.h" /* tr_statsAddUploaded, tr_statsAddDownloaded */
#include "torrent.h"
#include "tr-assert.h"
#include "tr-utp.h"
#include "utils.h"
#include "webseed.h"
@ -125,9 +125,9 @@ struct peer_atom
tr_address addr;
};
#ifdef NDEBUG
#ifndef TR_ENABLE_ASSERTS
#define tr_isAtom(a) (TRUE)
#define tr_isAtom(a) (true)
#else
@ -231,8 +231,8 @@ struct tr_peerMgr
static bool tr_peerIsTransferringPieces(tr_peer const* peer, uint64_t now, tr_direction direction, unsigned int* Bps)
{
assert(peer != NULL);
assert(peer->funcs != NULL);
TR_ASSERT(peer != NULL);
TR_ASSERT(peer->funcs != NULL);
return (*peer->funcs->is_transferring_pieces)(peer, now, direction, Bps);
}
@ -246,8 +246,8 @@ unsigned int tr_peerGetPieceSpeed_Bps(tr_peer const* peer, uint64_t now, tr_dire
static void tr_peerFree(tr_peer* peer)
{
assert(peer != NULL);
assert(peer->funcs != NULL);
TR_ASSERT(peer != NULL);
TR_ASSERT(peer->funcs != NULL);
(*peer->funcs->destruct)(peer);
@ -256,8 +256,8 @@ static void tr_peerFree(tr_peer* peer)
void tr_peerConstruct(tr_peer* peer, tr_torrent const* tor)
{
assert(peer != NULL);
assert(tr_isTorrent(tor));
TR_ASSERT(peer != NULL);
TR_ASSERT(tr_isTorrent(tor));
memset(peer, 0, sizeof(tr_peer));
@ -271,7 +271,7 @@ static void peerDeclinedAllRequests(tr_swarm*, tr_peer const*);
void tr_peerDestruct(tr_peer* peer)
{
assert(peer != NULL);
TR_ASSERT(peer != NULL);
if (peer->swarm != NULL)
{
@ -311,14 +311,14 @@ static inline void swarmUnlock(tr_swarm* swarm)
managerUnlock(swarm->manager);
}
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
static inline int swarmIsLocked(tr_swarm const* swarm)
{
return tr_sessionIsLocked(swarm->manager->session);
}
#endif /* NDEBUG */
#endif /* TR_ENABLE_ASSERTS */
/**
***
@ -357,7 +357,7 @@ static int compareAtomsByAddress(void const* va, void const* vb)
{
struct peer_atom const* b = vb;
assert(tr_isAtom(b));
TR_ASSERT(tr_isAtom(b));
return comparePeerAtomToAddress(va, &b->addr);
}
@ -393,7 +393,7 @@ static bool peerIsInUse(tr_swarm const* cs, struct peer_atom const* atom)
{
tr_swarm* s = (tr_swarm*)cs;
assert(swarmIsLocked(s));
TR_ASSERT(swarmIsLocked(s));
return atom->peer != NULL || getExistingHandshake(&s->outgoingHandshakes, &atom->addr) ||
getExistingHandshake(&s->manager->incomingHandshakes, &atom->addr);
@ -416,7 +416,7 @@ static void replicationNew(tr_swarm* s)
tr_piece_index_t const piece_count = s->tor->info.pieceCount;
int const n = tr_ptrArraySize(&s->peers);
assert(!replicationExists(s));
TR_ASSERT(!replicationExists(s));
s->pieceReplicationSize = piece_count;
s->pieceReplication = tr_new0(uint16_t, piece_count);
@ -443,11 +443,11 @@ static void swarmFree(void* vs)
{
tr_swarm* s = vs;
assert(s != NULL);
assert(!s->isRunning);
assert(swarmIsLocked(s));
assert(tr_ptrArrayEmpty(&s->outgoingHandshakes));
assert(tr_ptrArrayEmpty(&s->peers));
TR_ASSERT(s != NULL);
TR_ASSERT(!s->isRunning);
TR_ASSERT(swarmIsLocked(s));
TR_ASSERT(tr_ptrArrayEmpty(&s->outgoingHandshakes));
TR_ASSERT(tr_ptrArrayEmpty(&s->peers));
tr_ptrArrayDestruct(&s->webseeds, (PtrArrayForeachFunc)tr_peerFree);
tr_ptrArrayDestruct(&s->pool, (PtrArrayForeachFunc)tr_free);
@ -584,8 +584,9 @@ static bool isAtomBlocklisted(tr_session* session, struct peer_atom* atom)
static void atomSetSeedProbability(struct peer_atom* atom, int seedProbability)
{
assert(atom != NULL);
assert(-1 <= seedProbability && seedProbability <= 100);
TR_ASSERT(atom != NULL);
TR_ASSERT(seedProbability >= -1);
TR_ASSERT(seedProbability <= 100);
atom->seedProbability = seedProbability;
@ -719,7 +720,7 @@ static void requestListAdd(tr_swarm* s, tr_block_index_t block, tr_peer* peer)
bool exact;
int const pos = tr_lowerBound(&key, s->requests, s->requestCount, sizeof(struct block_request), compareReqByBlock,
&exact);
assert(!exact);
TR_ASSERT(!exact);
memmove(s->requests + pos + 1, s->requests + pos, sizeof(struct block_request) * (s->requestCount++ - pos));
s->requests[pos] = key;
}
@ -727,7 +728,7 @@ static void requestListAdd(tr_swarm* s, tr_block_index_t block, tr_peer* peer)
if (peer != NULL)
{
++peer->pendingReqsToPeer;
assert(peer->pendingReqsToPeer >= 0);
TR_ASSERT(peer->pendingReqsToPeer >= 0);
}
// fprintf(stderr, "added request of block %lu from peer %s... there are now %d block\n", (unsigned long)block,
@ -757,7 +758,7 @@ static void getBlockRequestPeers(tr_swarm* s, tr_block_index_t block, tr_ptrArra
key.peer = NULL;
pos = tr_lowerBound(&key, s->requests, s->requestCount, sizeof(struct block_request), compareReqByBlock, &exact);
assert(!exact); /* shouldn't have a request with .peer == NULL */
TR_ASSERT(!exact); /* shouldn't have a request with .peer == NULL */
for (int i = pos; i < s->requestCount; ++i)
{
@ -788,7 +789,7 @@ static void requestListRemove(tr_swarm* s, tr_block_index_t block, tr_peer const
if (b != NULL)
{
int const pos = b - s->requests;
assert(pos < s->requestCount);
TR_ASSERT(pos < s->requestCount);
decrementPendingReqCount(b);
@ -828,7 +829,7 @@ static bool testForEndgame(tr_swarm const* s)
static void updateEndgame(tr_swarm* s)
{
assert(s->requestCount >= 0);
TR_ASSERT(s->requestCount >= 0);
if (!testForEndgame(s))
{
@ -978,7 +979,7 @@ static int comparePieceByIndex(void const* va, void const* vb)
static void pieceListSort(tr_swarm* s, enum piece_sort_state state)
{
assert(state == PIECES_SORTED_BY_INDEX || state == PIECES_SORTED_BY_WEIGHT);
TR_ASSERT(state == PIECES_SORTED_BY_INDEX || state == PIECES_SORTED_BY_WEIGHT);
if (state == PIECES_SORTED_BY_WEIGHT)
{
@ -1012,7 +1013,7 @@ static void assertWeightedPiecesAreSorted(Torrent* t)
for (int i = 0; i < t->pieceCount - 1; ++i)
{
assert(comparePieceByWeight(&t->pieces[i], &t->pieces[i + 1]) <= 0);
TR_ASSERT(comparePieceByWeight(&t->pieces[i], &t->pieces[i + 1]) <= 0);
}
}
}
@ -1029,7 +1030,7 @@ static void assertReplicationCountIsExact(Torrent* t)
tr_peer const** peers = (tr_peer const**)tr_ptrArrayBase(&t->peers);
int const peer_count = tr_ptrArraySize(&t->peers);
assert(piece_count == t->tor->info.pieceCount);
TR_ASSERT(piece_count == t->tor->info.pieceCount);
for (size_t piece_i = 0; piece_i < piece_count; ++piece_i)
{
@ -1043,7 +1044,7 @@ static void assertReplicationCountIsExact(Torrent* t)
}
}
assert(rep[piece_i] == r);
TR_ASSERT(rep[piece_i] == r);
}
}
@ -1228,8 +1229,8 @@ static void pieceListRemoveRequest(tr_swarm* s, tr_block_index_t block)
*/
static void tr_incrReplicationOfPiece(tr_swarm* s, size_t const index)
{
assert(replicationExists(s));
assert(s->pieceReplicationSize == s->tor->info.pieceCount);
TR_ASSERT(replicationExists(s));
TR_ASSERT(s->pieceReplicationSize == s->tor->info.pieceCount);
/* One more replication of this piece is present in the swarm */
++s->pieceReplication[index];
@ -1249,7 +1250,7 @@ static void tr_incrReplicationFromBitfield(tr_swarm* s, tr_bitfield const* b)
uint16_t* rep = s->pieceReplication;
size_t const n = s->tor->info.pieceCount;
assert(replicationExists(s));
TR_ASSERT(replicationExists(s));
for (size_t i = 0; i < n; ++i)
{
@ -1270,8 +1271,8 @@ static void tr_incrReplicationFromBitfield(tr_swarm* s, tr_bitfield const* b)
*/
static void tr_incrReplication(tr_swarm* s)
{
assert(replicationExists(s));
assert(s->pieceReplicationSize == s->tor->info.pieceCount);
TR_ASSERT(replicationExists(s));
TR_ASSERT(s->pieceReplicationSize == s->tor->info.pieceCount);
for (size_t i = 0; i < s->pieceReplicationSize; ++i)
{
@ -1284,8 +1285,8 @@ static void tr_incrReplication(tr_swarm* s)
*/
static void tr_decrReplicationFromBitfield(tr_swarm* s, tr_bitfield const* b)
{
assert(replicationExists(s));
assert(s->pieceReplicationSize == s->tor->info.pieceCount);
TR_ASSERT(replicationExists(s));
TR_ASSERT(s->pieceReplicationSize == s->tor->info.pieceCount);
if (tr_bitfieldHasAll(b))
{
@ -1317,7 +1318,7 @@ static void tr_decrReplicationFromBitfield(tr_swarm* s, tr_bitfield const* b)
void tr_peerMgrRebuildRequests(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
pieceListRebuild(tor->swarm);
}
@ -1329,8 +1330,8 @@ void tr_peerMgrGetNextRequests(tr_torrent* tor, tr_peer* peer, int numwant, tr_b
tr_bitfield const* const have = &peer->have;
/* sanity clause */
assert(tr_isTorrent(tor));
assert(numwant > 0);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(numwant > 0);
/* walk through the pieces and find blocks that should be requested */
s = tor->swarm;
@ -1529,8 +1530,8 @@ static void refillUpkeep(evutil_socket_t foo UNUSED, short bar UNUSED, void* vmg
if (msgs != NULL && request->sentAt <= too_old && !tr_peerMsgsIsReadingBlock(msgs, request->block))
{
assert(cancel != NULL);
assert(cancelCount < cancel_buflen);
TR_ASSERT(cancel != NULL);
TR_ASSERT(cancelCount < cancel_buflen);
cancel[cancelCount++] = *request;
}
@ -1595,9 +1596,9 @@ static void peerSuggestedPiece(tr_swarm* s UNUSED, tr_peer* peer UNUSED, tr_piec
{
#if 0
assert(t != NULL);
assert(peer != NULL);
assert(peer->msgs != NULL);
TR_ASSERT(t != NULL);
TR_ASSERT(peer != NULL);
TR_ASSERT(peer->msgs != NULL);
/* is this a valid piece? */
if (pieceIndex >= t->tor->info.pieceCount)
@ -1736,7 +1737,7 @@ static void peerCallbackFunc(tr_peer* peer, tr_peer_event const* e, void* vs)
swarmLock(s);
assert(peer != NULL);
TR_ASSERT(peer != NULL);
switch (e->eventType)
{
@ -1801,7 +1802,7 @@ static void peerCallbackFunc(tr_peer* peer, tr_peer_event const* e, void* vs)
break;
case TR_PEER_CLIENT_GOT_BITFIELD:
assert(e->bitfield != NULL);
TR_ASSERT(e->bitfield != NULL);
if (replicationExists(s))
{
@ -1875,7 +1876,7 @@ static void peerCallbackFunc(tr_peer* peer, tr_peer_event const* e, void* vs)
break;
default:
assert(0);
TR_ASSERT_MSG(false, "unhandled peer event type %d", (int)e->eventType);
}
swarmUnlock(s);
@ -1918,8 +1919,8 @@ static void ensureAtomExists(tr_swarm* s, tr_address const* addr, tr_port const
{
struct peer_atom* a;
assert(tr_address_is_valid(addr));
assert(from < TR_PEER_FROM__MAX);
TR_ASSERT(tr_address_is_valid(addr));
TR_ASSERT(from < TR_PEER_FROM__MAX);
a = getExistingAtom(s, addr);
@ -1971,9 +1972,9 @@ static void createBitTorrentPeer(tr_torrent* tor, struct tr_peerIo* io, struct p
tr_peerMsgs* msgs;
tr_swarm* swarm;
assert(atom != NULL);
assert(tr_isTorrent(tor));
assert(tor->swarm != NULL);
TR_ASSERT(atom != NULL);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tor->swarm != NULL);
swarm = tor->swarm;
@ -1986,8 +1987,8 @@ static void createBitTorrentPeer(tr_torrent* tor, struct tr_peerIo* io, struct p
++swarm->stats.peerCount;
++swarm->stats.peerFromCount[atom->fromFirst];
assert(swarm->stats.peerCount == tr_ptrArraySize(&swarm->peers));
assert(swarm->stats.peerFromCount[atom->fromFirst] <= swarm->stats.peerCount);
TR_ASSERT(swarm->stats.peerCount == tr_ptrArraySize(&swarm->peers));
TR_ASSERT(swarm->stats.peerFromCount[atom->fromFirst] <= swarm->stats.peerCount);
msgs = PEER_MSGS(peer);
tr_peerMsgsUpdateActive(msgs, TR_UP);
@ -2005,7 +2006,7 @@ static bool myHandshakeDoneCB(tr_handshake* handshake, tr_peerIo* io, bool readA
tr_peerMgr* manager = vmanager;
tr_swarm* s;
assert(io != NULL);
TR_ASSERT(io != NULL);
s = tr_peerIoHasTorrentHash(io) ? getExistingSwarm(manager, tr_peerIoGetTorrentHash(io)) : NULL;
@ -2050,7 +2051,7 @@ static bool myHandshakeDoneCB(tr_handshake* handshake, tr_peerIo* io, bool readA
ensureAtomExists(s, addr, port, 0, -1, TR_PEER_FROM_INCOMING);
atom = getExistingAtom(s, addr);
assert(atom != NULL);
TR_ASSERT(atom != NULL);
atom->time = tr_time();
atom->piece_data_time = 0;
@ -2123,7 +2124,7 @@ void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_address* addr, tr_port port,
managerLock(manager);
assert(tr_isSession(manager->session));
TR_ASSERT(tr_isSession(manager->session));
session = manager->session;
if (tr_sessionIsAddressBlocked(session, addr))
@ -2297,8 +2298,8 @@ int tr_pexCompare(void const* va, void const* vb)
tr_pex const* a = va;
tr_pex const* b = vb;
assert(tr_isPex(a));
assert(tr_isPex(b));
TR_ASSERT(tr_isPex(a));
TR_ASSERT(tr_isPex(b));
if ((i = tr_address_compare(&a->addr, &b->addr)) != 0)
{
@ -2319,8 +2320,8 @@ static int compareAtomsByUsefulness(void const* va, void const* vb)
struct peer_atom const* a = *(struct peer_atom const* const*)va;
struct peer_atom const* b = *(struct peer_atom const* const*)vb;
assert(tr_isAtom(a));
assert(tr_isAtom(b));
TR_ASSERT(tr_isAtom(a));
TR_ASSERT(tr_isAtom(b));
if (a->piece_data_time != b->piece_data_time)
{
@ -2375,10 +2376,10 @@ int tr_peerMgrGetPeers(tr_torrent* tor, tr_pex** setme_pex, uint8_t af, uint8_t
tr_pex* pex;
tr_pex* walk;
assert(tr_isTorrent(tor));
assert(setme_pex != NULL);
assert(af == TR_AF_INET || af == TR_AF_INET6);
assert(list_mode == TR_PEERS_CONNECTED || list_mode == TR_PEERS_INTERESTING);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(setme_pex != NULL);
TR_ASSERT(af == TR_AF_INET || af == TR_AF_INET6);
TR_ASSERT(list_mode == TR_PEERS_CONNECTED || list_mode == TR_PEERS_INTERESTING);
managerLock(s->manager);
@ -2427,7 +2428,7 @@ int tr_peerMgrGetPeers(tr_torrent* tor, tr_pex** setme_pex, uint8_t af, uint8_t
if (atom->addr.type == af)
{
assert(tr_address_is_valid(&atom->addr));
TR_ASSERT(tr_address_is_valid(&atom->addr));
walk->addr = atom->addr;
walk->port = atom->port;
walk->flags = atom->flags;
@ -2438,7 +2439,7 @@ int tr_peerMgrGetPeers(tr_torrent* tor, tr_pex** setme_pex, uint8_t af, uint8_t
qsort(pex, count, sizeof(tr_pex), tr_pexCompare);
assert(walk - pex == count);
TR_ASSERT(walk - pex == count);
*setme_pex = pex;
/* cleanup */
@ -2486,8 +2487,8 @@ void tr_peerMgrStartTorrent(tr_torrent* tor)
{
tr_swarm* s;
assert(tr_isTorrent(tor));
assert(tr_torrentIsLocked(tor));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_torrentIsLocked(tor));
s = tor->swarm;
ensureMgrTimersExist(s->manager);
@ -2520,25 +2521,25 @@ static void stopSwarm(tr_swarm* swarm)
void tr_peerMgrStopTorrent(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
assert(tr_torrentIsLocked(tor));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_torrentIsLocked(tor));
stopSwarm(tor->swarm);
}
void tr_peerMgrAddTorrent(tr_peerMgr* manager, tr_torrent* tor)
{
assert(tr_isTorrent(tor));
assert(tr_torrentIsLocked(tor));
assert(tor->swarm == NULL);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_torrentIsLocked(tor));
TR_ASSERT(tor->swarm == NULL);
tor->swarm = swarmNew(manager, tor);
}
void tr_peerMgrRemoveTorrent(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
assert(tr_torrentIsLocked(tor));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_torrentIsLocked(tor));
stopSwarm(tor->swarm);
swarmFree(tor->swarm);
@ -2615,9 +2616,9 @@ void tr_peerMgrOnTorrentGotMetainfo(tr_torrent* tor)
void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned int tabCount)
{
assert(tr_isTorrent(tor));
assert(tab != NULL);
assert(tabCount > 0);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tab != NULL);
TR_ASSERT(tabCount > 0);
memset(tab, 0, tabCount);
@ -2652,8 +2653,8 @@ void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned
void tr_swarmGetStats(tr_swarm const* swarm, tr_swarm_stats* setme)
{
assert(swarm != NULL);
assert(setme != NULL);
TR_ASSERT(swarm != NULL);
TR_ASSERT(setme != NULL);
*setme = swarm->stats;
}
@ -2671,8 +2672,8 @@ void tr_swarmIncrementActivePeers(tr_swarm* swarm, tr_direction direction, bool
--n;
}
assert(0 <= n);
assert(n <= swarm->stats.peerCount);
TR_ASSERT(n >= 0);
TR_ASSERT(n <= swarm->stats.peerCount);
swarm->stats.activePeerCount[direction] = n;
}
@ -2698,7 +2699,7 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor)
uint64_t desiredAvailable;
tr_swarm const* s;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
/* common shortcuts... */
@ -2750,7 +2751,7 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor)
}
}
assert(desiredAvailable <= tor->info.totalSize);
TR_ASSERT(desiredAvailable <= tor->info.totalSize);
return desiredAvailable;
}
@ -2761,14 +2762,14 @@ double* tr_peerMgrWebSpeeds_KBps(tr_torrent const* tor)
double* ret = NULL;
uint64_t const now = tr_time_msec();
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
s = tor->swarm;
n = tr_ptrArraySize(&s->webseeds);
ret = tr_new0(double, n);
assert(s->manager != NULL);
assert(n == tor->info.webseedCount);
TR_ASSERT(s->manager != NULL);
TR_ASSERT(n == tor->info.webseedCount);
for (unsigned int i = 0; i < n; ++i)
{
@ -2796,8 +2797,8 @@ struct tr_peer_stat* tr_peerMgrPeerStats(tr_torrent const* tor, int* setmeCount)
time_t const now = tr_time();
uint64_t const now_msec = tr_time_msec();
assert(tr_isTorrent(tor));
assert(tor->swarm->manager != NULL);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tor->swarm->manager != NULL);
s = tor->swarm;
peers = (tr_peer**)tr_ptrArrayBase(&s->peers);
@ -2914,8 +2915,8 @@ void tr_peerMgrClearInterest(tr_torrent* tor)
tr_swarm* s = tor->swarm;
int const peerCount = tr_ptrArraySize(&s->peers);
assert(tr_isTorrent(tor));
assert(tr_torrentIsLocked(tor));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_torrentIsLocked(tor));
for (int i = 0; i < peerCount; ++i)
{
@ -2927,8 +2928,8 @@ void tr_peerMgrClearInterest(tr_torrent* tor)
static bool isPeerInteresting(tr_torrent* const tor, bool const* const piece_is_interesting, tr_peer const* const peer)
{
/* these cases should have already been handled by the calling code... */
assert(!tr_torrentIsSeed(tor));
assert(tr_torrentIsPieceTransferAllowed(tor, TR_PEER_TO_CLIENT));
TR_ASSERT(!tr_torrentIsSeed(tor));
TR_ASSERT(tr_torrentIsPieceTransferAllowed(tor, TR_PEER_TO_CLIENT));
if (tr_peerIsSeed(peer))
{
@ -3239,7 +3240,7 @@ static void rechokeUploads(tr_swarm* s, uint64_t const now)
bool const chokeAll = !tr_torrentIsPieceTransferAllowed(s->tor, TR_CLIENT_TO_PEER);
bool const isMaxedOut = isBandwidthMaxedOut(&s->tor->bandwidth, now, TR_UP);
assert(swarmIsLocked(s));
TR_ASSERT(swarmIsLocked(s));
/* an optimistic unchoke peer's "optimistic"
* state lasts for N calls to rechokeUploads(). */
@ -3441,7 +3442,7 @@ static tr_peer** getPeersToClose(tr_swarm* s, time_t const now_sec, int* setmeSi
struct tr_peer** ret = NULL;
tr_peer** peers = (tr_peer**)tr_ptrArrayPeek(&s->peers, &peerCount);
assert(swarmIsLocked(s));
TR_ASSERT(swarmIsLocked(s));
for (int i = 0; i < peerCount; ++i)
{
@ -3524,8 +3525,8 @@ static void removePeer(tr_swarm* s, tr_peer* peer)
{
struct peer_atom* atom = peer->atom;
assert(swarmIsLocked(s));
assert(atom != NULL);
TR_ASSERT(swarmIsLocked(s));
TR_ASSERT(atom != NULL);
atom->time = tr_time();
@ -3538,8 +3539,8 @@ static void removePeer(tr_swarm* s, tr_peer* peer)
tr_decrReplicationFromBitfield(s, &peer->have);
}
assert(s->stats.peerCount == tr_ptrArraySize(&s->peers));
assert(s->stats.peerFromCount[atom->fromFirst] >= 0);
TR_ASSERT(s->stats.peerCount == tr_ptrArraySize(&s->peers));
TR_ASSERT(s->stats.peerFromCount[atom->fromFirst] >= 0);
tr_peerFree(peer);
}
@ -3548,8 +3549,8 @@ static void closePeer(tr_swarm* s, tr_peer* peer)
{
struct peer_atom* atom;
assert(s != NULL);
assert(peer != NULL);
TR_ASSERT(s != NULL);
TR_ASSERT(peer != NULL);
atom = peer->atom;
@ -3578,7 +3579,7 @@ static void removeAllPeers(tr_swarm* s)
removePeer(s, tr_ptrArrayNth(&s->peers, 0));
}
assert(!s->stats.peerCount);
TR_ASSERT(s->stats.peerCount == 0);
}
static void closeBadPeers(tr_swarm* s, time_t const now_sec)
@ -3665,7 +3666,7 @@ static void sortPeersByLivelinessImpl(tr_peer** peers, void** clientData, int n,
}
/* sort 'em */
assert(n == l - lives);
TR_ASSERT(n == l - lives);
qsort(lives, n, sizeof(struct peer_liveliness), compare);
l = lives;
@ -3681,7 +3682,7 @@ static void sortPeersByLivelinessImpl(tr_peer** peers, void** clientData, int n,
}
}
assert(n == l - lives);
TR_ASSERT(n == l - lives);
/* cleanup */
tr_free(lives);
@ -3841,8 +3842,8 @@ static void queuePulseForeach(void* vtor)
static void queuePulse(tr_session* session, tr_direction dir)
{
assert(tr_isSession(session));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isSession(session));
TR_ASSERT(tr_isDirection(dir));
if (tr_sessionGetQueueEnabled(session, dir))
{
@ -3915,8 +3916,8 @@ static int compareAtomPtrsByAddress(void const* va, void const* vb)
struct peer_atom const* a = *(struct peer_atom const* const*)va;
struct peer_atom const* b = *(struct peer_atom const* const*)vb;
assert(tr_isAtom(a));
assert(tr_isAtom(b));
TR_ASSERT(tr_isAtom(a));
TR_ASSERT(tr_isAtom(b));
return tr_address_compare(&a->addr, &b->addr);
}
@ -3931,8 +3932,8 @@ static int compareAtomPtrsByShelfDate(void const* va, void const* vb)
int const data_time_cutoff_secs = 60 * 60;
time_t const tr_now = tr_time();
assert(tr_isAtom(a));
assert(tr_isAtom(b));
TR_ASSERT(tr_isAtom(a));
TR_ASSERT(tr_isAtom(b));
/* primary key: the last piece data time *if* it was within the last hour */
atime = a->piece_data_time;
@ -4206,7 +4207,7 @@ static void selectPeerCandidates(struct peer_candidate* candidates, int candidat
tr_quickfindFirstK(candidates, candidate_count, sizeof(struct peer_candidate), comparePeerCandidates, select_count);
}
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
static bool checkBestScoresComeFirst(struct peer_candidate const* candidates, int n, int k)
{
@ -4223,18 +4224,18 @@ static bool checkBestScoresComeFirst(struct peer_candidate const* candidates, in
for (int i = 0; i < x; i++)
{
assert(candidates[i].score <= worstFirstScore);
TR_ASSERT(candidates[i].score <= worstFirstScore);
}
for (int i = x + 1; i < n; i++)
{
assert(candidates[i].score >= worstFirstScore);
TR_ASSERT(candidates[i].score >= worstFirstScore);
}
return true;
}
#endif /* NDEBUG */
#endif /* TR_ENABLE_ASSERTS */
/** @return an array of all the atoms we might want to connect to */
static struct peer_candidate* getPeerCandidates(tr_session* session, int* candidateCount, int max)
@ -4319,7 +4320,7 @@ static struct peer_candidate* getPeerCandidates(tr_session* session, int* candid
selectPeerCandidates(candidates, walk - candidates, max);
}
assert(checkBestScoresComeFirst(candidates, *candidateCount, max));
TR_ASSERT(checkBestScoresComeFirst(candidates, *candidateCount, max));
return candidates;
}
@ -4352,7 +4353,7 @@ static void initiateConnection(tr_peerMgr* mgr, tr_swarm* s, struct peer_atom* a
{
tr_handshake* handshake = tr_handshakeNew(io, mgr->session->encryptionMode, myHandshakeDoneCB, mgr);
assert(tr_peerIoGetTorrentHash(io));
TR_ASSERT(tr_peerIoGetTorrentHash(io));
tr_peerIoUnref(io); /* balanced by the initial ref in tr_peerIoNewOutgoing() */

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
@ -27,6 +26,7 @@
#include "session.h"
#include "torrent.h"
#include "torrent-magnet.h"
#include "tr-assert.h"
#include "tr-dht.h"
#include "utils.h"
#include "variant.h"
@ -318,7 +318,7 @@ static void protocolSendReject(tr_peerMsgs* msgs, struct peer_request const* req
{
struct evbuffer* out = msgs->outMessages;
assert(tr_peerIoSupportsFEXT(msgs->io));
TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(out, sizeof(uint8_t) + 3 * sizeof(uint32_t));
evbuffer_add_uint8(out, BT_FEXT_REJECT);
@ -390,7 +390,7 @@ static void protocolSendAllowedFast(tr_peerMsgs* msgs, uint32_t pieceIndex)
tr_peerIo* io = msgs->io;
struct evbuffer* out = msgs->outMessages;
assert(tr_peerIoSupportsFEXT(msgs->io));
TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(io, out, sizeof(uint8_t) + sizeof(uint32_t));
evbuffer_add_uint8(io, out, BT_FEXT_ALLOWED_FAST);
@ -418,7 +418,7 @@ static void protocolSendHaveAll(tr_peerMsgs* msgs)
{
struct evbuffer* out = msgs->outMessages;
assert(tr_peerIoSupportsFEXT(msgs->io));
TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(out, sizeof(uint8_t));
evbuffer_add_uint8(out, BT_FEXT_HAVE_ALL);
@ -432,7 +432,7 @@ static void protocolSendHaveNone(tr_peerMsgs* msgs)
{
struct evbuffer* out = msgs->outMessages;
assert(tr_peerIoSupportsFEXT(msgs->io));
TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(out, sizeof(uint8_t));
evbuffer_add_uint8(out, BT_FEXT_HAVE_NONE);
@ -571,12 +571,12 @@ size_t tr_generateAllowedSet(tr_piece_index_t* setmePieces, size_t desiredSetSiz
{
size_t setSize = 0;
assert(setmePieces != NULL);
assert(desiredSetSize <= pieceCount);
assert(desiredSetSize != 0);
assert(pieceCount != 0);
assert(infohash != NULL);
assert(addr != NULL);
TR_ASSERT(setmePieces != NULL);
TR_ASSERT(desiredSetSize <= pieceCount);
TR_ASSERT(desiredSetSize != 0);
TR_ASSERT(pieceCount != 0);
TR_ASSERT(infohash != NULL);
TR_ASSERT(addr != NULL);
if (addr->type == TR_AF_INET)
{
@ -590,7 +590,7 @@ size_t tr_generateAllowedSet(tr_piece_index_t* setmePieces, size_t desiredSetSiz
memcpy(walk, infohash, SHA_DIGEST_LENGTH); /* (2) */
walk += SHA_DIGEST_LENGTH;
tr_sha1(x, w, walk - w, NULL); /* (3) */
assert(sizeof(w) == walk - w);
TR_ASSERT(sizeof(w) == walk - w);
while (setSize < desiredSetSize)
{
@ -652,8 +652,8 @@ static bool tr_peerMsgsCalculateActive(tr_peerMsgs const* msgs, tr_direction dir
{
bool is_active;
assert(tr_isPeerMsgs(msgs));
assert(tr_isDirection(direction));
TR_ASSERT(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isDirection(direction));
if (direction == TR_CLIENT_TO_PEER)
{
@ -662,7 +662,7 @@ static bool tr_peerMsgsCalculateActive(tr_peerMsgs const* msgs, tr_direction dir
/* FIXME: https://trac.transmissionbt.com/ticket/5505
if (is_active)
{
assert(!tr_peerIsSeed(&msgs->peer));
TR_ASSERT(!tr_peerIsSeed(&msgs->peer));
}
*/
}
@ -678,7 +678,7 @@ static bool tr_peerMsgsCalculateActive(tr_peerMsgs const* msgs, tr_direction dir
if (is_active)
{
assert(!tr_torrentIsSeed(msgs->torrent));
TR_ASSERT(!tr_torrentIsSeed(msgs->torrent));
}
}
}
@ -690,12 +690,12 @@ bool tr_peerMsgsIsActive(tr_peerMsgs const* msgs, tr_direction direction)
{
bool is_active;
assert(tr_isPeerMsgs(msgs));
assert(tr_isDirection(direction));
TR_ASSERT(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isDirection(direction));
is_active = msgs->is_active[direction];
assert(is_active == tr_peerMsgsCalculateActive(msgs, direction));
TR_ASSERT(is_active == tr_peerMsgsCalculateActive(msgs, direction));
return is_active;
}
@ -727,7 +727,7 @@ static void sendInterest(tr_peerMsgs* msgs, bool b)
{
struct evbuffer* out = msgs->outMessages;
assert(msgs != NULL);
TR_ASSERT(msgs != NULL);
msgs->client_is_interested = b;
dbgmsg(msgs, "Sending %s", b ? "Interested" : "Not Interested");
@ -800,7 +800,7 @@ void tr_peerMsgsSetChoke(tr_peerMsgs* msgs, bool peer_is_choked)
time_t const now = tr_time();
time_t const fibrillationTime = now - MIN_CHOKE_PERIOD_SEC;
assert(msgs != NULL);
TR_ASSERT(msgs != NULL);
if (msgs->chokeChangedAt > fibrillationTime)
{
@ -1226,7 +1226,7 @@ static void parseLtep(tr_peerMsgs* msgs, uint32_t msglen, struct evbuffer* inbuf
{
uint8_t ltep_msgid;
assert(msglen > 0);
TR_ASSERT(msglen > 0);
tr_peerIoReadUint8(msgs->io, inbuf, &ltep_msgid);
msglen--;
@ -1441,7 +1441,7 @@ static int readBtPiece(tr_peerMsgs* msgs, struct evbuffer* inbuf, size_t inlen,
{
struct peer_request* req = &msgs->incoming.blockReq;
assert(evbuffer_get_length(inbuf) >= inlen);
TR_ASSERT(evbuffer_get_length(inbuf) >= inlen);
dbgmsg(msgs, "In readBtPiece");
if (req->length == 0)
@ -1505,12 +1505,12 @@ static int readBtMessage(tr_peerMsgs* msgs, struct evbuffer* inbuf, size_t inlen
uint32_t ui32;
uint32_t msglen = msgs->incoming.length;
uint8_t const id = msgs->incoming.id;
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
size_t const startBufLen = evbuffer_get_length(inbuf);
#endif
bool const fext = tr_peerIoSupportsFEXT(msgs->io);
assert(msglen > 0);
TR_ASSERT(msglen > 0);
--msglen; /* id length */
@ -1629,7 +1629,7 @@ static int readBtMessage(tr_peerMsgs* msgs, struct evbuffer* inbuf, size_t inlen
}
case BT_PIECE:
assert(0); /* handled elsewhere! */
TR_ASSERT(false); /* handled elsewhere! */
break;
case BT_PORT:
@ -1681,7 +1681,7 @@ static int readBtMessage(tr_peerMsgs* msgs, struct evbuffer* inbuf, size_t inlen
if (fext)
{
tr_bitfieldSetHasAll(&msgs->peer.have);
assert(tr_bitfieldHasAll(&msgs->peer.have));
TR_ASSERT(tr_bitfieldHasAll(&msgs->peer.have));
fireClientGotHaveAll(msgs);
updatePeerProgress(msgs);
}
@ -1742,8 +1742,8 @@ static int readBtMessage(tr_peerMsgs* msgs, struct evbuffer* inbuf, size_t inlen
break;
}
assert(msglen + 1 == msgs->incoming.length);
assert(evbuffer_get_length(inbuf) == startBufLen - msglen);
TR_ASSERT(msglen + 1 == msgs->incoming.length);
TR_ASSERT(evbuffer_get_length(inbuf) == startBufLen - msglen);
msgs->state = AWAITING_BT_LENGTH;
return READ_NOW;
@ -1756,8 +1756,8 @@ static int clientGotBlock(tr_peerMsgs* msgs, struct evbuffer* data, struct peer_
tr_torrent* tor = msgs->torrent;
tr_block_index_t const block = _tr_block(tor, req->index, req->offset);
assert(msgs);
assert(req);
TR_ASSERT(msgs != NULL);
TR_ASSERT(req != NULL);
if (!requestIsValid(msgs, req))
{
@ -1851,7 +1851,7 @@ static ReadState canRead(tr_peerIo* io, void* vmsgs, size_t* piece)
default:
ret = READ_ERR;
assert(0);
TR_ASSERT_MSG(false, "unhandled peer messages state %d", (int)msgs->state);
}
}
@ -1965,8 +1965,8 @@ static void updateBlockRequests(tr_peerMsgs* msgs)
tr_block_index_t* blocks;
int const numwant = msgs->desiredRequestCount - msgs->peer.pendingReqsToPeer;
assert(tr_peerMsgsIsClientInterested(msgs));
assert(!tr_peerMsgsIsClientChoked(msgs));
TR_ASSERT(tr_peerMsgsIsClientInterested(msgs));
TR_ASSERT(!tr_peerMsgsIsClientChoked(msgs));
blocks = tr_new(tr_block_index_t, numwant);
tr_peerMgrGetNextRequests(msgs->torrent, &msgs->peer, numwant, blocks, &n, false);
@ -2127,7 +2127,7 @@ static size_t fillOutputBuffer(tr_peerMsgs* msgs, time_t now)
{
size_t const n = evbuffer_get_length(out);
dbgmsg(msgs, "sending block %u:%u->%u", req.index, req.offset, req.length);
assert(n == msglen);
TR_ASSERT(n == msglen);
tr_peerIoWriteBuf(msgs->io, out, true);
bytesWritten += n;
msgs->clientSentAnythingAt = now;
@ -2219,7 +2219,7 @@ static void sendBitfield(tr_peerMsgs* msgs)
size_t byte_count = 0;
struct evbuffer* out = msgs->outMessages;
assert(tr_torrentHasMetadata(msgs->torrent));
TR_ASSERT(tr_torrentHasMetadata(msgs->torrent));
bytes = tr_torrentCreatePieceBitfield(msgs->torrent, &byte_count);
evbuffer_add_uint32(out, sizeof(uint8_t) + byte_count);
@ -2428,7 +2428,7 @@ static void sendPex(tr_peerMsgs* msgs)
walk += 2;
}
assert(walk - tmp == diffs.addedCount * 6);
TR_ASSERT(walk - tmp == diffs.addedCount * 6);
tr_variantDictAddRaw(&val, TR_KEY_added, tmp, walk - tmp);
tr_free(tmp);
@ -2441,7 +2441,7 @@ static void sendPex(tr_peerMsgs* msgs)
*walk++ = diffs.added[i].flags & ~ADDED_F_HOLEPUNCH;
}
assert(walk - tmp == diffs.addedCount);
TR_ASSERT(walk - tmp == diffs.addedCount);
tr_variantDictAddRaw(&val, TR_KEY_added_f, tmp, walk - tmp);
tr_free(tmp);
}
@ -2459,7 +2459,7 @@ static void sendPex(tr_peerMsgs* msgs)
walk += 2;
}
assert(walk - tmp == diffs.droppedCount * 6);
TR_ASSERT(walk - tmp == diffs.droppedCount * 6);
tr_variantDictAddRaw(&val, TR_KEY_dropped, tmp, walk - tmp);
tr_free(tmp);
}
@ -2477,7 +2477,7 @@ static void sendPex(tr_peerMsgs* msgs)
walk += 2;
}
assert(walk - tmp == diffs6.addedCount * 18);
TR_ASSERT(walk - tmp == diffs6.addedCount * 18);
tr_variantDictAddRaw(&val, TR_KEY_added6, tmp, walk - tmp);
tr_free(tmp);
@ -2490,7 +2490,7 @@ static void sendPex(tr_peerMsgs* msgs)
*walk++ = diffs6.added[i].flags & ~ADDED_F_HOLEPUNCH;
}
assert(walk - tmp == diffs6.addedCount);
TR_ASSERT(walk - tmp == diffs6.addedCount);
tr_variantDictAddRaw(&val, TR_KEY_added6_f, tmp, walk - tmp);
tr_free(tmp);
}
@ -2508,7 +2508,7 @@ static void sendPex(tr_peerMsgs* msgs)
walk += 2;
}
assert(walk - tmp == diffs6.droppedCount * 18);
TR_ASSERT(walk - tmp == diffs6.droppedCount * 18);
tr_variantDictAddRaw(&val, TR_KEY_dropped6, tmp, walk - tmp);
tr_free(tmp);
}
@ -2545,7 +2545,7 @@ static void pexPulse(evutil_socket_t foo UNUSED, short bar UNUSED, void* vmsgs)
sendPex(msgs);
assert(msgs->pexTimer != NULL);
TR_ASSERT(msgs->pexTimer != NULL);
tr_timerAdd(msgs->pexTimer, PEX_INTERVAL_SECS, 0);
}
@ -2576,7 +2576,7 @@ static void peermsgs_destruct(tr_peer* peer)
{
tr_peerMsgs* msgs = PEER_MSGS(peer);
assert(msgs != NULL);
TR_ASSERT(msgs != NULL);
tr_peerMsgsSetActive(msgs, TR_UP, false);
tr_peerMsgsSetActive(msgs, TR_DOWN, false);
@ -2618,56 +2618,56 @@ static struct tr_peer_virtual_funcs const my_funcs =
time_t tr_peerMsgsGetConnectionAge(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return tr_peerIoGetAge(msgs->io);
}
bool tr_peerMsgsIsPeerChoked(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->peer_is_choked;
}
bool tr_peerMsgsIsPeerInterested(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->peer_is_interested;
}
bool tr_peerMsgsIsClientChoked(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->client_is_choked;
}
bool tr_peerMsgsIsClientInterested(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->client_is_interested;
}
bool tr_peerMsgsIsUtpConnection(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->io->utp_socket != NULL;
}
bool tr_peerMsgsIsEncrypted(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return tr_peerIoIsEncrypted(msgs->io);
}
bool tr_peerMsgsIsIncomingConnection(tr_peerMsgs const* msgs)
{
assert(tr_isPeerMsgs(msgs));
TR_ASSERT(tr_isPeerMsgs(msgs));
return tr_peerIoIsIncoming(msgs->io);
}
@ -2691,7 +2691,7 @@ tr_peerMsgs* tr_peerMsgsNew(struct tr_torrent* torrent, struct tr_peerIo* io, tr
{
tr_peerMsgs* m;
assert(io != NULL);
TR_ASSERT(io != NULL);
m = tr_new0(tr_peerMsgs, 1);

View File

@ -11,7 +11,6 @@
#define __USE_UNIX98 /* some older Linuxes need it spelt out for them */
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@ -40,6 +39,7 @@
#include "log.h"
#include "platform.h"
#include "session.h"
#include "tr-assert.h"
#include "utils.h"
/***
@ -191,8 +191,8 @@ void tr_lockLock(tr_lock* l)
pthread_mutex_lock(&l->lock);
#endif
assert(l->depth >= 0);
assert(l->depth == 0 || tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
TR_ASSERT(l->depth >= 0);
TR_ASSERT(l->depth == 0 || tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
l->lockThread = tr_getCurrentThread();
++l->depth;
}
@ -204,11 +204,11 @@ bool tr_lockHave(tr_lock const* l)
void tr_lockUnlock(tr_lock* l)
{
assert(l->depth > 0);
assert(tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
TR_ASSERT(l->depth > 0);
TR_ASSERT(tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
--l->depth;
assert(l->depth >= 0);
TR_ASSERT(l->depth >= 0);
#ifdef _WIN32
LeaveCriticalSection(&l->lock);
@ -502,7 +502,7 @@ char const* tr_getWebClientDir(tr_session const* session UNUSED)
char* appString = tr_malloc(appStringLength);
bool const success = CFStringGetFileSystemRepresentation(appRef, appString, appStringLength);
assert(success);
TR_ASSERT(success);
CFRelease(appURL);
CFRelease(appRef);

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
@ -21,6 +20,7 @@
#include "port-forwarding.h"
#include "session.h"
#include "torrent.h"
#include "tr-assert.h"
#include "upnp.h"
#include "utils.h"
@ -144,8 +144,8 @@ static void onTimer(evutil_socket_t fd UNUSED, short what UNUSED, void* vshared)
{
tr_shared* s = vshared;
assert(s != NULL);
assert(s->timer != NULL);
TR_ASSERT(s != NULL);
TR_ASSERT(s->timer != NULL);
/* do something */
natPulse(s, s->doPortCheck);

View File

@ -6,10 +6,10 @@
*
*/
#include <assert.h>
#include <string.h> /* memmove */
#include "ptrarray.h"
#include "tr-assert.h"
#include "utils.h"
#define FLOOR 32
@ -18,8 +18,8 @@ tr_ptrArray const TR_PTR_ARRAY_INIT = TR_PTR_ARRAY_INIT_STATIC;
void tr_ptrArrayDestruct(tr_ptrArray* p, PtrArrayForeachFunc func)
{
assert(p != NULL);
assert(p->items != NULL || p->n_items == 0);
TR_ASSERT(p != NULL);
TR_ASSERT(p->items != NULL || p->n_items == 0);
if (func != NULL)
{
@ -31,9 +31,9 @@ void tr_ptrArrayDestruct(tr_ptrArray* p, PtrArrayForeachFunc func)
void tr_ptrArrayForeach(tr_ptrArray* t, PtrArrayForeachFunc func)
{
assert(t != NULL);
assert(t->items != NULL || t->n_items == 0);
assert(func != NULL);
TR_ASSERT(t != NULL);
TR_ASSERT(t->items != NULL || t->n_items == 0);
TR_ASSERT(func != NULL);
for (int i = 0; i < t->n_items; ++i)
{
@ -88,9 +88,9 @@ void tr_ptrArrayErase(tr_ptrArray* t, int begin, int end)
end = t->n_items;
}
assert(begin >= 0);
assert(begin < end);
assert(end <= t->n_items);
TR_ASSERT(begin >= 0);
TR_ASSERT(begin < end);
TR_ASSERT(end <= t->n_items);
memmove(t->items + begin, t->items + end, sizeof(void*) * (t->n_items - end));
@ -161,7 +161,7 @@ int tr_ptrArrayLowerBound(tr_ptrArray const* t, void const* ptr, int (* compare)
return pos;
}
#ifdef NDEBUG
#ifndef TR_ENABLE_ASSERTS
#define assertArrayIsSortedAndUnique(array, compare) /* no-op */
#define assertIndexIsSortedAndUnique(array, pos, compare) /* no-op */
@ -172,7 +172,7 @@ static void assertArrayIsSortedAndUnique(tr_ptrArray const* t, int (* compare)(v
{
for (int i = 0; i < t->n_items - 2; ++i)
{
assert(compare(t->items[i], t->items[i + 1]) < 0);
TR_ASSERT(compare(t->items[i], t->items[i + 1]) < 0);
}
}
@ -180,12 +180,12 @@ static void assertIndexIsSortedAndUnique(tr_ptrArray const* t, int pos, int (* c
{
if (pos > 0)
{
assert(compare(t->items[pos - 1], t->items[pos]) < 0);
TR_ASSERT(compare(t->items[pos - 1], t->items[pos]) < 0);
}
if (pos + 1 < t->n_items)
{
assert(compare(t->items[pos], t->items[pos + 1]) < 0);
TR_ASSERT(compare(t->items[pos], t->items[pos + 1]) < 0);
}
}
@ -224,26 +224,26 @@ static void* tr_ptrArrayRemoveSortedValue(tr_ptrArray* t, void const* ptr, int (
if (match)
{
ret = t->items[pos];
assert(compare(ret, ptr) == 0);
TR_ASSERT(compare(ret, ptr) == 0);
tr_ptrArrayErase(t, pos, pos + 1);
}
assert((ret == NULL) || (compare(ret, ptr) == 0));
TR_ASSERT((ret == NULL) || (compare(ret, ptr) == 0));
return ret;
}
void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, int (* compare)(void const*, void const*))
{
#ifdef NDEBUG
#ifndef TR_ENABLE_ASSERTS
tr_ptrArrayRemoveSortedValue(t, ptr, compare);
#else
void* removed = tr_ptrArrayRemoveSortedValue(t, ptr, compare);
assert(removed != NULL);
assert(removed == ptr);
assert(tr_ptrArrayFindSorted(t, ptr, compare) == NULL);
TR_ASSERT(removed != NULL);
TR_ASSERT(removed == ptr);
TR_ASSERT(tr_ptrArrayFindSorted(t, ptr, compare) == NULL);
#endif
}

View File

@ -12,9 +12,8 @@
#pragma once
#include <assert.h>
#include "transmission.h"
#include "tr-assert.h"
/**
* @addtogroup utils Utilities
@ -50,9 +49,9 @@ void tr_ptrArrayForeach(tr_ptrArray* array, PtrArrayForeachFunc func);
@return the nth item in a tr_ptrArray */
static inline void* tr_ptrArrayNth(tr_ptrArray* array, int i)
{
assert(array != NULL);
assert(i >= 0);
assert(i < array->n_items);
TR_ASSERT(array != NULL);
TR_ASSERT(i >= 0);
TR_ASSERT(i < array->n_items);
return array->items[i];
}

View File

@ -6,13 +6,13 @@
*
*/
#include <assert.h>
#include <stdlib.h> /* bsearch() */
#include <string.h> /* memcmp() */
#include "transmission.h"
#include "ptrarray.h"
#include "quark.h"
#include "tr-assert.h"
#include "utils.h" /* tr_memdup(), tr_strndup() */
struct tr_key_struct
@ -427,7 +427,7 @@ bool tr_quark_lookup(void const* str, size_t len, tr_quark* setme)
static size_t const n_static = TR_N_ELEMENTS(my_static);
bool success = false;
assert(n_static == TR_N_KEYS);
TR_ASSERT(n_static == TR_N_KEYS);
tmp.str = str;
tmp.len = len;

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdio.h> /* fopen() */
#include <string.h> /* strcmp() */
@ -16,6 +15,7 @@
#include "file.h"
#include "resume.h"
#include "torrent.h" /* tr_isTorrent() */
#include "tr-assert.h"
#include "variant.h"
#include "libtransmission-test.h"
@ -52,7 +52,7 @@ static bool testFileExistsAndConsistsOfThisString(tr_torrent const* tor, tr_file
uint8_t* contents;
size_t contents_len;
assert(tr_sys_path_exists(path, NULL));
TR_ASSERT(tr_sys_path_exists(path, NULL));
contents = tr_loadFile(path, &contents_len, NULL);
@ -115,15 +115,15 @@ static tr_torrent* create_torrent_from_base64_metainfo(tr_ctor* ctor, char const
/* create the torrent ctor */
metainfo = tr_base64_decode_str(metainfo_base64, &metainfo_len);
assert(metainfo != NULL);
assert(metainfo_len > 0);
TR_ASSERT(metainfo != NULL);
TR_ASSERT(metainfo_len > 0);
tr_ctorSetMetainfo(ctor, (uint8_t*)metainfo, metainfo_len);
tr_ctorSetPaused(ctor, TR_FORCE, true);
/* create the torrent */
err = 0;
tor = tr_torrentNew(ctor, &err, NULL);
assert(err == 0);
TR_ASSERT(err == 0);
/* cleanup */
tr_free(metainfo);

View File

@ -19,6 +19,7 @@
#include "resume.h"
#include "session.h"
#include "torrent.h"
#include "tr-assert.h"
#include "utils.h" /* tr_buildPath */
#include "variant.h"
@ -759,7 +760,7 @@ static uint64_t loadFromFile(tr_torrent* tor, uint64_t fieldsToLoad)
bool const wasDirty = tor->isDirty;
tr_error* error = NULL;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
filename = getResumeFilename(tor);
@ -978,7 +979,7 @@ uint64_t tr_torrentLoadResume(tr_torrent* tor, uint64_t fieldsToLoad, tr_ctor co
{
uint64_t ret = 0;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
ret |= useManditoryFields(tor, fieldsToLoad, ctor);
fieldsToLoad &= ~ret;

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <string.h> /* memcpy */
@ -31,6 +30,7 @@
#include "rpc-server.h"
#include "session.h"
#include "session-id.h"
#include "tr-assert.h"
#include "trevent.h"
#include "utils.h"
#include "variant.h"
@ -796,7 +796,7 @@ static void restartServer(void* vserver)
void tr_rpcSetPort(tr_rpc_server* server, tr_port port)
{
assert(server != NULL);
TR_ASSERT(server != NULL);
if (server->port != port)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <ctype.h> /* isdigit */
#include <errno.h>
#include <stdlib.h> /* strtol */
@ -28,6 +27,7 @@
#include "session.h"
#include "session-id.h"
#include "torrent.h"
#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "version.h"
@ -251,7 +251,7 @@ static char const* torrentStart(tr_session* session, tr_variant* args_in, tr_var
int torrentCount;
tr_torrent** torrents;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
qsort(torrents, torrentCount, sizeof(tr_torrent*), compareTorrentByQueuePosition);
@ -277,7 +277,7 @@ static char const* torrentStartNow(tr_session* session, tr_variant* args_in, tr_
int torrentCount;
tr_torrent** torrents;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
qsort(torrents, torrentCount, sizeof(tr_torrent*), compareTorrentByQueuePosition);
@ -303,7 +303,7 @@ static char const* torrentStop(tr_session* session, tr_variant* args_in, tr_vari
int torrentCount;
tr_torrent** torrents;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
@ -330,7 +330,7 @@ static char const* torrentRemove(tr_session* session, tr_variant* args_in, tr_va
bool deleteFlag;
tr_torrent** torrents;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
if (!tr_variantDictFindBool(args_in, TR_KEY_delete_local_data, &deleteFlag))
{
@ -362,7 +362,7 @@ static char const* torrentReannounce(tr_session* session, tr_variant* args_in, t
int torrentCount;
tr_torrent** torrents;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
@ -387,7 +387,7 @@ static char const* torrentVerify(tr_session* session, tr_variant* args_in, tr_va
int torrentCount;
tr_torrent** torrents;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
@ -894,7 +894,7 @@ static char const* torrentGet(tr_session* session, tr_variant* args_in, tr_varia
char const* strVal;
char const* errmsg = NULL;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
if (tr_variantDictFindStr(args_in, TR_KEY_ids, &strVal, NULL) && strcmp(strVal, "recently-active") == 0)
{
@ -1228,7 +1228,7 @@ static char const* torrentSet(tr_session* session, tr_variant* args_in, tr_varia
tr_torrent** torrents;
char const* errmsg = NULL;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
@ -1358,7 +1358,7 @@ static char const* torrentSetLocation(tr_session* session, tr_variant* args_in,
{
char const* location = NULL;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
if (!tr_variantDictFindStr(args_in, TR_KEY_location, &location, NULL))
{
@ -1714,7 +1714,7 @@ static char const* torrentAdd(tr_session* session, tr_variant* args_in, tr_varia
char const* filename = NULL;
char const* metainfo_base64 = NULL;
assert(idle_data != NULL);
TR_ASSERT(idle_data != NULL);
tr_variantDictFindStr(args_in, TR_KEY_filename, &filename, NULL);
tr_variantDictFindStr(args_in, TR_KEY_metainfo, &metainfo_base64, NULL);
@ -1848,7 +1848,7 @@ static char const* torrentAdd(tr_session* session, tr_variant* args_in, tr_varia
static char const* sessionSet(tr_session* session, tr_variant* args_in, tr_variant* args_out UNUSED,
struct tr_rpc_idle_data* idle_data UNUSED)
{
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
char const* download_dir = NULL;
char const* incomplete_dir = NULL;
@ -2110,7 +2110,7 @@ static char const* sessionStats(tr_session* session, tr_variant* args_in UNUSED,
tr_session_stats cumulativeStats = { 0.0f, 0, 0, 0, 0, 0 };
tr_torrent* tor = NULL;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
while ((tor = tr_torrentNext(session, tor)) != NULL)
{
@ -2378,7 +2378,7 @@ static char const* sessionGet(tr_session* s, tr_variant* args_in, tr_variant* ar
{
tr_variant* fields;
assert(idle_data == NULL);
TR_ASSERT(idle_data == NULL);
if (tr_variantDictFindList(args_in, TR_KEY_fields, &fields))
{

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@
#include "magnet.h"
#include "session.h" /* tr_sessionFindTorrentFile() */
#include "torrent.h" /* tr_ctorGetSave() */
#include "tr-assert.h"
#include "utils.h" /* tr_new0 */
#include "variant.h"
@ -311,8 +312,8 @@ void tr_ctorSetPaused(tr_ctor* ctor, tr_ctorMode mode, bool isPaused)
{
struct optional_args* args;
assert(ctor != NULL);
assert(mode == TR_FALLBACK || mode == TR_FORCE);
TR_ASSERT(ctor != NULL);
TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
args = &ctor->optionalArgs[mode];
args->isSet_paused = true;
@ -323,8 +324,8 @@ void tr_ctorSetPeerLimit(tr_ctor* ctor, tr_ctorMode mode, uint16_t peerLimit)
{
struct optional_args* args;
assert(ctor != NULL);
assert(mode == TR_FALLBACK || mode == TR_FORCE);
TR_ASSERT(ctor != NULL);
TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
args = &ctor->optionalArgs[mode];
args->isSet_connected = true;
@ -335,8 +336,8 @@ void tr_ctorSetDownloadDir(tr_ctor* ctor, tr_ctorMode mode, char const* director
{
struct optional_args* args;
assert(ctor != NULL);
assert(mode == TR_FALLBACK || mode == TR_FORCE);
TR_ASSERT(ctor != NULL);
TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
args = &ctor->optionalArgs[mode];
tr_free(args->downloadDir);

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <string.h> /* memcpy(), memset(), memcmp() */
#include <event2/buffer.h>
@ -20,6 +19,7 @@
#include "resume.h"
#include "torrent.h"
#include "torrent-magnet.h"
#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "web.h"
@ -145,7 +145,7 @@ static size_t findInfoDictOffset(tr_torrent const* tor)
static void ensureInfoDictOffsetIsCached(tr_torrent* tor)
{
assert(tr_torrentHasMetadata(tor));
TR_ASSERT(tr_torrentHasMetadata(tor));
if (!tor->infoDictOffsetIsCached)
{
@ -158,9 +158,9 @@ void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len)
{
char* ret = NULL;
assert(tr_isTorrent(tor));
assert(piece >= 0);
assert(len != NULL);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(piece >= 0);
TR_ASSERT(len != NULL);
if (tr_torrentHasMetadata(tor))
{
@ -168,7 +168,7 @@ void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len)
ensureInfoDictOffsetIsCached(tor);
assert(tor->infoDictLength > 0);
TR_ASSERT(tor->infoDictLength > 0);
fd = tr_sys_file_open(tor->info.torrent, TR_SYS_FILE_READ, 0, NULL);
@ -200,7 +200,7 @@ void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len)
}
}
assert(ret == NULL || *len > 0);
TR_ASSERT(ret == NULL || *len > 0);
return ret;
}
@ -210,9 +210,9 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in
struct tr_incomplete_metadata* m;
int const offset = piece * METADATA_PIECE_SIZE;
assert(tr_isTorrent(tor));
assert(data != NULL);
assert(len >= 0);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(data != NULL);
TR_ASSERT(len >= 0);
dbgmsg(tor, "got metadata piece %d of %d bytes", piece, len);
@ -235,7 +235,7 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in
return;
}
assert(offset <= m->metadata_size);
TR_ASSERT(offset <= m->metadata_size);
if (len == 0 || len > m->metadata_size - offset)
{
@ -364,7 +364,7 @@ bool tr_torrentGetNextMetadataRequest(tr_torrent* tor, time_t now, int* setme_pi
bool have_request = false;
struct tr_incomplete_metadata* m;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
m = tor->incompleteMetadata;

View File

@ -16,7 +16,6 @@
#include <windows.h> /* CreateProcess(), GetLastError() */
#endif
#include <assert.h>
#include <math.h>
#include <stdarg.h>
#include <string.h> /* memcmp */
@ -46,6 +45,7 @@
#include "session.h"
#include "torrent.h"
#include "torrent-magnet.h"
#include "tr-assert.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
#include "variant.h"
@ -154,8 +154,8 @@ bool tr_torrentIsPieceTransferAllowed(tr_torrent const* tor, tr_direction direct
bool allowed = true;
unsigned int limit;
assert(tr_isTorrent(tor));
assert(tr_isDirection(direction));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_isDirection(direction));
if (tr_torrentUsesSpeedLimit(tor, direction))
{
@ -239,8 +239,8 @@ unsigned char const* tr_torrentGetPeerId(tr_torrent* tor)
void tr_torrentSetSpeedLimit_Bps(tr_torrent* tor, tr_direction dir, unsigned int Bps)
{
assert(tr_isTorrent(tor));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_isDirection(dir));
if (tr_bandwidthSetDesiredSpeed_Bps(&tor->bandwidth, dir, Bps))
{
@ -255,24 +255,24 @@ void tr_torrentSetSpeedLimit_KBps(tr_torrent* tor, tr_direction dir, unsigned in
unsigned int tr_torrentGetSpeedLimit_Bps(tr_torrent const* tor, tr_direction dir)
{
assert(tr_isTorrent(tor));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_isDirection(dir));
return tr_bandwidthGetDesiredSpeed_Bps(&tor->bandwidth, dir);
}
unsigned int tr_torrentGetSpeedLimit_KBps(tr_torrent const* tor, tr_direction dir)
{
assert(tr_isTorrent(tor));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_isDirection(dir));
return toSpeedKBps(tr_torrentGetSpeedLimit_Bps(tor, dir));
}
void tr_torrentUseSpeedLimit(tr_torrent* tor, tr_direction dir, bool do_use)
{
assert(tr_isTorrent(tor));
assert(tr_isDirection(dir));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_isDirection(dir));
if (tr_bandwidthSetLimited(&tor->bandwidth, dir, do_use))
{
@ -282,7 +282,7 @@ void tr_torrentUseSpeedLimit(tr_torrent* tor, tr_direction dir, bool do_use)
bool tr_torrentUsesSpeedLimit(tr_torrent const* tor, tr_direction dir)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tr_bandwidthIsLimited(&tor->bandwidth, dir);
}
@ -291,7 +291,7 @@ void tr_torrentUseSessionLimits(tr_torrent* tor, bool doUse)
{
bool changed;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
changed = tr_bandwidthHonorParentLimits(&tor->bandwidth, TR_UP, doUse);
changed |= tr_bandwidthHonorParentLimits(&tor->bandwidth, TR_DOWN, doUse);
@ -304,7 +304,7 @@ void tr_torrentUseSessionLimits(tr_torrent* tor, bool doUse)
bool tr_torrentUsesSessionLimits(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tr_bandwidthAreParentLimitsHonored(&tor->bandwidth, TR_UP);
}
@ -315,8 +315,8 @@ bool tr_torrentUsesSessionLimits(tr_torrent const* tor)
void tr_torrentSetRatioMode(tr_torrent* tor, tr_ratiolimit mode)
{
assert(tr_isTorrent(tor));
assert(mode == TR_RATIOLIMIT_GLOBAL || mode == TR_RATIOLIMIT_SINGLE || mode == TR_RATIOLIMIT_UNLIMITED);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(mode == TR_RATIOLIMIT_GLOBAL || mode == TR_RATIOLIMIT_SINGLE || mode == TR_RATIOLIMIT_UNLIMITED);
if (mode != tor->ratioLimitMode)
{
@ -328,14 +328,14 @@ void tr_torrentSetRatioMode(tr_torrent* tor, tr_ratiolimit mode)
tr_ratiolimit tr_torrentGetRatioMode(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->ratioLimitMode;
}
void tr_torrentSetRatioLimit(tr_torrent* tor, double desiredRatio)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if ((int)(desiredRatio * 100.0) != (int)(tor->desiredRatio * 100.0))
{
@ -347,7 +347,7 @@ void tr_torrentSetRatioLimit(tr_torrent* tor, double desiredRatio)
double tr_torrentGetRatioLimit(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->desiredRatio;
}
@ -356,7 +356,7 @@ bool tr_torrentGetSeedRatio(tr_torrent const* tor, double* ratio)
{
bool isLimited;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
switch (tr_torrentGetRatioMode(tor))
{
@ -395,7 +395,7 @@ static bool tr_torrentGetSeedRatioBytes(tr_torrent const* tor, uint64_t* setmeLe
double seedRatio;
bool seedRatioApplies = false;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tr_torrentGetSeedRatio(tor, &seedRatio))
{
@ -432,8 +432,8 @@ static bool tr_torrentIsSeedRatioDone(tr_torrent const* tor)
void tr_torrentSetIdleMode(tr_torrent* tor, tr_idlelimit mode)
{
assert(tr_isTorrent(tor));
assert(mode == TR_IDLELIMIT_GLOBAL || mode == TR_IDLELIMIT_SINGLE || mode == TR_IDLELIMIT_UNLIMITED);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(mode == TR_IDLELIMIT_GLOBAL || mode == TR_IDLELIMIT_SINGLE || mode == TR_IDLELIMIT_UNLIMITED);
if (mode != tor->idleLimitMode)
{
@ -445,14 +445,14 @@ void tr_torrentSetIdleMode(tr_torrent* tor, tr_idlelimit mode)
tr_idlelimit tr_torrentGetIdleMode(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->idleLimitMode;
}
void tr_torrentSetIdleLimit(tr_torrent* tor, uint16_t idleMinutes)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (idleMinutes > 0)
{
@ -464,7 +464,7 @@ void tr_torrentSetIdleLimit(tr_torrent* tor, uint16_t idleMinutes)
uint16_t tr_torrentGetIdleLimit(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->idleLimitMinutes;
}
@ -516,7 +516,7 @@ static bool tr_torrentIsSeedIdleLimitDone(tr_torrent* tor)
void tr_torrentCheckSeedLimit(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (!tor->isRunning || tor->isStopping || !tr_torrentIsSeed(tor))
{
@ -560,7 +560,7 @@ void tr_torrentSetLocalError(tr_torrent* tor, char const* fmt, ...)
{
va_list ap;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
va_start(ap, fmt);
tor->error = TR_STAT_LOCAL_ERROR;
@ -643,8 +643,8 @@ static tr_piece_index_t getBytePiece(tr_info const* info, uint64_t byteOffset)
{
tr_piece_index_t piece;
assert(info != NULL);
assert(info->pieceSize != 0);
TR_ASSERT(info != NULL);
TR_ASSERT(info->pieceSize != 0);
piece = byteOffset / info->pieceSize;
@ -663,8 +663,8 @@ static void initFilePieces(tr_info* info, tr_file_index_t fileIndex)
uint64_t firstByte;
uint64_t lastByte;
assert(info);
assert(fileIndex < info->fileCount);
TR_ASSERT(info != NULL);
TR_ASSERT(fileIndex < info->fileCount);
file = &info->files[fileIndex];
firstByte = file->offset;
@ -767,12 +767,12 @@ static void tr_torrentInitFilePieces(tr_torrent* tor)
for (tr_piece_index_t p = 0; p < inf->pieceCount; ++p)
{
tr_file_index_t f = firstFiles[p];
assert(inf->files[f].firstPiece <= p);
assert(inf->files[f].lastPiece >= p);
TR_ASSERT(inf->files[f].firstPiece <= p);
TR_ASSERT(inf->files[f].lastPiece >= p);
if (f > 0)
{
assert(inf->files[f - 1].lastPiece < p);
TR_ASSERT(inf->files[f - 1].lastPiece < p);
}
f = 0;
@ -785,7 +785,7 @@ static void tr_torrentInitFilePieces(tr_torrent* tor)
}
}
assert((int)f == firstFiles[p]);
TR_ASSERT((int)f == firstFiles[p]);
}
#endif
@ -858,21 +858,21 @@ static void torrentInitFromInfo(tr_torrent* tor)
/* check our work */
if (tor->blockSize != 0)
{
assert(info->pieceSize % tor->blockSize == 0);
TR_ASSERT(info->pieceSize % tor->blockSize == 0);
}
t = info->pieceCount - 1;
t *= info->pieceSize;
t += tor->lastPieceSize;
assert(t == info->totalSize);
TR_ASSERT(t == info->totalSize);
t = tor->blockCount - 1;
t *= tor->blockSize;
t += tor->lastBlockSize;
assert(t == info->totalSize);
TR_ASSERT(t == info->totalSize);
t = info->pieceCount - 1;
t *= tor->blockCountInPiece;
t += tor->blockCountInLastPiece;
assert(t == (uint64_t)tor->blockCount);
TR_ASSERT(t == (uint64_t)tor->blockCount);
tr_cpConstruct(&tor->completion, tor);
@ -928,7 +928,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
tr_session* session = tr_ctorGetSession(ctor);
static int nextUniqueId = 1;
assert(session != NULL);
TR_ASSERT(session != NULL);
tr_sessionLock(session);
@ -962,8 +962,8 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
tr_peerMgrAddTorrent(session->peerMgr, tor);
assert(tor->downloadedCur == 0);
assert(tor->uploadedCur == 0);
TR_ASSERT(tor->downloadedCur == 0);
TR_ASSERT(tor->uploadedCur == 0);
tr_torrentSetAddedDate(tor, tr_time()); /* this is a default value to be overwritten by the resume file */
@ -1134,8 +1134,8 @@ tr_torrent* tr_torrentNew(tr_ctor const* ctor, int* setme_error, int* setme_dupl
tr_parse_result r;
tr_torrent* tor = NULL;
assert(ctor != NULL);
assert(tr_isSession(tr_ctorGetSession(ctor)));
TR_ASSERT(ctor != NULL);
TR_ASSERT(tr_isSession(tr_ctorGetSession(ctor)));
r = torrentParseImpl(ctor, &tmpInfo, &hasInfo, &len, setme_duplicate_id);
@ -1173,7 +1173,7 @@ tr_torrent* tr_torrentNew(tr_ctor const* ctor, int* setme_error, int* setme_dupl
void tr_torrentSetDownloadDir(tr_torrent* tor, char const* path)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (path == NULL || tor->downloadDir == NULL || strcmp(path, tor->downloadDir) != 0)
{
@ -1187,21 +1187,21 @@ void tr_torrentSetDownloadDir(tr_torrent* tor, char const* path)
char const* tr_torrentGetDownloadDir(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->downloadDir;
}
char const* tr_torrentGetCurrentDir(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->currentDir;
}
void tr_torrentChangeMyPort(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tor->isRunning)
{
@ -1213,7 +1213,7 @@ static inline void tr_torrentManualUpdateImpl(void* vtor)
{
tr_torrent* tor = vtor;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tor->isRunning)
{
@ -1223,7 +1223,7 @@ static inline void tr_torrentManualUpdateImpl(void* vtor)
void tr_torrentManualUpdate(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_runInEventThread(tor->session, tr_torrentManualUpdateImpl, tor);
}
@ -1247,8 +1247,8 @@ tr_stat const* tr_torrentStatCached(tr_torrent* tor)
void tr_torrentSetVerifyState(tr_torrent* tor, tr_verify_state state)
{
assert(tr_isTorrent(tor));
assert(state == TR_VERIFY_NONE || state == TR_VERIFY_WAIT || state == TR_VERIFY_NOW);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(state == TR_VERIFY_NONE || state == TR_VERIFY_WAIT || state == TR_VERIFY_NOW);
tor->verifyState = state;
tor->anyDate = tr_time();
@ -1344,7 +1344,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
unsigned int pieceDownloadSpeed_Bps;
struct tr_swarm_stats swarm_stats;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->lastStatTime = tr_time();
@ -1500,9 +1500,9 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
}
/* test some of the constraints */
assert(s->sizeWhenDone <= tor->info.totalSize);
assert(s->leftUntilDone <= s->sizeWhenDone);
assert(s->desiredAvailable <= s->leftUntilDone);
TR_ASSERT(s->sizeWhenDone <= tor->info.totalSize);
TR_ASSERT(s->leftUntilDone <= s->sizeWhenDone);
TR_ASSERT(s->desiredAvailable <= s->leftUntilDone);
return s;
}
@ -1563,7 +1563,7 @@ tr_file_stat* tr_torrentFiles(tr_torrent const* tor, tr_file_index_t* fileCount)
tr_file_stat* walk = files;
bool const isSeed = tor->completeness == TR_SEED;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
for (tr_file_index_t i = 0; i < n; ++i, ++walk)
{
@ -1591,14 +1591,14 @@ void tr_torrentFilesFree(tr_file_stat* files, tr_file_index_t fileCount UNUSED)
double* tr_torrentWebSpeeds_KBps(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tr_peerMgrWebSpeeds_KBps(tor);
}
tr_peer_stat* tr_torrentPeers(tr_torrent const* tor, int* peerCount)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tr_peerMgrPeerStats(tor, peerCount);
}
@ -1610,7 +1610,7 @@ void tr_torrentPeersFree(tr_peer_stat* peers, int peerCount UNUSED)
tr_tracker_stat* tr_torrentTrackers(tr_torrent const* tor, int* setmeTrackerCount)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tr_announcerStats(tor, setmeTrackerCount);
}
@ -1622,7 +1622,7 @@ void tr_torrentTrackersFree(tr_tracker_stat* trackers, int trackerCount)
void tr_torrentAvailability(tr_torrent const* tor, int8_t* tab, int size)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tab != NULL && size > 0)
{
@ -1653,8 +1653,8 @@ static void tr_torrentResetTransferStats(tr_torrent* tor)
void tr_torrentSetHasPiece(tr_torrent* tor, tr_piece_index_t pieceIndex, bool has)
{
assert(tr_isTorrent(tor));
assert(pieceIndex < tor->info.pieceCount);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(pieceIndex < tor->info.pieceCount);
if (has)
{
@ -1670,7 +1670,7 @@ void tr_torrentSetHasPiece(tr_torrent* tor, tr_piece_index_t pieceIndex, bool ha
****
***/
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
static bool queueIsSequenced(tr_session*);
#endif
@ -1680,7 +1680,7 @@ static void freeTorrent(tr_torrent* tor)
tr_info* inf = &tor->info;
time_t const now = tr_time();
assert(!tor->isRunning);
TR_ASSERT(!tor->isRunning);
tr_sessionLock(session);
@ -1710,7 +1710,7 @@ static void freeTorrent(tr_torrent* tor)
}
/* decrement the torrent count */
assert(session->torrentCount >= 1);
TR_ASSERT(session->torrentCount >= 1);
session->torrentCount--;
/* resequence the queue positions */
@ -1725,7 +1725,7 @@ static void freeTorrent(tr_torrent* tor)
}
}
assert(queueIsSequenced(session));
TR_ASSERT(queueIsSequenced(session));
tr_bandwidthDestruct(&tor->bandwidth);
@ -1747,7 +1747,7 @@ static void torrentStartImpl(void* vtor)
time_t now;
tr_torrent* tor = vtor;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_sessionLock(tor->session);
@ -1921,7 +1921,7 @@ cleanup:
static void onVerifyDone(tr_torrent* tor, bool aborted, void* vdata)
{
struct verify_data* data = vdata;
assert(data->tor == tor);
TR_ASSERT(data->tor == tor);
if (tor->isDeleting)
{
@ -1985,7 +1985,7 @@ void tr_torrentVerify(tr_torrent* tor, tr_verify_done_func callback_func, void*
void tr_torrentSave(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tor->isDirty)
{
@ -1999,7 +1999,7 @@ static void stopTorrent(void* vtor)
tr_torrent* tor = vtor;
tr_logAddTorInfo(tor, "%s", "Pausing");
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
@ -2030,7 +2030,7 @@ static void stopTorrent(void* vtor)
void tr_torrentStop(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tr_isTorrent(tor))
{
@ -2050,7 +2050,7 @@ static void closeTorrent(void* vtor)
tr_variant* d;
tr_torrent* tor = vtor;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
d = tr_variantListAddDict(&tor->session->removedTorrents, 2);
tr_variantDictAddInt(d, TR_KEY_id, tor->uniqueId);
@ -2076,7 +2076,7 @@ void tr_torrentFree(tr_torrent* tor)
if (tr_isTorrent(tor))
{
tr_session* session = tor->session;
assert(tr_isSession(session));
TR_ASSERT(tr_isSession(session));
tr_sessionLock(session);
tr_torrentClearCompletenessCallback(tor);
@ -2117,7 +2117,7 @@ void tr_torrentRemove(tr_torrent* tor, bool deleteFlag, tr_fileFunc deleteFunc)
{
struct remove_data* data;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->isDeleting = true;
data = tr_new0(struct remove_data, 1);
@ -2153,7 +2153,7 @@ static char const* getCompletionString(int type)
static void fireCompletenessChange(tr_torrent* tor, tr_completeness status, bool wasRunning)
{
assert(status == TR_LEECH || status == TR_SEED || status == TR_PARTIAL_SEED);
TR_ASSERT(status == TR_LEECH || status == TR_SEED || status == TR_PARTIAL_SEED);
if (tor->completeness_func != NULL)
{
@ -2163,7 +2163,7 @@ static void fireCompletenessChange(tr_torrent* tor, tr_completeness status, bool
void tr_torrentSetCompletenessCallback(tr_torrent* tor, tr_torrent_completeness_func func, void* user_data)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->completeness_func = func;
tor->completeness_func_user_data = user_data;
@ -2176,7 +2176,7 @@ void tr_torrentClearCompletenessCallback(tr_torrent* torrent)
void tr_torrentSetRatioLimitHitCallback(tr_torrent* tor, tr_torrent_ratio_limit_hit_func func, void* user_data)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->ratio_limit_hit_func = func;
tor->ratio_limit_hit_func_user_data = user_data;
@ -2189,7 +2189,7 @@ void tr_torrentClearRatioLimitHitCallback(tr_torrent* torrent)
void tr_torrentSetIdleLimitHitCallback(tr_torrent* tor, tr_torrent_idle_limit_hit_func func, void* user_data)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->idle_limit_hit_func = func;
tor->idle_limit_hit_func_user_data = user_data;
@ -2250,12 +2250,12 @@ static void torrentCallScript(tr_torrent const* tor, char const* script)
tr_logAddTorInfo(tor, "Calling script \"%s\"", script);
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
/* Win32 environment block strings should be sorted alphabetically */
for (size_t i = 1; env[i] != NULL; ++i)
{
assert(strcmp(env[i - 1], env[i]) < 0);
TR_ASSERT(strcmp(env[i - 1], env[i]) < 0);
}
#endif
@ -2416,7 +2416,7 @@ void tr_torrentRecheckCompleteness(tr_torrent* tor)
static void tr_torrentFireMetadataCompleted(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tor->metadata_func != NULL)
{
@ -2426,7 +2426,7 @@ static void tr_torrentFireMetadataCompleted(tr_torrent* tor)
void tr_torrentSetMetadataCallback(tr_torrent* tor, tr_torrent_metadata_func func, void* user_data)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->metadata_func = func;
tor->metadata_func_user_data = user_data;
@ -2440,9 +2440,9 @@ void tr_torrentInitFilePriority(tr_torrent* tor, tr_file_index_t fileIndex, tr_p
{
tr_file* file;
assert(tr_isTorrent(tor));
assert(fileIndex < tor->info.fileCount);
assert(tr_isPriority(priority));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(fileIndex < tor->info.fileCount);
TR_ASSERT(tr_isPriority(priority));
file = &tor->info.files[fileIndex];
file->priority = priority;
@ -2456,7 +2456,7 @@ void tr_torrentInitFilePriority(tr_torrent* tor, tr_file_index_t fileIndex, tr_p
void tr_torrentSetFilePriorities(tr_torrent* tor, tr_file_index_t const* files, tr_file_index_t fileCount,
tr_priority_t priority)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
for (tr_file_index_t i = 0; i < fileCount; ++i)
@ -2477,7 +2477,7 @@ tr_priority_t* tr_torrentGetFilePriorities(tr_torrent const* tor)
{
tr_priority_t* p;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
p = tr_new0(tr_priority_t, tor->info.fileCount);
@ -2561,7 +2561,7 @@ static void setFileDND(tr_torrent* tor, tr_file_index_t fileIndex, int doDownloa
void tr_torrentInitFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file_index_t fileCount, bool doDownload)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
@ -2580,7 +2580,7 @@ void tr_torrentInitFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_fil
void tr_torrentSetFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file_index_t fileCount, bool doDownload)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
tr_torrentInitFileDLs(tor, files, fileCount, doDownload);
@ -2597,15 +2597,15 @@ void tr_torrentSetFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file
tr_priority_t tr_torrentGetPriority(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->bandwidth.priority;
}
void tr_torrentSetPriority(tr_torrent* tor, tr_priority_t priority)
{
assert(tr_isTorrent(tor));
assert(tr_isPriority(priority));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_isPriority(priority));
if (tor->bandwidth.priority != priority)
{
@ -2621,7 +2621,7 @@ void tr_torrentSetPriority(tr_torrent* tor, tr_priority_t priority)
void tr_torrentSetPeerLimit(tr_torrent* tor, uint16_t maxConnectedPeers)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tor->maxConnectedPeers != maxConnectedPeers)
{
@ -2633,7 +2633,7 @@ void tr_torrentSetPeerLimit(tr_torrent* tor, uint16_t maxConnectedPeers)
uint16_t tr_torrentGetPeerLimit(tr_torrent const* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
return tor->maxConnectedPeers;
}
@ -2656,7 +2656,7 @@ tr_block_index_t _tr_block(tr_torrent const* tor, tr_piece_index_t index, uint32
{
tr_block_index_t ret;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
ret = index;
ret *= tor->info.pieceSize / tor->blockSize;
@ -2668,7 +2668,7 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_
{
int err = 0;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (index >= tor->info.pieceCount)
{
@ -2704,7 +2704,7 @@ uint64_t tr_pieceOffset(tr_torrent const* tor, tr_piece_index_t index, uint32_t
{
uint64_t ret;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
ret = tor->info.pieceSize;
ret *= index;
@ -2747,15 +2747,15 @@ void tr_torGetPieceBlockRange(tr_torrent const* tor, tr_piece_index_t const piec
void tr_torrentSetPieceChecked(tr_torrent* tor, tr_piece_index_t pieceIndex)
{
assert(tr_isTorrent(tor));
assert(pieceIndex < tor->info.pieceCount);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(pieceIndex < tor->info.pieceCount);
tor->info.pieces[pieceIndex].timeChecked = tr_time();
}
void tr_torrentSetChecked(tr_torrent* tor, time_t when)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
for (tr_piece_index_t i = 0; i < tor->info.pieceCount; ++i)
{
@ -2846,7 +2846,7 @@ bool tr_torrentSetAnnounceList(tr_torrent* tor, tr_tracker_info const* trackers_
tr_torrentLock(tor);
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
/* ensure the trackers' tiers are in ascending order */
trackers = tr_memdup(trackers_in, sizeof(tr_tracker_info) * trackerCount);
@ -2954,7 +2954,7 @@ bool tr_torrentSetAnnounceList(tr_torrent* tor, tr_tracker_info const* trackers_
void tr_torrentSetAddedDate(tr_torrent* tor, time_t t)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->addedDate = t;
tor->anyDate = MAX(tor->anyDate, tor->addedDate);
@ -2962,7 +2962,7 @@ void tr_torrentSetAddedDate(tr_torrent* tor, time_t t)
void tr_torrentSetActivityDate(tr_torrent* tor, time_t t)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->activityDate = t;
tor->anyDate = MAX(tor->anyDate, tor->activityDate);
@ -2970,7 +2970,7 @@ void tr_torrentSetActivityDate(tr_torrent* tor, time_t t)
void tr_torrentSetDoneDate(tr_torrent* tor, time_t t)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->doneDate = t;
tor->anyDate = MAX(tor->anyDate, tor->doneDate);
@ -2984,7 +2984,7 @@ uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor)
{
uint64_t bytesLeft = 0;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
for (tr_file_index_t i = 0; i < tor->info.fileCount; ++i)
{
@ -3253,7 +3253,7 @@ static void deleteLocalData(tr_torrent* tor, tr_fileFunc func)
static void tr_torrentDeleteLocalData(tr_torrent* tor, tr_fileFunc func)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (func == NULL)
{
@ -3290,7 +3290,7 @@ static void setLocation(void* vdata)
double bytesHandled = 0;
tr_torrentLock(tor);
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_logAddDebug("Moving \"%s\" location from currentDir \"%s\" to \"%s\"", tr_torrentName(tor), tor->currentDir, location);
@ -3379,7 +3379,7 @@ void tr_torrentSetLocation(tr_torrent* tor, char const* location, bool move_from
{
struct LocationData* data;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (setme_state != NULL)
{
@ -3472,8 +3472,8 @@ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t block)
{
bool const block_is_new = !tr_torrentBlockIsComplete(tor, block);
assert(tr_isTorrent(tor));
assert(tr_amInEventThread(tor->session));
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_amInEventThread(tor->session));
if (block_is_new)
{
@ -3522,8 +3522,8 @@ bool tr_torrentFindFile2(tr_torrent const* tor, tr_file_index_t fileNum, char co
char const* s = NULL;
tr_sys_path_info file_info;
assert(tr_isTorrent(tor));
assert(fileNum < tor->info.fileCount);
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(fileNum < tor->info.fileCount);
file = &tor->info.files[fileNum];
@ -3642,8 +3642,8 @@ static void refreshCurrentDir(tr_torrent* tor)
dir = tor->incompleteDir;
}
assert(dir != NULL);
assert(dir == tor->downloadDir || dir == tor->incompleteDir);
TR_ASSERT(dir != NULL);
TR_ASSERT(dir == tor->downloadDir || dir == tor->incompleteDir);
tor->currentDir = dir;
}
@ -3664,7 +3664,7 @@ static int compareTorrentByQueuePosition(void const* va, void const* vb)
return a->queuePosition - b->queuePosition;
}
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
static bool queueIsSequenced(tr_session* session)
{
@ -3753,7 +3753,7 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, int pos)
tor->queuePosition = MIN(pos, back + 1);
tor->anyDate = now;
assert(queueIsSequenced(tor->session));
TR_ASSERT(queueIsSequenced(tor->session));
}
void tr_torrentsQueueMoveTop(tr_torrent** torrents_in, int n)
@ -3816,7 +3816,7 @@ void tr_torrentsQueueMoveBottom(tr_torrent** torrents_in, int n)
static void torrentSetQueued(tr_torrent* tor, bool queued)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tr_torrentIsQueued(tor) != queued)
{
@ -4007,7 +4007,7 @@ static void torrentRenamePath(void* vdata)
****
***/
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (!renameArgsAreValid(oldpath, newname))
{

View File

@ -15,6 +15,7 @@
#include "bandwidth.h" /* tr_bandwidth */
#include "completion.h" /* tr_completion */
#include "session.h" /* tr_sessionLock(), tr_sessionUnlock() */
#include "tr-assert.h"
#include "utils.h" /* TR_GNUC_PRINTF */
struct tr_torrent_tiers;
@ -332,7 +333,7 @@ static inline bool tr_isTorrent(tr_torrent const* tor)
* needs to be saved when the torrent is closed */
static inline void tr_torrentSetDirty(tr_torrent* tor)
{
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tor->isDirty = true;
}

View File

@ -0,0 +1,31 @@
/*
* This file Copyright (C) 2017 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "tr-assert.h"
#if !defined(NDEBUG) || defined(TR_FORCE_ASSERTIONS)
bool tr_assert_report(char const* file, int line, char const* message_fmt, ...)
{
va_list args;
va_start(args, message_fmt);
fprintf(stderr, "assertion failed: ");
vfprintf(stderr, message_fmt, args);
fprintf(stderr, " (%s:%d)\n", file, line);
va_end(args);
abort();
}
#endif

View File

@ -0,0 +1,55 @@
/*
* This file Copyright (C) 2017 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#pragma once
#if !defined(NDEBUG) || defined(TR_FORCE_ASSERTIONS)
#include <stdbool.h>
#ifndef TR_LIKELY
#if defined(__GNUC__)
#define TR_LIKELY(x) __builtin_expect(!!(x), true)
#else
#define TR_LIKELY(x) (x)
#endif
#endif
#ifndef TR_NORETURN
#if defined(__GNUC__)
#define TR_NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER)
#define TR_NORETURN __declspec(noreturn)
#else
#define TR_NORETURN
#endif
#endif
#ifndef TR_GNUC_PRINTF
#if defined(__GNUC__)
#define TR_GNUC_PRINTF(fmt, args) __attribute__((format(printf, fmt, args)))
#else
#define TR_GNUC_PRINTF(fmt, args)
#endif
#endif
bool TR_NORETURN tr_assert_report(char const* file, int line, char const* message_fmt, ...) TR_GNUC_PRINTF(3, 4);
#define TR_ASSERT(x) (TR_LIKELY(x) || tr_assert_report(__FILE__, __LINE__, "%s", #x))
#define TR_ASSERT_MSG(x, ...) (TR_LIKELY(x) || tr_assert_report(__FILE__, __LINE__, __VA_ARGS__))
#define TR_ENABLE_ASSERTS
#else
#define TR_ASSERT(x) ((void)0)
#define TR_ASSERT_MSG(x, ...) ((void)0)
#undef TR_ENABLE_ASSERTS
#endif

View File

@ -58,6 +58,7 @@
#include "platform.h" /* tr_threadNew() */
#include "session.h"
#include "torrent.h" /* tr_torrentFindFromHash() */
#include "tr-assert.h"
#include "tr-dht.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
@ -776,7 +777,7 @@ void tr_dhtCallback(unsigned char* buf, int buflen, struct sockaddr* from, sockl
time_t tosleep;
int rc;
assert(tr_isSession(sv));
TR_ASSERT(tr_isSession(sv));
if (sv != session)
{
@ -843,7 +844,7 @@ int dht_random_bytes(void* buf, size_t size)
int dht_gettimeofday(struct timeval* tv, struct timezone* tz)
{
assert(tz == NULL);
TR_ASSERT(tz == NULL);
return tr_gettimeofday(tv);
}

View File

@ -52,6 +52,7 @@ typedef uint16_t in_port_t; /* all missing */
#include "peer-mgr.h" /* tr_peerMgrAddPex() */
#include "session.h"
#include "torrent.h" /* tr_torrentFindFromHash() */
#include "tr-assert.h"
#include "tr-lpd.h"
#include "utils.h"
#include "version.h"
@ -174,7 +175,7 @@ static char const* lpd_extractHeader(char const* s, struct lpd_protocolVersion*
int minor = -1;
size_t len;
assert(s != NULL);
TR_ASSERT(s != NULL);
len = strlen(s);
/* something might be rotten with this chunk of data */
@ -239,8 +240,9 @@ static bool lpd_extractParam(char const* const str, char const* const name, int
char sstr[maxLength] = { 0 };
char const* pos;
assert(str != NULL && name != NULL);
assert(val != NULL);
TR_ASSERT(str != NULL);
TR_ASSERT(name != NULL);
TR_ASSERT(val != NULL);
if (strlen(name) > maxLength - strlen(CRLF ": "))
{
@ -304,8 +306,8 @@ int tr_lpdInit(tr_session* ss, tr_address* tr_addr UNUSED)
return -1;
}
assert(lpd_announceInterval > 0);
assert(lpd_announceScope > 0);
TR_ASSERT(lpd_announceInterval > 0);
TR_ASSERT(lpd_announceScope > 0);
lpd_port = tr_sessionGetPeerPort(ss);
@ -701,7 +703,7 @@ static void on_upkeep_timer(evutil_socket_t foo UNUSED, short bar UNUSED, void*
* @see DoS */
static void event_callback(evutil_socket_t s UNUSED, short type, void* ignore UNUSED)
{
assert(tr_isSession(session));
TR_ASSERT(tr_isSession(session));
/* do not allow announces to be processed if LPD is disabled */
if (!tr_sessionAllowsLPD(session))

View File

@ -21,7 +21,6 @@ THE SOFTWARE.
*/
#include <assert.h>
#include <string.h> /* memcmp(), memcpy(), memset() */
#include <stdlib.h> /* malloc(), free() */
@ -39,6 +38,7 @@ THE SOFTWARE.
#include "log.h"
#include "net.h"
#include "session.h"
#include "tr-assert.h"
#include "tr-dht.h"
#include "tr-utp.h"
#include "tr-udp.h"
@ -246,8 +246,8 @@ static void event_callback(evutil_socket_t s, short type UNUSED, void* sv)
struct sockaddr_storage from;
tr_session* ss = sv;
assert(tr_isSession(sv));
assert(type == EV_READ);
TR_ASSERT(tr_isSession(sv));
TR_ASSERT(type == EV_READ);
fromlen = sizeof(from);
rc = recvfrom(s, (void*)buf, 4096 - 1, 0, (struct sockaddr*)&from, &fromlen);
@ -300,8 +300,8 @@ void tr_udpInit(tr_session* ss)
struct sockaddr_in sin;
int rc;
assert(ss->udp_socket == TR_BAD_SOCKET);
assert(ss->udp6_socket == TR_BAD_SOCKET);
TR_ASSERT(ss->udp_socket == TR_BAD_SOCKET);
TR_ASSERT(ss->udp6_socket == TR_BAD_SOCKET);
ss->udp_port = tr_sessionGetPeerPort(ss);

View File

@ -21,8 +21,6 @@ THE SOFTWARE.
*/
#include <assert.h>
#include <event2/event.h>
#include <libutp/utp.h>
@ -33,6 +31,7 @@ THE SOFTWARE.
#include "session.h"
#include "crypto-utils.h" /* tr_rand_int_weak() */
#include "peer-mgr.h"
#include "tr-assert.h"
#include "tr-utp.h"
#include "utils.h"
@ -46,21 +45,21 @@ void UTP_Close(struct UTPSocket* socket)
{
tr_logAddNamedError(MY_NAME, "UTP_Close(%p) was called.", socket);
dbgmsg("UTP_Close(%p) was called.", socket);
assert(0); /* FIXME: this is too much for the long term, but probably needed in the short term */
TR_ASSERT(false); /* FIXME: this is too much for the long term, but probably needed in the short term */
}
void UTP_RBDrained(struct UTPSocket* socket)
{
tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p) was called.", socket);
dbgmsg("UTP_RBDrained(%p) was called.", socket);
assert(0); /* FIXME: this is too much for the long term, but probably needed in the short term */
TR_ASSERT(false); /* FIXME: this is too much for the long term, but probably needed in the short term */
}
bool UTP_Write(struct UTPSocket* socket, size_t count)
{
tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p, %zu) was called.", socket, count);
dbgmsg("UTP_RBDrained(%p, %zu) was called.", socket, count);
assert(0); /* FIXME: this is too much for the long term, but probably needed in the short term */
TR_ASSERT(false); /* FIXME: this is too much for the long term, but probably needed in the short term */
return false;
}

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <string.h>
@ -28,6 +27,7 @@
#include "transmission.h"
#include "platform.h" /* tr_lockLock() */
#include "tr-assert.h"
#include "trevent.h"
#include "utils.h"
@ -215,7 +215,7 @@ static void readFromPipe(evutil_socket_t fd, short eventType, void* veh)
default:
{
assert(0 && "unhandled command type!");
TR_ASSERT_MSG(false, "unhandled command type %d", (int)ch);
break;
}
}
@ -297,7 +297,7 @@ void tr_eventInit(tr_session* session)
void tr_eventClose(tr_session* session)
{
assert(tr_isSession(session));
TR_ASSERT(tr_isSession(session));
if (session->events == NULL)
{
@ -315,8 +315,8 @@ void tr_eventClose(tr_session* session)
bool tr_amInEventThread(tr_session const* session)
{
assert(tr_isSession(session));
assert(session->events != NULL);
TR_ASSERT(tr_isSession(session));
TR_ASSERT(session->events != NULL);
return tr_amInThread(session->events->thread);
}
@ -327,8 +327,8 @@ bool tr_amInEventThread(tr_session const* session)
void tr_runInEventThread(tr_session* session, void (* func)(void*), void* user_data)
{
assert(tr_isSession(session));
assert(session->events != NULL);
TR_ASSERT(tr_isSession(session));
TR_ASSERT(session->events != NULL);
if (tr_amInThread(session->events->thread))
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#ifdef SYSTEM_MINIUPNP
@ -21,6 +20,7 @@
#include "log.h"
#include "port-forwarding.h"
#include "session.h"
#include "tr-assert.h"
#include "upnp.h"
#include "utils.h"
@ -65,8 +65,8 @@ tr_upnp* tr_upnpInit(void)
void tr_upnpClose(tr_upnp* handle)
{
assert(!handle->isMapped);
assert(handle->state == TR_UPNP_IDLE || handle->state == TR_UPNP_ERR || handle->state == TR_UPNP_DISCOVER);
TR_ASSERT(!handle->isMapped);
TR_ASSERT(handle->state == TR_UPNP_IDLE || handle->state == TR_UPNP_ERR || handle->state == TR_UPNP_DISCOVER);
if (handle->hasDiscovered)
{

View File

@ -15,7 +15,6 @@
#define HAVE_VALLOC
#endif
#include <assert.h>
#include <ctype.h> /* isdigit(), tolower() */
#include <errno.h>
#include <float.h> /* DBL_EPSILON */
@ -50,9 +49,10 @@
#include "list.h"
#include "log.h"
#include "net.h"
#include "utils.h"
#include "platform.h" /* tr_lockLock() */
#include "platform-quota.h" /* tr_device_info_create(), tr_device_info_get_free_space(), tr_device_info_free() */
#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "version.h"
@ -216,9 +216,9 @@ void tr_timerAdd(struct event* timer, int seconds, int microseconds)
tv.tv_sec = seconds;
tv.tv_usec = microseconds;
assert(tv.tv_sec >= 0);
assert(tv.tv_usec >= 0);
assert(tv.tv_usec < 1000000);
TR_ASSERT(tv.tv_sec >= 0);
TR_ASSERT(tv.tv_usec >= 0);
TR_ASSERT(tv.tv_usec < 1000000);
evtimer_add(timer, &tv);
}
@ -260,7 +260,7 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
/* file size should be able to fit into size_t */
if (sizeof(info.size) > sizeof(*size))
{
assert(info.size <= SIZE_MAX);
TR_ASSERT(info.size <= SIZE_MAX);
}
/* Load the torrent file into our buffer */
@ -340,7 +340,7 @@ char* tr_buildPath(char const* first_element, ...)
*pch++ = '\0';
/* sanity checks & return */
assert(pch - buf == (ptrdiff_t)bufLen);
TR_ASSERT(pch - buf == (ptrdiff_t)bufLen);
return buf;
}
@ -667,8 +667,8 @@ size_t tr_strlcpy(char* dst, void const* src, size_t siz)
char const* s = src;
size_t n = siz;
assert(s);
assert(d);
TR_ASSERT(s != NULL);
TR_ASSERT(d != NULL);
/* Copy as many bytes as will fit */
if (n != 0)
@ -1047,19 +1047,19 @@ static size_t quickfindPartition(char* base, size_t left, size_t right, size_t s
SWAP(base + (size * right), base + (size * storeIndex), size);
/* sanity check the partition */
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
assert(storeIndex >= left);
assert(storeIndex <= right);
TR_ASSERT(storeIndex >= left);
TR_ASSERT(storeIndex <= right);
for (size_t i = left; i < storeIndex; ++i)
{
assert((*compar)(base + (size * i), base + (size * storeIndex)) <= 0);
TR_ASSERT((*compar)(base + (size * i), base + (size * storeIndex)) <= 0);
}
for (size_t i = storeIndex + 1; i <= right; ++i)
{
assert((*compar)(base + (size * i), base + (size * storeIndex)) >= 0);
TR_ASSERT((*compar)(base + (size * i), base + (size * storeIndex)) >= 0);
}
#endif
@ -1087,7 +1087,7 @@ static void quickfindFirstK(char* base, size_t left, size_t right, size_t size,
}
}
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, int (* compar)(void const*, void const*), size_t k)
{
@ -1103,12 +1103,12 @@ static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, int
for (size_t i = 0; i < k; ++i)
{
assert((*compar)(base + (size * i), base + (size * worstFirstPos)) <= 0);
TR_ASSERT((*compar)(base + (size * i), base + (size * worstFirstPos)) <= 0);
}
for (size_t i = k; i < nmemb; ++i)
{
assert((*compar)(base + (size * i), base + (size * worstFirstPos)) >= 0);
TR_ASSERT((*compar)(base + (size * i), base + (size * worstFirstPos)) >= 0);
}
}
@ -1120,7 +1120,7 @@ void tr_quickfindFirstK(void* base, size_t nmemb, size_t size, int (* compar)(vo
{
quickfindFirstK(base, 0, nmemb - 1, size, compar, k);
#ifndef NDEBUG
#ifdef TR_ENABLE_ASSERTS
checkBestScoresComeFirst(base, nmemb, size, compar, k);
#endif
}
@ -1215,7 +1215,7 @@ char* tr_utf8clean(char const* str, size_t max_len)
ret = to_utf8(str, max_len);
}
assert(tr_utf8_validate(ret, TR_BAD_SIZE, NULL));
TR_ASSERT(tr_utf8_validate(ret, TR_BAD_SIZE, NULL));
return ret;
}
@ -1345,7 +1345,7 @@ void tr_win32_make_args_utf8(int* argc, char*** argv)
return;
}
assert(*argc == my_argc);
TR_ASSERT(*argc == my_argc);
char** my_argv = tr_new(char*, my_argc + 1);
int processed_argc = 0;
@ -1540,7 +1540,7 @@ int* tr_parseNumberRange(char const* str_in, size_t len, int* setmeCount)
}
qsort(sorted, n, sizeof(int), compareInt);
assert(n == n2);
TR_ASSERT(n == n2);
/* remove duplicates */
uniq = tr_new(int, n);
@ -1709,8 +1709,8 @@ bool tr_moveFile(char const* oldpath, char const* newpath, tr_error** error)
break;
}
assert(numRead == bytesWritten);
assert(bytesWritten <= bytesLeft);
TR_ASSERT(numRead == bytesWritten);
TR_ASSERT(bytesWritten <= bytesLeft);
bytesLeft -= bytesWritten;
}
@ -2036,7 +2036,7 @@ void tr_formatter_get_units(void* vdict)
bool tr_env_key_exists(char const* key)
{
assert(key != NULL);
TR_ASSERT(key != NULL);
#ifdef _WIN32
return GetEnvironmentVariableA(key, NULL, 0) != 0;
@ -2051,7 +2051,7 @@ int tr_env_get_int(char const* key, int default_value)
char value[16];
assert(key != NULL);
TR_ASSERT(key != NULL);
if (GetEnvironmentVariableA(key, value, TR_N_ELEMENTS(value)) > 1)
{
@ -2062,7 +2062,7 @@ int tr_env_get_int(char const* key, int default_value)
char const* value;
assert(key != NULL);
TR_ASSERT(key != NULL);
value = getenv(key);
@ -2115,7 +2115,7 @@ char* tr_env_get_string(char const* key, char const* default_value)
char* value;
assert(key != NULL);
TR_ASSERT(key != NULL);
value = getenv(key);

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <ctype.h> /* isdigit() */
#include <errno.h>
#include <stdlib.h> /* strtoul() */

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <ctype.h>
#include <math.h> /* fabs() */
#include <stdio.h>
@ -26,6 +25,7 @@
#include "list.h"
#include "log.h"
#include "ptrarray.h"
#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "variant-common.h"
@ -130,9 +130,9 @@ static bool decode_hex_string(char const* in, unsigned int* setme)
unsigned int val = 0;
char const* const end = in + 6;
assert(in != NULL);
assert(in[0] == '\\');
assert(in[1] == 'u');
TR_ASSERT(in != NULL);
TR_ASSERT(in[0] == '\\');
TR_ASSERT(in[1] == 'u');
in += 2;
do

View File

@ -15,7 +15,6 @@
#define _GNU_SOURCE
#endif
#include <assert.h>
#include <errno.h>
#include <stdlib.h> /* strtod(), realloc(), qsort() */
#include <string.h>
@ -38,6 +37,7 @@
#include "error.h"
#include "file.h"
#include "log.h"
#include "tr-assert.h"
#include "utils.h" /* tr_new(), tr_free() */
#include "variant.h"
#include "variant-common.h"
@ -219,7 +219,7 @@ static void tr_variant_string_set_string(struct tr_variant_string* str, char con
static inline char const* getStr(tr_variant const* v)
{
assert(tr_variantIsString(v));
TR_ASSERT(tr_variantIsString(v));
return tr_variant_string_get_string(&v->val.s);
}
@ -489,7 +489,7 @@ static void containerReserve(tr_variant* v, size_t count)
{
size_t const needed = v->val.l.count + count;
assert(tr_variantIsContainer(v));
TR_ASSERT(tr_variantIsContainer(v));
if (needed > v->val.l.alloc)
{
@ -508,7 +508,7 @@ static void containerReserve(tr_variant* v, size_t count)
void tr_variantListReserve(tr_variant* list, size_t count)
{
assert(tr_variantIsList(list));
TR_ASSERT(tr_variantIsList(list));
containerReserve(list, count);
}
@ -520,7 +520,7 @@ void tr_variantInitDict(tr_variant* v, size_t reserve_count)
void tr_variantDictReserve(tr_variant* dict, size_t reserve_count)
{
assert(tr_variantIsDict(dict));
TR_ASSERT(tr_variantIsDict(dict));
containerReserve(dict, reserve_count);
}
@ -528,7 +528,7 @@ tr_variant* tr_variantListAdd(tr_variant* list)
{
tr_variant* child;
assert(tr_variantIsList(list));
TR_ASSERT(tr_variantIsList(list));
containerReserve(list, 1);
child = &list->val.l.vals[list->val.l.count++];
@ -598,7 +598,7 @@ tr_variant* tr_variantDictAdd(tr_variant* dict, tr_quark const key)
{
tr_variant* val;
assert(tr_variantIsDict(dict));
TR_ASSERT(tr_variantIsDict(dict));
containerReserve(dict, 1);
@ -1008,7 +1008,7 @@ bool tr_variantDictChild(tr_variant* dict, size_t n, tr_quark* key, tr_variant**
{
bool success = 0;
assert(tr_variantIsDict(dict));
TR_ASSERT(tr_variantIsDict(dict));
if (tr_variantIsDict(dict) && n < dict->val.l.count)
{
@ -1024,8 +1024,8 @@ void tr_variantMergeDicts(tr_variant* target, tr_variant const* source)
{
size_t const sourceCount = tr_variantDictSize(source);
assert(tr_variantIsDict(target));
assert(tr_variantIsDict(source));
TR_ASSERT(tr_variantIsDict(target));
TR_ASSERT(tr_variantIsDict(source));
tr_variantDictReserve(target, sourceCount + tr_variantDictSize(target));

View File

@ -26,6 +26,7 @@
#include "log.h"
#include "platform.h" /* tr_lock() */
#include "torrent.h"
#include "tr-assert.h"
#include "utils.h" /* tr_valloc(), tr_free() */
#include "verify.h"
@ -231,7 +232,7 @@ static void verifyThreadFunc(void* unused UNUSED)
tr_torrentSetVerifyState(tor, TR_VERIFY_NOW);
changed = verifyTorrent(tor, &stopCurrent);
tr_torrentSetVerifyState(tor, TR_VERIFY_NONE);
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (!stopCurrent && changed)
{
@ -280,7 +281,7 @@ void tr_verifyAdd(tr_torrent* tor, tr_verify_done_func callback_func, void* call
{
struct verify_node* node;
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
tr_logAddTorInfo(tor, "%s", _("Queued for verification"));
node = tr_new(struct verify_node, 1);
@ -313,7 +314,7 @@ void tr_verifyRemove(tr_torrent* tor)
tr_lock* lock = getVerifyLock();
tr_lockLock(lock);
assert(tr_isTorrent(tor));
TR_ASSERT(tr_isTorrent(tor));
if (tor == currentNode.torrent)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <event2/event.h>
@ -16,6 +15,7 @@
#include "transmission.h"
#include "log.h"
#include "ptrarray.h"
#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
@ -66,7 +66,7 @@ static void tr_watchdir_generic_free(tr_watchdir_backend* backend_base)
return;
}
assert(backend->base.free_func == &tr_watchdir_generic_free);
TR_ASSERT(backend->base.free_func == &tr_watchdir_generic_free);
if (backend->event != NULL)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <limits.h> /* NAME_MAX */
#include <stdlib.h> /* realloc() */
@ -22,6 +21,7 @@
#include "transmission.h"
#include "log.h"
#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
@ -64,7 +64,7 @@ static void tr_watchdir_inotify_on_first_scan(evutil_socket_t fd UNUSED, short t
static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* context)
{
assert(context != NULL);
TR_ASSERT(context != NULL);
tr_watchdir_t const handle = context;
tr_watchdir_inotify* const backend = BACKEND_UPCAST(tr_watchdir_get_backend(handle));
@ -89,9 +89,9 @@ static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* contex
break;
}
assert(ev.wd == backend->inwd);
assert((ev.mask & INOTIFY_WATCH_MASK) != 0);
assert(ev.len > 0);
TR_ASSERT(ev.wd == backend->inwd);
TR_ASSERT((ev.mask & INOTIFY_WATCH_MASK) != 0);
TR_ASSERT(ev.len > 0);
if (ev.len > name_size)
{
@ -127,7 +127,7 @@ static void tr_watchdir_inotify_free(tr_watchdir_backend* backend_base)
return;
}
assert(backend->base.free_func == &tr_watchdir_inotify_free);
TR_ASSERT(backend->base.free_func == &tr_watchdir_inotify_free);
if (backend->event != NULL)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <string.h> /* strcmp() */
@ -27,6 +26,7 @@
#include "transmission.h"
#include "log.h"
#include "ptrarray.h"
#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
@ -87,7 +87,7 @@ static void tr_watchdir_kqueue_free(tr_watchdir_backend* backend_base)
return;
}
assert(backend->base.free_func == &tr_watchdir_kqueue_free);
TR_ASSERT(backend->base.free_func == &tr_watchdir_kqueue_free);
if (backend->event != NULL)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stddef.h> /* offsetof */
#include <stdlib.h> /* realloc() */
@ -24,6 +23,7 @@
#include "transmission.h"
#include "log.h"
#include "net.h"
#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
@ -92,7 +92,7 @@ static BOOL tr_get_overlapped_result_ex(HANDLE handle, LPOVERLAPPED overlapped,
return FALSE;
}
assert(wait_result == WAIT_OBJECT_0);
TR_ASSERT(wait_result == WAIT_OBJECT_0);
return GetOverlappedResult(handle, overlapped, bytes_transferred, FALSE);
}
@ -166,9 +166,9 @@ static void tr_watchdir_win32_on_event(struct bufferevent* event, void* context)
size_t const nleft = ev->NextEntryOffset - nread;
assert(ev->FileNameLength % sizeof(WCHAR) == 0);
assert(ev->FileNameLength > 0);
assert(ev->FileNameLength <= nleft);
TR_ASSERT(ev->FileNameLength % sizeof(WCHAR) == 0);
TR_ASSERT(ev->FileNameLength > 0);
TR_ASSERT(ev->FileNameLength <= nleft);
if (nleft > name_size)
{
@ -214,7 +214,7 @@ static void tr_watchdir_win32_free(tr_watchdir_backend* backend_base)
return;
}
assert(backend->base.free_func == &tr_watchdir_win32_free);
TR_ASSERT(backend->base.free_func == &tr_watchdir_win32_free);
if (backend->fd != INVALID_HANDLE_VALUE)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <string.h> /* strcmp() */
#include <event2/event.h>
@ -20,6 +19,7 @@
#include "file.h"
#include "log.h"
#include "ptrarray.h"
#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
@ -105,7 +105,7 @@ static tr_watchdir_status tr_watchdir_process_impl(tr_watchdir_t handle, char co
tr_watchdir_status const ret = (*handle->callback)(handle, name, handle->callback_user_data);
assert(ret == TR_WATCHDIR_ACCEPT || ret == TR_WATCHDIR_IGNORE || ret == TR_WATCHDIR_RETRY);
TR_ASSERT(ret == TR_WATCHDIR_ACCEPT || ret == TR_WATCHDIR_IGNORE || ret == TR_WATCHDIR_RETRY);
log_debug("Callback decided to %s file \"%s\"", watchdir_status_to_string(ret), name);
@ -146,7 +146,7 @@ static void tr_watchdir_retry_free(tr_watchdir_retry* retry);
static void tr_watchdir_on_retry_timer(evutil_socket_t fd UNUSED, short type UNUSED, void* context)
{
assert(context != NULL);
TR_ASSERT(context != NULL);
tr_watchdir_retry* const retry = context;
tr_watchdir_t const handle = retry->handle;
@ -208,7 +208,7 @@ static void tr_watchdir_retry_free(tr_watchdir_retry* retry)
static void tr_watchdir_retry_restart(tr_watchdir_retry* retry)
{
assert(retry != NULL);
TR_ASSERT(retry != NULL);
evtimer_del(retry->timer);
@ -276,7 +276,7 @@ tr_watchdir_t tr_watchdir_new(char const* path, tr_watchdir_cb callback, void* c
}
else
{
assert(handle->backend->free_func != NULL);
TR_ASSERT(handle->backend->free_func != NULL);
}
return handle;
@ -302,19 +302,19 @@ void tr_watchdir_free(tr_watchdir_t handle)
char const* tr_watchdir_get_path(tr_watchdir_t handle)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
return handle->path;
}
tr_watchdir_backend* tr_watchdir_get_backend(tr_watchdir_t handle)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
return handle->backend;
}
struct event_base* tr_watchdir_get_event_base(tr_watchdir_t handle)
{
assert(handle != NULL);
TR_ASSERT(handle != NULL);
return handle->event_base;
}
@ -327,7 +327,7 @@ void tr_watchdir_process(tr_watchdir_t handle, char const* name)
tr_watchdir_retry const search_key = { .name = (char*)name };
tr_watchdir_retry* existing_retry;
assert(handle != NULL);
TR_ASSERT(handle != NULL);
if ((existing_retry = tr_watchdir_retries_find(&handle->active_retries, &search_key)) != NULL)
{

View File

@ -6,7 +6,6 @@
*
*/
#include <assert.h>
#include <string.h> /* strlen(), strstr() */
#ifdef _WIN32
@ -27,6 +26,7 @@
#include "torrent.h"
#include "platform.h" /* mutex */
#include "session.h"
#include "tr-assert.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
#include "version.h" /* User-Agent */
@ -506,7 +506,7 @@ static void tr_webThreadFunc(void* vsession)
long req_bytes_sent;
CURL* e = msg->easy_handle;
curl_easy_getinfo(e, CURLINFO_PRIVATE, (void*)&task);
assert(e == task->curl_easy);
TR_ASSERT(e == task->curl_easy);
curl_easy_getinfo(e, CURLINFO_RESPONSE_CODE, &task->code);
curl_easy_getinfo(e, CURLINFO_REQUEST_SIZE, &req_bytes_sent);
curl_easy_getinfo(e, CURLINFO_TOTAL_TIME, &total_time);