Commit Graph

662 Commits

Author SHA1 Message Date
Charles Kerr 19e52d8b9a
chore: sonarcloud warnings 2 (#1496)
* fix "merge nested if" sonarcloud warnings

* fix explicit constructor warnings in qt client
2020-11-01 15:47:57 -06:00
Charles Kerr a4dd67ae45
chore: fix some fixmes (#1449)
* chore: remove assertions that were flagged for removal

* chore: remove unneeded check

* refactor: move tr_peerIoAddrStr to net.h

* refactor: formatter API now takes size_t args

* chore: remove out-of-date FIXME comment

* refactor: cleanup logging win32 ifdefs
2020-09-13 16:43:29 -05:00
Charles Kerr efaa66a920
fix: resolve some lgtm warnings (#1444)
* fix: warnings found by LGTM static analyzer
2020-09-11 16:07:45 -05:00
Charles Kerr d3323ddee0
fix: Coverity warnings (#1443)
* fix: coverity warnings
2020-09-10 18:50:46 -05:00
Mike Gelfand b7a8bd45b7 Reformat affected code after recent changes 2020-08-18 20:31:06 +03:00
Mike Gelfand ff8d0dbf3b Switch from UNUSED macro to TR_UNUSED macro
Since there is no way to mark parameters as [potentially] unused in
standard C and when using MSVC compiler, use the widely accepted
cast-to-void approach instead.
2020-08-18 14:19:55 +03:00
Charles Kerr 677dc73eac
refactor: use GTest for running tests (#1383)
* refactor: use google-test on libtransmission tests
2020-08-11 13:11:55 -05:00
Charles Kerr fa6df52d58
chore: remove unused methods (#1207)
* chore: remove unused methods in qt client

* chore: remove unused libtransmission methods

* chore: remove unused gtk methods

* chore: remove more unused libtransmission methods

* chore: remove more unused code found by @reardonia
2020-05-11 17:20:46 -05:00
Charles Kerr abac811dd2
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings

* fix: implicit fallthrough warning

* fixup! fix: implicit fallthrough warning

* fix: disable warnings for 3rd party code

Since we want to leave upstream code as-is

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: disable warnings for 3rd party code

* silence spurious alignment warning

Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: 90ac46f710/f/src/util/util_safealign.h (_35)

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: implicit fallthrough warning

* make uncrustify happy

* remove uncrustify-test.sh

that's probably off-topic for this PR

* fixup! fix: __attribute__(__printf__) warnings

* Update libtransmission/CMakeLists.txt

Co-Authored-By: ckerr <ckerr@github.com>

* fixup! silence spurious alignment warning

* use -w for DISABLE_WARNINGS in Clang

* refactor: fix libtransmission deprecation warnings

* fix: pthread_create's start_routine's return value

This was defined as `void` on non-Windows but should have been `void*`

* chore: uncrustify

* fix: add DISABLE_WARNINGS option for SunPro Studio

* fix "unused in lambda capture" warnings by clang++

* fix 'increases required alignment' warning

Caused from storing int16_t's in a char array.

* fix net.c 'increases required alignment' warning

The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.

* make building quieter so warnings are more visible

* fixup! fix 'increases required alignment' warning

* Fix -Wcast-function-type warnings in GTK+ app code

https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.

GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.

Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.

In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).

* fixup! fix "unused in lambda capture" warnings by clang++

* fixup! fix "unused in lambda capture" warnings by clang++

* fix two more libtransmission compiler warnings

* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 11:27:03 -06:00
Mike Gelfand 10cdd7f790 Use explicit boolean conversions 2019-07-14 16:25:07 +03:00
Mike Gelfand 17307e7484 Extract assignments from expression
Assignments explicitly enclosed in parentheses are ignored.

* MISRA C:2004, 13.1 - Assignment operators shall not be used in expressions
  that yield a Boolean value
* MISRA C++:2008, 6-2-1 - Assignment operators shall not be used in
  sub-expressions
* MISRA C:2012, 13.4 - The result of an assignment operator should not be used
* MITRE, CWE-481 - Assigning instead of Comparing
* CERT, EXP45-C. - Do not perform assignments in selection statements
* CERT, EXP51-J. - Do not perform assignments in conditional expressions
2019-03-17 08:00:15 +03:00
Mike Gelfand 1d6d946388 Fixup some formatting leftovers 2019-02-16 10:50:37 +03:00
Mike Gelfand 82df3a87f4 Update to Uncrustify 0.68.1
Tweak a few rules in the process. Now all code in cli, daemon, gtk,
libtransmission, qt, and utils is properly formatted with no manual
intervention.
2019-02-15 09:21:48 +03:00
Mike Gelfand 18aabdeb06 Introduce peer socket struct to improve readability 2017-06-28 18:50:05 +03:00
Mike Gelfand 13bbaeec76 Use field initializers for readability 2017-06-24 13:30:33 +03:00
Mike Gelfand deea6fc6a2 Bring assertions closer to the beginning of blocks 2017-06-13 07:44:09 +03:00
Mike Gelfand 98695fe3c1 Introduce our own assertion macros with finer control 2017-06-08 10:24:12 +03:00
Mike Gelfand f27596238d Include stdbool.h unconditionally
All the compilers should provide the header file by now. Remove `tr_isBool`
sanity checks along the way as compiler should guarantee that bool (_Bool)
values are 0 or 1 and nothing else.
2017-05-24 22:53:06 +03:00
Mike Gelfand 501be27972 Reduce code duplication in logging macros 2017-05-22 23:20:28 +03:00
Mike Gelfand 82722476aa Fix some issues reported by Coverity 2017-05-20 23:31:56 +03:00
Mike Gelfand 1e3d20422a Reduce for loop variables scope 2017-05-14 01:38:31 +03:00
Mike Gelfand 14370e5353 Fix a number of other style inconsistencies met along the way (part 2) 2017-05-01 18:47:49 +03:00
Mike Gelfand e1d53855f4 Avoid declaring multiple variables on the same line 2017-05-01 18:46:41 +03:00
Mike Gelfand fbd8d4c79f Fix a number of other style inconsistencies met along the way 2017-04-30 19:33:55 +03:00
Mike Gelfand a762c770f2 Make conditional expressions explicitly boolean 2017-04-30 19:26:01 +03:00
Mike Gelfand 4f9d9ad92b Code style change leftovers
For some reason, GTK client wasn't fully processed. All the rest of changes
are mostly in comments.
2017-04-21 10:40:57 +03:00
Mike Gelfand dadffa2c0f Align type qualifiers to the right (code style)
This way all the qualifiers (`const`, `volatile`, `mutable`) are grouped
together, e.g. `T const* const x` vs. `const T* const x`. Also helps reading
types right-to-left, e.g. "constant pointer to constant T" vs. "constant
pointer to T which is constant".
2017-04-20 19:53:20 +03:00
Mike Gelfand d7930984ef Adjust uncrustify config, reformat all but Mac client
There're places where manual intervention is still required as uncrustify
is not ideal (unfortunately), but at least one may rely on it to do the
right thing most of the time (e.g. when sending in a patch).

The style itself is quite different from what we had before but making it
uniform across all the codebase is the key. I also hope that it'll make the
code more readable (YMMV) and less sensitive to further changes.
2017-04-20 10:01:22 +03:00
Mike Gelfand 2248d3670f Get rid of $Id$ SVN keywords in source files 2016-09-02 23:10:15 +03:00
Mike Gelfand 13a98a02b8 Use `TR_BAD_SIZE` instead of -1 in `tr_quark_new()` calls
Extend quark test to improve branch coverage.
2016-01-07 19:20:14 +00:00
Mike Gelfand de304e8a35 #5407: In `tr_peerMgrGetDesiredAvailable()`, check if swarm is running (suggested by x190) 2015-12-31 14:33:02 +00:00
Mike Gelfand eb8fc35ac6 Remove useless checks and definitions (C99)
Now that MSVC support for C99 is quite good, remove previously needed but
now unused checks and definitions, like PRI* format macros (including
PRIdMAX and TR_PRIuSIZE, replaced with %jd and %zu) and inline macro.
Also, remove ssize_t typedef and replace few occurences with ev_ssize_t.
Also, remove check for stdbool.h availability (guaranteed by C99) and
include it unconditionally (except when in C++ mode).
2015-12-29 19:37:31 +00:00
Mike Gelfand 15c9e5c126 Get rid of some more warnings 2015-12-28 23:53:55 +00:00
Mike Gelfand e3c5ab74ed #5963: Fix two more places where int is used in boolean context 2015-12-27 15:19:03 +00:00
Jordan Lee b559a20029 const correctness
silence some qual-cast warnings by sprinkling more consts throughout,
e.g. casting a const void* to a const struct foo * const *
2015-12-06 22:13:10 +00:00
Mike Gelfand 2321bc3fad Fix some issues revealed by coverity 2015-05-09 08:37:55 +00:00
Mike Gelfand c768af3865 #5407: Fix crash on Mac when pausing torrents (patch by x190) 2015-03-26 18:32:33 +00:00
Mike Gelfand 949e02b933 Define and use tr_socket_t and TR_BAD_SOCKET instead of int and -1.
Test socket validity by comparing to TR_BAD_SOCKET instead of various
(and sometimes wrong) other tests like `x >= 0`, `x != -1`, `x > 0`,
`x > -1`, `x` (valid), and `x < 0`, `x == -1` (invalid).
2015-03-18 07:34:26 +00:00
Mike Gelfand 440f482d01 Replace tabs with spaces; remove trailing spaces 2015-01-02 11:15:31 +00:00
Mike Gelfand c845e35ce1 Fix format specifier warning introduced couple commits earlier 2014-12-13 17:04:14 +00:00
Mike Gelfand 52a9d774e4 Fix compilation on Windows
This should not affect non-Win32 platforms in any way.
As for Win32 (both MinGW and MSVC), this should hopefully allow for
unpatched compilation. Correct functioning is not yet guaranteed though.
2014-12-13 15:22:39 +00:00
Mike Gelfand 74c6719bb2 #5407: Fix crash on Mac when pausing torrents (patch by x190) 2014-12-11 19:57:52 +00:00
Mike Gelfand f6f7bf8227 #4400, #5462: Move random helpers to crypto-utils
On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing random numbers/data generation to crypto-utils.{c,h}. OpenSSL-
related functionality (generation of cryptographically strong random
data) is moved to crypto-utils-openssl.c.

Rename functions to follow currently accepted style:
* tr_cryptoRandBuf -> tr_rand_buffer
* tr_cryptoRandInt -> tr_rand_int
* tr_cryptoWeakRandInt -> tr_rand_int_weak

Fix rare case of invalid value being returned from tr_rand_int. Return
value for abs(INT_MIN) may be undefined and thus negative, and so
tr_rand_int will return negative value which is incorrect (out of
requested and expected range).
2014-12-04 11:27:38 +00:00
Mike Gelfand e30728367f #5771: Use true and false instead of 1 and 0 for bool variables (patch by ticamkq + additional fixes) 2014-11-30 19:38:47 +00:00
Jordan Lee b939f98ec7 (trunk, libT) #5709 'Fix an instance of time_t printing' -- fixed, patch by naddy 2014-07-03 19:28:21 +00:00
Jordan Lee 02cff80c2d Copyedit the license's revised text: (1) remove unnecessary repitition use of the word 'license' from the top of the header and source files (2) add the standard 'we hope it's useful, but no warranty' clause to COPYING (3) make explicit that linking OpenSSL is allowed (see https://people.gnome.org/~markmc/openssl-and-the-gpl.html for background) (4) sync the Qt and GTK+ clients' license popups with COPYING's revised text 2014-01-21 03:10:30 +00:00
Jordan Lee 4b9626bb83 Licensing changes:
1. add the option the code to be used under GPLv2 or GPLv3; previously only GPLv2 was allowed

2. add the "proxy option" as described in GPLv3 so we can add future licenses without having to bulk-edit everything again :)

3. remove the awkward "exception for MIT code in Mac client" clause; it was unnecessary and confusing.
2014-01-19 01:09:44 +00:00
Jordan Lee 4904b923fb (trunk) restore copyright year as suggested in email by rms 2014-01-18 20:56:57 +00:00
Jordan Lee 605e2e89ad use evutil_socket_t instead of int to define socket types. Patch my mikedLd :) 2013-09-08 17:03:11 +00:00
Jordan Lee 35638e210e add inline wrapper functions to tr_torrent to decouple the rest of the code from tr_completion 2013-08-18 13:06:39 +00:00