mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +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 PRIdMAX "I64d"
|
||||||
#define PRIXMAX "I64X"
|
#define PRIXMAX "I64X"
|
||||||
#define SCNu64 "I64u"
|
#define SCNu64 "I64u"
|
||||||
|
#define SIZEx "Ix"
|
||||||
|
#define SIZEu "Iu"
|
||||||
uintmax_t strtoumax(const char *nptr, char **endptr, int base);
|
uintmax_t strtoumax(const char *nptr, char **endptr, int base);
|
||||||
#else
|
#else
|
||||||
#include <inttypes.h>
|
#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
|
#endif
|
||||||
|
|
||||||
#if defined __GNUC__ || defined __clang__
|
#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
|
/* If we're about to stop omitting, it's time to say how
|
||||||
* much we omitted. */
|
* much we omitted. */
|
||||||
if ((blktype != PKTLOG_OMIT) && 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, (omitted==1?"":"s"));
|
||||||
omitted = 0;
|
omitted = 0;
|
||||||
}
|
}
|
||||||
@ -352,7 +352,8 @@ void log_packet(LogContext *ctx, int direction, int type,
|
|||||||
/* (Re-)initialise dumpdata as necessary
|
/* (Re-)initialise dumpdata as necessary
|
||||||
* (start of row, or if we've just stopped omitting) */
|
* (start of row, or if we've just stopped omitting) */
|
||||||
if (!output_pos && !omitted)
|
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. */
|
/* Deal with the current byte. */
|
||||||
if (blktype == PKTLOG_OMIT) {
|
if (blktype == PKTLOG_OMIT) {
|
||||||
@ -387,7 +388,7 @@ void log_packet(LogContext *ctx, int direction, int type,
|
|||||||
|
|
||||||
/* Tidy up */
|
/* Tidy up */
|
||||||
if (omitted)
|
if (omitted)
|
||||||
logprintf(ctx, " (%zu byte%s omitted)\r\n",
|
logprintf(ctx, " (%"SIZEu" byte%s omitted)\r\n",
|
||||||
omitted, (omitted==1?"":"s"));
|
omitted, (omitted==1?"":"s"));
|
||||||
logflush(ctx);
|
logflush(ctx);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ static void prng_seed_BinarySink_write(
|
|||||||
prng *pr = BinarySink_DOWNCAST(bs, prng);
|
prng *pr = BinarySink_DOWNCAST(bs, prng);
|
||||||
prng_impl *pi = container_of(pr, prng_impl, Prng);
|
prng_impl *pi = container_of(pr, prng_impl, Prng);
|
||||||
assert(pi->keymaker);
|
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);
|
put_data(pi->keymaker, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ void prng_read(prng *pr, void *vout, size_t size)
|
|||||||
|
|
||||||
assert(!pi->keymaker);
|
assert(!pi->keymaker);
|
||||||
|
|
||||||
prngdebug("prng_read %zu\n", size);
|
prngdebug("prng_read %"SIZEu"\n", size);
|
||||||
|
|
||||||
uint8_t *out = (uint8_t *)vout;
|
uint8_t *out = (uint8_t *)vout;
|
||||||
for (; size > 0; size--) {
|
for (; size > 0; size--) {
|
||||||
@ -256,7 +256,7 @@ void prng_add_entropy(prng *pr, unsigned source_id, ptrlen data)
|
|||||||
index++;
|
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);
|
source_id, data.len, index);
|
||||||
|
|
||||||
put_datapl(pi->collectors[index], data);
|
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;
|
uint32_t reseed_index = ++pi->reseeds;
|
||||||
prngdebug("prng entropy reseed #%"PRIu32"\n", reseed_index);
|
prngdebug("prng entropy reseed #%"PRIu32"\n", reseed_index);
|
||||||
for (size_t i = 0; i < NCOLLECTORS; i++) {
|
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);
|
ssh_hash_final(pi->collectors[i], pi->pending_output);
|
||||||
put_data(&pi->Prng, pi->pending_output, pi->hashalg->hlen);
|
put_data(&pi->Prng, pi->pending_output, pi->hashalg->hlen);
|
||||||
pi->collectors[i] = ssh_hash_new(pi->hashalg);
|
pi->collectors[i] = ssh_hash_new(pi->hashalg);
|
||||||
|
@ -1362,8 +1362,8 @@ char *ssh1_pubkey_str(RSAKey *key)
|
|||||||
|
|
||||||
dec1 = mp_get_decimal(key->exponent);
|
dec1 = mp_get_decimal(key->exponent);
|
||||||
dec2 = mp_get_decimal(key->modulus);
|
dec2 = mp_get_decimal(key->modulus);
|
||||||
buffer = dupprintf("%zd %s %s%s%s", mp_get_nbits(key->modulus), dec1, dec2,
|
buffer = dupprintf("%"SIZEu" %s %s%s%s", mp_get_nbits(key->modulus),
|
||||||
key->comment ? " " : "",
|
dec1, dec2, key->comment ? " " : "",
|
||||||
key->comment ? key->comment : "");
|
key->comment ? key->comment : "");
|
||||||
sfree(dec1);
|
sfree(dec1);
|
||||||
sfree(dec2);
|
sfree(dec2);
|
||||||
|
4
sshrsa.c
4
sshrsa.c
@ -296,7 +296,7 @@ char *rsa_ssh1_fingerprint(RSAKey *key)
|
|||||||
ssh_hash_final(hash, digest);
|
ssh_hash_final(hash, digest);
|
||||||
|
|
||||||
out = strbuf_new();
|
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++)
|
for (i = 0; i < 16; i++)
|
||||||
strbuf_catf(out, "%s%02x", i ? ":" : "", digest[i]);
|
strbuf_catf(out, "%s%02x", i ? ":" : "", digest[i]);
|
||||||
if (key->comment)
|
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);
|
const ssh_hashalg *halg = rsa2_hash_alg_for_flags(flags, &sign_alg_name);
|
||||||
if (nbytes < rsa_pkcs1_length_of_fixed_parts(halg)) {
|
if (nbytes < rsa_pkcs1_length_of_fixed_parts(halg)) {
|
||||||
return dupprintf(
|
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);
|
bits, sign_alg_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1115,7 +1115,7 @@ int main(int argc, char **argv)
|
|||||||
for (size_t i = 0; i < sb->len; i++)
|
for (size_t i = 0; i < sb->len; i++)
|
||||||
if (sb->s[i] == '\n')
|
if (sb->s[i] == '\n')
|
||||||
lines++;
|
lines++;
|
||||||
fprintf(outfp, "%zu\n%s", lines, sb->s);
|
fprintf(outfp, "%"SIZEu"\n%s", lines, sb->s);
|
||||||
fflush(outfp);
|
fflush(outfp);
|
||||||
strbuf_free(sb);
|
strbuf_free(sb);
|
||||||
sfree(line);
|
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;
|
static const char *outdir = NULL;
|
||||||
char *log_filename(const char *basename, size_t index)
|
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;
|
static char *last_filename;
|
||||||
@ -1574,7 +1574,7 @@ int main(int argc, char **argv)
|
|||||||
printf("All tests passed\n");
|
printf("All tests passed\n");
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
printf("%zu tests failed\n", nrun - npass);
|
printf("%"SIZEu" tests failed\n", nrun - npass);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -884,7 +884,7 @@ static char *answer_filemapping_message(const char *mapname)
|
|||||||
mapsize = mbi.RegionSize;
|
mapsize = mbi.RegionSize;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_IPC
|
#ifdef DEBUG_IPC
|
||||||
debug("region size = %zd\n", mapsize);
|
debug("region size = %"SIZEu"\n", mapsize);
|
||||||
#endif
|
#endif
|
||||||
if (mapsize < 5) {
|
if (mapsize < 5) {
|
||||||
err = dupstr("mapping smaller than smallest possible request");
|
err = dupstr("mapping smaller than smallest possible request");
|
||||||
|
Loading…
Reference in New Issue
Block a user