Print size_t variables on properly on Windows
OpenSC used SUSv3 "z" printf length modifier for printing size_t variables, however this modifier is not available on Windows ("I" must be used instead), at least for now. Introduce SC_FORMAT_LEN_SIZE_T define for that purpose and convert existing code to use it when printing size_t variables. This define can't go into libopensc/internal.h since tools use it, too. Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
This commit is contained in:
parent
1168ca00f3
commit
b646a306dc
|
@ -1676,8 +1676,9 @@ static int piv_general_mutual_authenticate(sc_card_t *card,
|
|||
plain_text_len += tmplen;
|
||||
|
||||
if (plain_text_len != witness_len) {
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Encrypted and decrypted lengths do not match: %zu:%zu\n",
|
||||
witness_len, plain_text_len);
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
|
||||
"Encrypted and decrypted lengths do not match: %"SC_FORMAT_LEN_SIZE_T"u:%"SC_FORMAT_LEN_SIZE_T"u\n",
|
||||
witness_len, plain_text_len);
|
||||
r = SC_ERROR_INTERNAL;
|
||||
goto err;
|
||||
}
|
||||
|
@ -1801,8 +1802,9 @@ static int piv_general_mutual_authenticate(sc_card_t *card,
|
|||
decrypted_reponse_len += tmplen;
|
||||
|
||||
if (decrypted_reponse_len != nonce_len || memcmp(nonce, decrypted_reponse, nonce_len) != 0) {
|
||||
sc_log(card->ctx, "mutual authentication failed, card returned wrong value %zu:%zu",
|
||||
decrypted_reponse_len, nonce_len);
|
||||
sc_log(card->ctx,
|
||||
"mutual authentication failed, card returned wrong value %"SC_FORMAT_LEN_SIZE_T"u:%"SC_FORMAT_LEN_SIZE_T"u",
|
||||
decrypted_reponse_len, nonce_len);
|
||||
r = SC_ERROR_DECRYPT_FAILED;
|
||||
goto err;
|
||||
}
|
||||
|
@ -2005,7 +2007,7 @@ static int piv_general_external_authenticate(sc_card_t *card,
|
|||
/* Sanity check the lengths again */
|
||||
if(output_len != (size_t)tmplen) {
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Allocated and computed lengths do not match! "
|
||||
"Expected %zd, found: %d\n", output_len, tmplen);
|
||||
"Expected %"SC_FORMAT_LEN_SIZE_T"d, found: %d\n", output_len, tmplen);
|
||||
r = SC_ERROR_INTERNAL;
|
||||
goto err;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,12 @@ extern "C" {
|
|||
#include "libopensc/sm.h"
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define SC_FORMAT_LEN_SIZE_T "I"
|
||||
#else
|
||||
/* hope SUSv3 one works */
|
||||
#define SC_FORMAT_LEN_SIZE_T "z"
|
||||
#endif
|
||||
|
||||
#define SC_SEC_OPERATION_DECIPHER 0x0001
|
||||
#define SC_SEC_OPERATION_SIGN 0x0002
|
||||
|
|
|
@ -396,8 +396,8 @@ static int cardos_sm4h(const unsigned char *in, size_t inlen, unsigned char
|
|||
unsigned int i,j;
|
||||
|
||||
if (keylen != 16) {
|
||||
printf("key has wrong size, need 16 bytes, got %zd. aborting.\n",
|
||||
keylen);
|
||||
printf("key has wrong size, need 16 bytes, got %"SC_FORMAT_LEN_SIZE_T"d. aborting.\n",
|
||||
keylen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -593,7 +593,8 @@ static int cardos_format(const char *opt_startkey)
|
|||
if (check_apdu(&apdu))
|
||||
return 1;
|
||||
if (apdu.resplen < 0x04) {
|
||||
printf("expected 4-6 bytes form GET DATA for startkey data, but got only %zu\n", apdu.resplen);
|
||||
printf("expected 4-6 bytes form GET DATA for startkey data, but got only %"SC_FORMAT_LEN_SIZE_T"u\n",
|
||||
apdu.resplen);
|
||||
printf("aborting\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -914,7 +915,8 @@ static int cardos_change_startkey(const char *change_startkey_apdu)
|
|||
if (check_apdu(&apdu))
|
||||
return 1;
|
||||
if (apdu.resplen < 0x04) {
|
||||
printf("expected 4-6 bytes form GET DATA for startkey data, but got only %zu\n", apdu.resplen);
|
||||
printf("expected 4-6 bytes form GET DATA for startkey data, but got only %"SC_FORMAT_LEN_SIZE_T"u\n",
|
||||
apdu.resplen);
|
||||
printf("aborting\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -999,7 +1001,8 @@ change_startkey:
|
|||
if (check_apdu(&apdu))
|
||||
return 1;
|
||||
if (apdu.resplen < 0x04) {
|
||||
printf("expected 4-6 bytes form GET DATA for startkey data, but got only %zu\n", apdu.resplen);
|
||||
printf("expected 4-6 bytes form GET DATA for startkey data, but got only %"SC_FORMAT_LEN_SIZE_T"u\n",
|
||||
apdu.resplen);
|
||||
printf("aborting\n");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -385,12 +385,7 @@ static int print_info(sc_card_t *card) {
|
|||
if (r < 0) {
|
||||
printf(" unable to read the file: %s\n", sc_strerror(r));
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
// visual studio doesn't support %zu
|
||||
printf(" Size: %Iu\n", size);
|
||||
#else
|
||||
printf(" Size: %zu\n", size);
|
||||
#endif
|
||||
printf(" Size: %"SC_FORMAT_LEN_SIZE_T"u\n", size);
|
||||
}
|
||||
printf("\n");
|
||||
if (strcmp(records[i].directory, "mscp") == 0 && strcmp(records[i].filename, "cmapfile") == 0 ) {
|
||||
|
|
|
@ -365,7 +365,8 @@ static int do_userinfo(sc_card_t *card)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
if (r != (signed)count) {
|
||||
fprintf(stderr, "%s: expecting %zd, got only %d bytes\n", openpgp_data[i].ef, count, r);
|
||||
fprintf(stderr, "%s: expecting %"SC_FORMAT_LEN_SIZE_T"d, got only %d bytes\n",
|
||||
openpgp_data[i].ef, count, r);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -656,8 +656,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
file->path = path;
|
||||
|
||||
printf("File key creation %s, size %zd.\n", file->path.value,
|
||||
file->size);
|
||||
printf("File key creation %s, size %"SC_FORMAT_LEN_SIZE_T"d.\n",
|
||||
file->path.value,
|
||||
file->size);
|
||||
|
||||
r = sc_create_file(card, file);
|
||||
if(r) goto out;
|
||||
|
@ -672,7 +673,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
printf("Private key length is %zd\n", lg);
|
||||
printf("Private key length is %"SC_FORMAT_LEN_SIZE_T"d\n", lg);
|
||||
|
||||
printf("Write private key.\n");
|
||||
r = sc_update_binary(card,0,pdata,lg,0);
|
||||
|
@ -696,7 +697,7 @@ int main(int argc, char *argv[])
|
|||
r = sc_pkcs15_encode_pubkey(ctx, &key, &pdata, &lg);
|
||||
if(r) goto out;
|
||||
|
||||
printf("Public key length %zd\n", lg);
|
||||
printf("Public key length %"SC_FORMAT_LEN_SIZE_T"d\n", lg);
|
||||
|
||||
sc_format_path("3F000002", &path);
|
||||
r = sc_select_file(card, &path, NULL);
|
||||
|
|
Loading…
Reference in New Issue