diff --git a/src/common/compat.h b/src/common/compat.h index 60fb1cb652..3b58bff8c4 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -196,10 +196,16 @@ size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2)); #define U64_SCANF_ARG(a) (a) /** Expands to a literal uint64_t-typed constant for the value n. */ #define U64_LITERAL(n) (n ## ui64) +#define I64_PRINTF_ARG(a) (a) +#define I64_SCANF_ARG(a) (a) +#define I64_LITERAL(n) (n ## i64) #else #define U64_PRINTF_ARG(a) ((long long unsigned int)(a)) #define U64_SCANF_ARG(a) ((long long unsigned int*)(a)) #define U64_LITERAL(n) (n ## llu) +#define I64_PRINTF_ARG(a) ((long long signed int)(a)) +#define I64_SCANF_ARG(a) ((long long signed int*)(a)) +#define I64_LITERAL(n) (n ## ll) #endif #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) diff --git a/src/or/dirvote.c b/src/or/dirvote.c index 8643ef367d..505af38cfc 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -756,7 +756,9 @@ out: log_info(LD_DIR, "Bw weight mismatch %d. G="I64_FORMAT" M="I64_FORMAT " E="I64_FORMAT" D="I64_FORMAT" T="I64_FORMAT, - berr, G, M, E, D, T); + berr, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); } return berr; @@ -778,7 +780,8 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M, log_warn(LD_DIR, "Consensus with empty bandwidth: " "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT " D="I64_FORMAT" T="I64_FORMAT, - G, M, E, D, T); + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); return; } @@ -817,7 +820,9 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M, log_warn(LD_DIR, "Bw Weights error %d for case %s. " "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT " D="I64_FORMAT" T="I64_FORMAT, - berr, casename, G, M, E, D, T); + berr, casename, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); } } else if (3*E < T && 3*G < T) { // E < T/3 && G < T/3 int64_t R = MIN(E, G); @@ -876,7 +881,9 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M, log_warn(LD_DIR, "Bw Weights error %d for case %s. " "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT " D="I64_FORMAT" T="I64_FORMAT, - berr, casename, G, M, E, D, T); + berr, casename, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); } } } else { // if (E < T/3 || G < T/3) { @@ -886,7 +893,8 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M, log_warn(LD_BUG, "Bw-Weights Case 3 but with G="I64_FORMAT" M=" I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT" T="I64_FORMAT, - G, M, E, D, T); + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); } if (3*(S+D) < T) { // Subcase a: S+D < T/3 @@ -941,7 +949,9 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M, log_warn(LD_DIR, "Bw Weights error %d for case %s. " "G="I64_FORMAT" M="I64_FORMAT " E="I64_FORMAT" D="I64_FORMAT" T="I64_FORMAT, - berr, casename, G, M, E, D, T); + berr, casename, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); } } } @@ -955,49 +965,64 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M, log_warn(LD_DIR, "Bw %s: Wgg="I64_FORMAT"! G="I64_FORMAT " M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, Wgg, G, M, E, D, T); + casename, I64_PRINTF_ARG(Wgg), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); + Wgg = MAX(MIN(Wgg, weight_scale), 0); } if (Wgd < 0 || Wgd > weight_scale) { log_warn(LD_DIR, "Bw %s: Wgd="I64_FORMAT"! G="I64_FORMAT " M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, Wgd, G, M, E, D, T); + casename, I64_PRINTF_ARG(Wgd), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); Wgd = MAX(MIN(Wgd, weight_scale), 0); } if (Wmg < 0 || Wmg > weight_scale) { log_warn(LD_DIR, "Bw %s: Wmg="I64_FORMAT"! G="I64_FORMAT " M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, Wmg, G, M, E, D, T); + casename, I64_PRINTF_ARG(Wmg), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); Wmg = MAX(MIN(Wmg, weight_scale), 0); } if (Wme < 0 || Wme > weight_scale) { log_warn(LD_DIR, "Bw %s: Wme="I64_FORMAT"! G="I64_FORMAT " M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, Wme, G, M, E, D, T); + casename, I64_PRINTF_ARG(Wme), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); Wme = MAX(MIN(Wme, weight_scale), 0); } if (Wmd < 0 || Wmd > weight_scale) { log_warn(LD_DIR, "Bw %s: Wmd="I64_FORMAT"! G="I64_FORMAT " M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, Wmd, G, M, E, D, T); + casename, I64_PRINTF_ARG(Wmd), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); Wmd = MAX(MIN(Wmd, weight_scale), 0); } if (Wee < 0 || Wee > weight_scale) { log_warn(LD_DIR, "Bw %s: Wee="I64_FORMAT"! G="I64_FORMAT " M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, Wee, G, M, E, D, T); + casename, I64_PRINTF_ARG(Wee), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); Wee = MAX(MIN(Wee, weight_scale), 0); } if (Wed < 0 || Wed > weight_scale) { log_warn(LD_DIR, "Bw %s: Wed="I64_FORMAT"! G="I64_FORMAT " M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, Wed, G, M, E, D, T); + casename, I64_PRINTF_ARG(Wed), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); Wed = MAX(MIN(Wed, weight_scale), 0); } @@ -1031,7 +1056,9 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M, log_notice(LD_CIRC, "Computed bandwidth weights for %s: " "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT, - casename, G, M, E, D, T); + casename, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T)); } /** Given a list of vote networkstatus_t in votes, our public diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 082bf2ef0c..9e197c4377 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -2373,7 +2373,7 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) // We use > 1 as the check for these because they are computed as integers. // Sometimes there are rounding errors. if (fabs(Wmm - weight_scale) > 1) { - log_warn(LD_BUG, "Wmm=%lf != "I64_FORMAT, Wmm, weight_scale); + log_warn(LD_BUG, "Wmm=%lf != "I64_FORMAT, Wmm, I64_PRINTF_ARG(weight_scale)); valid = 0; } @@ -2394,19 +2394,19 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) if (fabs(Wgg + Wmg - weight_scale) > 0.001*weight_scale) { log_warn(LD_BUG, "Wgg=%lf != "I64_FORMAT" - Wmg=%lf", Wgg, - weight_scale, Wmg); + I64_PRINTF_ARG(weight_scale), Wmg); valid = 0; } if (fabs(Wee + Wme - weight_scale) > 0.001*weight_scale) { log_warn(LD_BUG, "Wee=%lf != "I64_FORMAT" - Wme=%lf", Wee, - weight_scale, Wme); + I64_PRINTF_ARG(weight_scale), Wme); valid = 0; } if (fabs(Wgd + Wmd + Wed - weight_scale) > 0.001*weight_scale) { log_warn(LD_BUG, "Wgd=%lf + Wmd=%lf + Wed=%lf != "I64_FORMAT, - Wgd, Wmd, Wed, weight_scale); + Wgd, Wmd, Wed, I64_PRINTF_ARG(weight_scale)); valid = 0; } @@ -2464,7 +2464,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Etotal, Mtotal, G, M, E, D, T, + casename, Etotal, Mtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2474,7 +2476,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Etotal, Gtotal, G, M, E, D, T, + casename, Etotal, Gtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2484,7 +2488,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Mtotal, Gtotal, G, M, E, D, T, + casename, Mtotal, Gtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2514,7 +2520,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Rtotal, Stotal, G, M, E, D, T, + casename, Rtotal, Stotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2525,7 +2533,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) I64_FORMAT". G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT " D="I64_FORMAT" T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Rtotal*3, T, G, M, E, D, T, + casename, Rtotal*3, I64_PRINTF_ARG(T), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2536,7 +2546,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) I64_FORMAT". G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT " D="I64_FORMAT" T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Stotal*3, T, G, M, E, D, T, + casename, Stotal*3, I64_PRINTF_ARG(T), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2548,7 +2560,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Mtotal*3, T, G, M, E, D, T, + casename, Mtotal*3, I64_PRINTF_ARG(T), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2564,7 +2578,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Etotal, Mtotal, G, M, E, D, T, + casename, Etotal, Mtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2574,7 +2590,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Etotal, Gtotal, G, M, E, D, T, + casename, Etotal, Gtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2584,7 +2602,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Mtotal, Gtotal, G, M, E, D, T, + casename, Mtotal, Gtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2595,7 +2615,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Etotal, Gtotal, G, M, E, D, T, + casename, Etotal, Gtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2623,7 +2645,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) I64_FORMAT". G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT " D="I64_FORMAT" T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Stotal*3, T, G, M, E, D, T, + casename, Stotal*3, I64_PRINTF_ARG(T), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2634,7 +2658,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, NStotal, Mtotal, G, M, E, D, T, + casename, NStotal, Mtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2646,7 +2672,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) I64_FORMAT". G="I64_FORMAT" M="I64_FORMAT " E="I64_FORMAT" D="I64_FORMAT" T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, NStotal*3, T, G, M, E, D, T, + casename, NStotal*3, I64_PRINTF_ARG(T), + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2659,7 +2687,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Etotal, Mtotal, G, M, E, D, T, + casename, Etotal, Mtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2669,7 +2699,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Etotal, Gtotal, G, M, E, D, T, + casename, Etotal, Gtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; } @@ -2679,7 +2711,9 @@ networkstatus_verify_bw_weights(networkstatus_t *ns) "G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT " T="I64_FORMAT". " "Wgg=%lf Wgd=%lf Wmg=%lf Wme=%lf Wmd=%lf Wee=%lf Wed=%lf", - casename, Mtotal, Gtotal, G, M, E, D, T, + casename, Mtotal, Gtotal, + I64_PRINTF_ARG(G), I64_PRINTF_ARG(M), I64_PRINTF_ARG(E), + I64_PRINTF_ARG(D), I64_PRINTF_ARG(T), Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed); valid = 0; }