]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix clang-6.0 build on FreeBSD 12 [-Wformat] (#577)
authorFrancesco Chemolli <kinkie@squid-cache.org>
Sat, 28 Mar 2020 14:09:19 +0000 (14:09 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sat, 28 Mar 2020 21:51:19 +0000 (21:51 +0000)
Cast and print std::chrono:nanoseconds::count() as intmax_t because its
actual type might be larger than the 64 bytes expected by %PRId64.

The problem was not, technically, specific to clang or FreeBSD.

The error message says "long" because %PRId64 is %ld on platforms where
"long" is 64 bits:

    format specifies type 'long' but the argument has type [...]
    'long long' [-Wformat]

src/cache_cf.cc

index 7a02b8cb83958e1c13711d8d35f2d416169ca98a..6d168721c059bc9d341260cc6b25561f9ccb995f 100644 (file)
@@ -3072,7 +3072,8 @@ free_time_msec(time_msec_t * var)
 static void
 dump_time_nanoseconds(StoreEntry *entry, const char *name, const std::chrono::nanoseconds &var)
 {
-    storeAppendPrintf(entry, "%s %" PRId64 " nanoseconds\n", name, var.count());
+    // std::chrono::nanoseconds::rep is unknown a priori so we cast to (and print) the largest supported integer
+    storeAppendPrintf(entry, "%s %jd nanoseconds\n", name, static_cast<intmax_t>(var.count()));
 }
 
 static void