mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-08 08:58:00 +00:00
New wrapper macro for printf("%zu"), for old VS compat.
A user reports that Visual Studio 2013 and earlier have printf
implementations in their C library that don't support the 'z' modifier
to indicate that an integer argument is size_t. The 'I' modifier
apparently works in place of it.
To avoid littering ifdefs everywhere, I've invented my own inttypes.h
style macros to wrap size_t formatting directives, which are defined
to %zu and %zx normally, or %Iu and %Ix in old-VS mode. Those are in
defs.h, and they're used everywhere that a %z might otherwise get into
the Windows build.
(cherry picked from commit 82a7e8c4ac
)
This commit is contained in:
parent
cb671ec2d8
commit
8453b9239c
7
defs.h
7
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 <inttypes.h>
|
||||
/* 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__
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
4
sshrsa.c
4
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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
4
testsc.c
4
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;
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user