mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 01:18: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.
This commit is contained in:
parent
247866a9d3
commit
82a7e8c4ac
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);
|
||||
}
|
||||
|
11
pageant.c
11
pageant.c
@ -978,10 +978,10 @@ static void pageant_conn_closing(Plug *plug, const char *error_msg,
|
||||
struct pageant_conn_state *pc = container_of(
|
||||
plug, struct pageant_conn_state, plug);
|
||||
if (error_msg)
|
||||
pageant_listener_client_log(pc->plc, "c#%zu: error: %s",
|
||||
pageant_listener_client_log(pc->plc, "c#%"SIZEu": error: %s",
|
||||
pc->conn_index, error_msg);
|
||||
else
|
||||
pageant_listener_client_log(pc->plc, "c#%zu: connection closed",
|
||||
pageant_listener_client_log(pc->plc, "c#%"SIZEu": connection closed",
|
||||
pc->conn_index);
|
||||
sk_close(pc->connsock);
|
||||
pageant_unregister_client(&pc->pc);
|
||||
@ -1010,7 +1010,7 @@ static void pageant_conn_log(PageantClient *pc, PageantClientRequestId *reqid,
|
||||
container_of(reqid, struct pageant_conn_queued_response, reqid);
|
||||
|
||||
char *formatted = dupvprintf(fmt, ap);
|
||||
pageant_listener_client_log(pcs->plc, "c#%zu,r#%zu: %s",
|
||||
pageant_listener_client_log(pcs->plc, "c#%"SIZEu",r#%"SIZEu": %s",
|
||||
pcs->conn_index, qr->req_index, formatted);
|
||||
sfree(formatted);
|
||||
}
|
||||
@ -1159,10 +1159,11 @@ static int pageant_listen_accepting(Plug *plug,
|
||||
|
||||
peerinfo = sk_peer_info(pc->connsock);
|
||||
if (peerinfo && peerinfo->log_text) {
|
||||
pageant_listener_client_log(pl->plc, "c#%zu: new connection from %s",
|
||||
pageant_listener_client_log(pl->plc,
|
||||
"c#%"SIZEu": new connection from %s",
|
||||
pc->conn_index, peerinfo->log_text);
|
||||
} else {
|
||||
pageant_listener_client_log(pl->plc, "c#%zu: new connection",
|
||||
pageant_listener_client_log(pl->plc, "c#%"SIZEu": new connection",
|
||||
pc->conn_index);
|
||||
}
|
||||
sk_free_peer_info(peerinfo);
|
||||
|
@ -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_digest(pi->collectors[i], pi->pending_output);
|
||||
put_data(&pi->Prng, pi->pending_output, pi->hashalg->hlen);
|
||||
ssh_hash_reset(pi->collectors[i]);
|
||||
|
@ -1421,8 +1421,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)
|
||||
@ -788,7 +788,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);
|
||||
}
|
||||
|
||||
|
@ -1286,7 +1286,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
@ -161,7 +161,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;
|
||||
@ -1572,7 +1572,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;
|
||||
}
|
||||
}
|
||||
|
@ -909,7 +909,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