diff --git a/defs.h b/defs.h index 0a4f08c8..b9577036 100644 --- a/defs.h +++ b/defs.h @@ -22,9 +22,16 @@ #define PRIdMAX "I64d" #define PRIXMAX "I64X" #define SCNu64 "I64u" +#define SIZEx "Ix" +#define SIZEu "Iu" uintmax_t strtoumax(const char *nptr, char **endptr, int base); #else #include +/* Because we still support older MSVC libraries which don't recognise the + * standard C "z" modifier for size_t-sized integers, we must use an + * inttypes.h-style macro for those */ +#define SIZEx "zx" +#define SIZEu "zu" #endif #if defined __GNUC__ || defined __clang__ diff --git a/logging.c b/logging.c index d61038c9..a12caa5a 100644 --- a/logging.c +++ b/logging.c @@ -344,7 +344,7 @@ void log_packet(LogContext *ctx, int direction, int type, /* If we're about to stop omitting, it's time to say how * much we omitted. */ if ((blktype != PKTLOG_OMIT) && omitted) { - logprintf(ctx, " (%zu byte%s omitted)\r\n", + logprintf(ctx, " (%"SIZEu" byte%s omitted)\r\n", omitted, (omitted==1?"":"s")); omitted = 0; } @@ -352,7 +352,8 @@ void log_packet(LogContext *ctx, int direction, int type, /* (Re-)initialise dumpdata as necessary * (start of row, or if we've just stopped omitting) */ if (!output_pos && !omitted) - sprintf(dumpdata, " %08zx%*s\r\n", p-(p%16), 1+3*16+2+16, ""); + sprintf(dumpdata, " %08"SIZEx"%*s\r\n", + p-(p%16), 1+3*16+2+16, ""); /* Deal with the current byte. */ if (blktype == PKTLOG_OMIT) { @@ -387,7 +388,7 @@ void log_packet(LogContext *ctx, int direction, int type, /* Tidy up */ if (omitted) - logprintf(ctx, " (%zu byte%s omitted)\r\n", + logprintf(ctx, " (%"SIZEu" byte%s omitted)\r\n", omitted, (omitted==1?"":"s")); logflush(ctx); } diff --git a/sshprng.c b/sshprng.c index ea40c99f..e333e836 100644 --- a/sshprng.c +++ b/sshprng.c @@ -177,7 +177,7 @@ static void prng_seed_BinarySink_write( prng *pr = BinarySink_DOWNCAST(bs, prng); prng_impl *pi = container_of(pr, prng_impl, Prng); assert(pi->keymaker); - prngdebug("prng: got %zu bytes of seed\n", len); + prngdebug("prng: got %"SIZEu" bytes of seed\n", len); put_data(pi->keymaker, data, len); } @@ -228,7 +228,7 @@ void prng_read(prng *pr, void *vout, size_t size) assert(!pi->keymaker); - prngdebug("prng_read %zu\n", size); + prngdebug("prng_read %"SIZEu"\n", size); uint8_t *out = (uint8_t *)vout; for (; size > 0; size--) { @@ -256,7 +256,7 @@ void prng_add_entropy(prng *pr, unsigned source_id, ptrlen data) index++; } - prngdebug("prng_add_entropy source=%u size=%zu -> collector %zi\n", + prngdebug("prng_add_entropy source=%u size=%"SIZEu" -> collector %zi\n", source_id, data.len, index); put_datapl(pi->collectors[index], data); @@ -272,7 +272,7 @@ void prng_add_entropy(prng *pr, unsigned source_id, ptrlen data) uint32_t reseed_index = ++pi->reseeds; prngdebug("prng entropy reseed #%"PRIu32"\n", reseed_index); for (size_t i = 0; i < NCOLLECTORS; i++) { - prngdebug("emptying collector %zu\n", i); + prngdebug("emptying collector %"SIZEu"\n", i); ssh_hash_final(pi->collectors[i], pi->pending_output); put_data(&pi->Prng, pi->pending_output, pi->hashalg->hlen); pi->collectors[i] = ssh_hash_new(pi->hashalg); diff --git a/sshpubk.c b/sshpubk.c index c9423192..6ad84788 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -1362,8 +1362,8 @@ char *ssh1_pubkey_str(RSAKey *key) dec1 = mp_get_decimal(key->exponent); dec2 = mp_get_decimal(key->modulus); - buffer = dupprintf("%zd %s %s%s%s", mp_get_nbits(key->modulus), dec1, dec2, - key->comment ? " " : "", + buffer = dupprintf("%"SIZEu" %s %s%s%s", mp_get_nbits(key->modulus), + dec1, dec2, key->comment ? " " : "", key->comment ? key->comment : ""); sfree(dec1); sfree(dec2); diff --git a/sshrsa.c b/sshrsa.c index 504a73e7..23330620 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -296,7 +296,7 @@ char *rsa_ssh1_fingerprint(RSAKey *key) ssh_hash_final(hash, digest); out = strbuf_new(); - strbuf_catf(out, "%zu ", mp_get_nbits(key->modulus)); + strbuf_catf(out, "%"SIZEu" ", mp_get_nbits(key->modulus)); for (i = 0; i < 16; i++) strbuf_catf(out, "%s%02x", i ? ":" : "", digest[i]); if (key->comment) @@ -779,7 +779,7 @@ char *rsa2_invalid(ssh_key *key, unsigned flags) const ssh_hashalg *halg = rsa2_hash_alg_for_flags(flags, &sign_alg_name); if (nbytes < rsa_pkcs1_length_of_fixed_parts(halg)) { return dupprintf( - "%zu-bit RSA key is too short to generate %s signatures", + "%"SIZEu"-bit RSA key is too short to generate %s signatures", bits, sign_alg_name); } diff --git a/testcrypt.c b/testcrypt.c index c92311f4..aa41a7a5 100644 --- a/testcrypt.c +++ b/testcrypt.c @@ -1115,7 +1115,7 @@ int main(int argc, char **argv) for (size_t i = 0; i < sb->len; i++) if (sb->s[i] == '\n') lines++; - fprintf(outfp, "%zu\n%s", lines, sb->s); + fprintf(outfp, "%"SIZEu"\n%s", lines, sb->s); fflush(outfp); strbuf_free(sb); sfree(line); diff --git a/testsc.c b/testsc.c index 760a9482..7127032e 100644 --- a/testsc.c +++ b/testsc.c @@ -160,7 +160,7 @@ VOLATILE_WRAPPED_DEFN(, void, log_to_file, (const char *filename)) static const char *outdir = NULL; char *log_filename(const char *basename, size_t index) { - return dupprintf("%s/%s.%04zu", outdir, basename, index); + return dupprintf("%s/%s.%04"SIZEu, outdir, basename, index); } static char *last_filename; @@ -1574,7 +1574,7 @@ int main(int argc, char **argv) printf("All tests passed\n"); return 0; } else { - printf("%zu tests failed\n", nrun - npass); + printf("%"SIZEu" tests failed\n", nrun - npass); return 1; } } diff --git a/windows/winpgnt.c b/windows/winpgnt.c index 4374f2fe..4c4ec6af 100644 --- a/windows/winpgnt.c +++ b/windows/winpgnt.c @@ -884,7 +884,7 @@ static char *answer_filemapping_message(const char *mapname) mapsize = mbi.RegionSize; } #ifdef DEBUG_IPC - debug("region size = %zd\n", mapsize); + debug("region size = %"SIZEu"\n", mapsize); #endif if (mapsize < 5) { err = dupstr("mapping smaller than smallest possible request");