mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Add -Wfloat-conversion for GCC >= 4.9
This caught quite a few minor issues in our unit tests and elsewhere in our code.
This commit is contained in:
parent
2ff20c93a5
commit
493499a339
@ -1768,6 +1768,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
|
||||
|
||||
if test "x$have_gcc49" = "xyes"; then
|
||||
CFLAGS="$CFLAGS -Wdate-time"
|
||||
CFLAGS="$CFLAGS -Wfloat-conversion"
|
||||
fi
|
||||
|
||||
if test "x$have_gcc5" = "xyes"; then
|
||||
|
@ -5530,7 +5530,7 @@ clamp_double_to_int64(double number)
|
||||
* representable integer for which this is not the case is INT64_MIN, but
|
||||
* it is covered by the logic below. */
|
||||
if (isfinite(number) && exp <= 63) {
|
||||
return number;
|
||||
return (int64_t)number;
|
||||
}
|
||||
|
||||
/* Handle infinities and finite numbers with magnitude >= 2^63. */
|
||||
|
@ -4525,7 +4525,7 @@ channel_update_xmit_queue_size(channel_t *chan)
|
||||
if (chan->get_overhead_estimate) {
|
||||
overhead = chan->get_overhead_estimate(chan);
|
||||
if (overhead >= 1.0f) {
|
||||
queued *= overhead;
|
||||
queued = (uint64_t)(queued * overhead);
|
||||
} else {
|
||||
/* Ignore silly overhead factors */
|
||||
log_notice(LD_CHANNEL, "Ignoring silly overhead factor %f", overhead);
|
||||
|
@ -5782,7 +5782,7 @@ parse_dir_authority_line(const char *line, dirinfo_type_t required_type,
|
||||
} else if (!strcmpstart(flag, "weight=")) {
|
||||
int ok;
|
||||
const char *wstring = flag + strlen("weight=");
|
||||
weight = tor_parse_double(wstring, 0, UINT64_MAX, &ok, NULL);
|
||||
weight = tor_parse_double(wstring, 0, (double)UINT64_MAX, &ok, NULL);
|
||||
if (!ok) {
|
||||
log_warn(LD_CONFIG, "Invalid weight '%s' on DirAuthority line.",flag);
|
||||
weight=1.0;
|
||||
@ -5926,7 +5926,7 @@ parse_dir_fallback_line(const char *line,
|
||||
} else if (!strcmpstart(cp, "weight=")) {
|
||||
int ok;
|
||||
const char *wstring = cp + strlen("weight=");
|
||||
weight = tor_parse_double(wstring, 0, UINT64_MAX, &ok, NULL);
|
||||
weight = tor_parse_double(wstring, 0, (double)UINT64_MAX, &ok, NULL);
|
||||
if (!ok) {
|
||||
log_warn(LD_CONFIG, "Invalid weight '%s' on FallbackDir line.", cp);
|
||||
weight=1.0;
|
||||
|
@ -1238,7 +1238,7 @@ config_parse_units(const char *val, struct unit_table_t *u, int *ok)
|
||||
|
||||
v = tor_parse_uint64(val, 10, 0, UINT64_MAX, ok, &cp);
|
||||
if (!*ok || (cp && *cp == '.')) {
|
||||
d = tor_parse_double(val, 0, UINT64_MAX, ok, &cp);
|
||||
d = tor_parse_double(val, 0, (double)UINT64_MAX, ok, &cp);
|
||||
if (!*ok)
|
||||
goto done;
|
||||
use_float = 1;
|
||||
@ -1255,7 +1255,7 @@ config_parse_units(const char *val, struct unit_table_t *u, int *ok)
|
||||
for ( ;u->unit;++u) {
|
||||
if (!strcasecmp(u->unit, cp)) {
|
||||
if (use_float)
|
||||
v = u->multiplier * d;
|
||||
v = (uint64_t)(u->multiplier * d);
|
||||
else
|
||||
v *= u->multiplier;
|
||||
*ok = 1;
|
||||
|
@ -2178,7 +2178,7 @@ scale_array_elements_to_u64(uint64_t *entries_out, const double *entries_in,
|
||||
double scale_factor = 0.0;
|
||||
int i;
|
||||
/* big, but far away from overflowing an int64_t */
|
||||
#define SCALE_TO_U64_MAX ((int64_t) (INT64_MAX / 4))
|
||||
#define SCALE_TO_U64_MAX ((double) (INT64_MAX / 4))
|
||||
|
||||
for (i = 0; i < n_entries; ++i)
|
||||
total += entries_in[i];
|
||||
|
@ -185,7 +185,7 @@ test_channeltls_overhead_estimate(void *arg)
|
||||
const char test_digest[DIGEST_LEN] = {
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
|
||||
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14 };
|
||||
float r;
|
||||
double r;
|
||||
channel_tls_t *tlschan = NULL;
|
||||
|
||||
(void)arg;
|
||||
@ -212,25 +212,25 @@ test_channeltls_overhead_estimate(void *arg)
|
||||
tlschan->conn->bytes_xmitted = 128;
|
||||
tlschan->conn->bytes_xmitted_by_tls = 64;
|
||||
r = ch->get_overhead_estimate(ch);
|
||||
tt_assert(fabsf(r - 1.0f) < 1E-12);
|
||||
tt_assert(fabs(r - 1.0f) < 1E-12);
|
||||
|
||||
tlschan->conn->bytes_xmitted_by_tls = 127;
|
||||
r = ch->get_overhead_estimate(ch);
|
||||
tt_assert(fabsf(r - 1.0f) < 1E-12);
|
||||
tt_assert(fabs(r - 1.0f) < 1E-12);
|
||||
|
||||
/* Now middle of the range */
|
||||
tlschan->conn->bytes_xmitted_by_tls = 192;
|
||||
r = ch->get_overhead_estimate(ch);
|
||||
tt_assert(fabsf(r - 1.5f) < 1E-12);
|
||||
tt_assert(fabs(r - 1.5f) < 1E-12);
|
||||
|
||||
/* Now above the 2.0f clamp */
|
||||
tlschan->conn->bytes_xmitted_by_tls = 257;
|
||||
r = ch->get_overhead_estimate(ch);
|
||||
tt_assert(fabsf(r - 2.0f) < 1E-12);
|
||||
tt_assert(fabs(r - 2.0f) < 1E-12);
|
||||
|
||||
tlschan->conn->bytes_xmitted_by_tls = 512;
|
||||
r = ch->get_overhead_estimate(ch);
|
||||
tt_assert(fabsf(r - 2.0f) < 1E-12);
|
||||
tt_assert(fabs(r - 2.0f) < 1E-12);
|
||||
|
||||
done:
|
||||
if (ch) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||
@ -1194,17 +1195,17 @@ test_tortls_get_write_overhead_ratio(void *ignored)
|
||||
|
||||
total_bytes_written_over_tls = 0;
|
||||
ret = tls_get_write_overhead_ratio();
|
||||
tt_int_op(ret, OP_EQ, 1.0);
|
||||
tt_double_op(fabs(ret - 1.0), OP_LT, 1E-12);
|
||||
|
||||
total_bytes_written_by_tls = 10;
|
||||
total_bytes_written_over_tls = 1;
|
||||
ret = tls_get_write_overhead_ratio();
|
||||
tt_int_op(ret, OP_EQ, 10.0);
|
||||
tt_double_op(fabs(ret - 10.0), OP_LT, 1E-12);
|
||||
|
||||
total_bytes_written_by_tls = 10;
|
||||
total_bytes_written_over_tls = 2;
|
||||
ret = tls_get_write_overhead_ratio();
|
||||
tt_int_op(ret, OP_EQ, 5.0);
|
||||
tt_double_op(fabs(ret - 5.0), OP_LT, 1E-12);
|
||||
|
||||
done:
|
||||
(void)0;
|
||||
|
@ -1472,24 +1472,24 @@ test_util_strmisc(void *arg)
|
||||
|
||||
{
|
||||
/* Test parse_double */
|
||||
double d = tor_parse_double("10", 0, UINT64_MAX,&i,NULL);
|
||||
double d = tor_parse_double("10", 0, (double)UINT64_MAX,&i,NULL);
|
||||
tt_int_op(1,OP_EQ, i);
|
||||
tt_assert(DBL_TO_U64(d) == 10);
|
||||
d = tor_parse_double("0", 0, UINT64_MAX,&i,NULL);
|
||||
d = tor_parse_double("0", 0, (double)UINT64_MAX,&i,NULL);
|
||||
tt_int_op(1,OP_EQ, i);
|
||||
tt_assert(DBL_TO_U64(d) == 0);
|
||||
d = tor_parse_double(" ", 0, UINT64_MAX,&i,NULL);
|
||||
d = tor_parse_double(" ", 0, (double)UINT64_MAX,&i,NULL);
|
||||
tt_int_op(0,OP_EQ, i);
|
||||
d = tor_parse_double(".0a", 0, UINT64_MAX,&i,NULL);
|
||||
d = tor_parse_double(".0a", 0, (double)UINT64_MAX,&i,NULL);
|
||||
tt_int_op(0,OP_EQ, i);
|
||||
d = tor_parse_double(".0a", 0, UINT64_MAX,&i,&cp);
|
||||
d = tor_parse_double(".0a", 0, (double)UINT64_MAX,&i,&cp);
|
||||
tt_int_op(1,OP_EQ, i);
|
||||
d = tor_parse_double("-.0", 0, UINT64_MAX,&i,NULL);
|
||||
d = tor_parse_double("-.0", 0, (double)UINT64_MAX,&i,NULL);
|
||||
tt_int_op(1,OP_EQ, i);
|
||||
tt_assert(DBL_TO_U64(d) == 0);
|
||||
d = tor_parse_double("-10", -100.0, 100.0,&i,NULL);
|
||||
tt_int_op(1,OP_EQ, i);
|
||||
tt_int_op(-10.0,OP_EQ, d);
|
||||
tt_double_op(fabs(d - -10.0),OP_LT, 1E-12);
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user