From 91177e51ec77d00c4739cce6e177ef8d11fba74c Mon Sep 17 00:00:00 2001 From: "ludovic.rousseau" Date: Mon, 5 May 2008 13:00:01 +0000 Subject: [PATCH] Use size_t instead of int when needed, plus some other minor changes Patch bug.1 included in Ticket #176 git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3510 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/libopensc/muscle-filesystem.h | 2 +- src/libopensc/muscle.c | 8 ++++---- src/pkcs11/framework-pkcs15.c | 2 +- src/pkcs11/openssl.c | 4 ++-- src/pkcs11/pkcs11-display.c | 4 ++-- src/scconf/parse.c | 2 +- src/scconf/sclex.c | 2 +- src/signer/dialog.c | 7 ++++--- src/signer/opensc-crypto.h | 2 +- src/tests/print.c | 10 ++++++---- src/tests/sc-test.h | 2 +- src/tools/opensc-explorer.c | 6 +++--- src/tools/piv-tool.c | 3 ++- src/tools/pkcs15-init.c | 2 +- 14 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/libopensc/muscle-filesystem.h b/src/libopensc/muscle-filesystem.h index 60fe0877..30c8c184 100644 --- a/src/libopensc/muscle-filesystem.h +++ b/src/libopensc/muscle-filesystem.h @@ -51,7 +51,7 @@ typedef struct mscsfs { int (*listFile)(mscfs_file_t *fileOut, int reset, void* udata); } mscfs_t; -mscfs_t *mscfs_new(); +mscfs_t *mscfs_new(void); void mscfs_free(mscfs_t *fs); void mscfs_clear_cache(mscfs_t* fs); int mscfs_push_file(mscfs_t* fs, mscfs_file_t *file); diff --git a/src/libopensc/muscle.c b/src/libopensc/muscle.c index b4b4693f..da405ad2 100644 --- a/src/libopensc/muscle.c +++ b/src/libopensc/muscle.c @@ -316,7 +316,7 @@ int msc_verify_pin(sc_card_t *card, int pinNumber, const u8 *pinValue, int pinLe void msc_verify_pin_apdu(sc_card_t *card, sc_apdu_t *apdu, u8* buffer, size_t bufferLength, int pinNumber, const u8 *pinValue, int pinLength) { assert(buffer); - assert(bufferLength >= pinLength); + assert(bufferLength >= (size_t)pinLength); assert(pinLength <= MSC_MAX_PIN_LENGTH); truncatePinNulls(pinValue, &pinLength); @@ -360,7 +360,7 @@ int msc_unblock_pin(sc_card_t *card, int pinNumber, const u8 *pukValue, int pukL void msc_unblock_pin_apdu(sc_card_t *card, sc_apdu_t *apdu, u8* buffer, size_t bufferLength, int pinNumber, const u8 *pukValue, int pukLength) { assert(buffer); - assert(bufferLength >= pukLength); + assert(bufferLength >= (size_t)pukLength); assert(pukLength <= MSC_MAX_PIN_LENGTH); truncatePinNulls(pukValue, &pukLength); @@ -406,7 +406,7 @@ void msc_change_pin_apdu(sc_card_t *card, sc_apdu_t *apdu, u8* buffer, size_t bu assert(pinLength <= MSC_MAX_PIN_LENGTH); assert(newPinLength <= MSC_MAX_PIN_LENGTH); assert(buffer); - assert(bufferLength >= pinLength + newPinLength + 2); + assert(bufferLength >= pinLength + newPinLength + 2UL); truncatePinNulls(pinValue, &pinLength); truncatePinNulls(newPin, &newPinLength); @@ -806,7 +806,7 @@ int msc_compute_crypt(sc_card_t *card, size_t dataLength, size_t outputDataLength) { - int left = dataLength; + size_t left = dataLength; const u8* inPtr = data; u8* outPtr = outputData; int toSend; diff --git a/src/pkcs11/framework-pkcs15.c b/src/pkcs11/framework-pkcs15.c index 5da290ea..e081ecbe 100644 --- a/src/pkcs11/framework-pkcs15.c +++ b/src/pkcs11/framework-pkcs15.c @@ -263,7 +263,7 @@ static int public_key_created(struct pkcs15_fw_data *fw_data, struct pkcs15_any_object **obj2) { int found = 0; - int ii=0; + unsigned int ii=0; while(iiobjects[ii]->p15_object) { diff --git a/src/pkcs11/openssl.c b/src/pkcs11/openssl.c index a4a494a0..592d7630 100644 --- a/src/pkcs11/openssl.c +++ b/src/pkcs11/openssl.c @@ -136,9 +136,9 @@ static CK_RV sc_pkcs11_openssl_md_final(sc_pkcs11_operation_t *op, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen) { EVP_MD_CTX *md_ctx = DIGEST_CTX(op); - unsigned int len = *pulDigestLen; + CK_ULONG len = *pulDigestLen; - if (len < EVP_MD_CTX_size(md_ctx)) { + if (len < (CK_ULONG)EVP_MD_CTX_size(md_ctx)) { *pulDigestLen = EVP_MD_CTX_size(md_ctx); return CKR_BUFFER_TOO_SMALL; } diff --git a/src/pkcs11/pkcs11-display.c b/src/pkcs11/pkcs11-display.c index 9ee5e997..8d0fc53e 100644 --- a/src/pkcs11/pkcs11-display.c +++ b/src/pkcs11/pkcs11-display.c @@ -713,7 +713,7 @@ void print_slot_list(FILE *f, CK_SLOT_ID_PTR pSlotList, CK_ULONG ulCount) void print_slot_info(FILE *f, CK_SLOT_INFO *info) { - int i; + size_t i; enum_specs ck_flags[] = { { CKF_TOKEN_PRESENT , "CKF_TOKEN_PRESENT " }, { CKF_REMOVABLE_DEVICE , "CKF_REMOVABLE_DEVICE " }, @@ -899,7 +899,7 @@ void print_attribute_list_req(FILE *f, CK_ATTRIBUTE_PTR pTemplate, void print_session_info(FILE *f, CK_SESSION_INFO *info) { - int i; + size_t i; enum_specs ck_flags[] = { { CKF_RW_SESSION , "CKF_RW_SESSION " }, { CKF_SERIAL_SESSION , "CKF_SERIAL_SESSION " } diff --git a/src/scconf/parse.c b/src/scconf/parse.c index 7946362f..0736c01d 100644 --- a/src/scconf/parse.c +++ b/src/scconf/parse.c @@ -150,7 +150,7 @@ scconf_item *scconf_item_add(scconf_context * config, scconf_block * block, scco scconf_item_add_internal(&parser, type); switch (parser.current_item->type) { case SCCONF_ITEM_TYPE_COMMENT: - parser.current_item->value.comment = strdup((char *) data); + parser.current_item->value.comment = strdup((const char *) data); break; case SCCONF_ITEM_TYPE_BLOCK: if (!dst) diff --git a/src/scconf/sclex.c b/src/scconf/sclex.c index 3194d0f7..6f3a0db0 100644 --- a/src/scconf/sclex.c +++ b/src/scconf/sclex.c @@ -92,7 +92,7 @@ static void buf_finished(BUFHAN * bp) } } -static void buf_eat_till(BUFHAN * bp, char start, char *end) +static void buf_eat_till(BUFHAN * bp, char start, const char *end) { int i; diff --git a/src/signer/dialog.c b/src/signer/dialog.c index 87290df2..c66f4346 100644 --- a/src/signer/dialog.c +++ b/src/signer/dialog.c @@ -36,6 +36,7 @@ int ask_and_verify_pin_code(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *pin) { int r; + size_t len; const char *argv[3]; const char *pgmname = PIN_ENTRY; ASSUAN_CONTEXT ctx; @@ -78,12 +79,12 @@ int ask_and_verify_pin_code(struct sc_pkcs15_card *p15card, printf("GETPIN: %s\n", assuan_strerror((AssuanError) r)); goto err; } - r = strlen(buf); - if (r < pinfo->min_length) { + len = strlen(buf); + if (len < pinfo->min_length) { sprintf(errtext, "PIN code too short, min. %lu digits", (unsigned long) pinfo->min_length); continue; } - if (r > pinfo->max_length) { + if (len > pinfo->max_length) { sprintf(errtext, "PIN code too long, max. %lu digits", (unsigned long) pinfo->max_length); continue; } diff --git a/src/signer/opensc-crypto.h b/src/signer/opensc-crypto.h index c5fc21f9..c4da5d0c 100644 --- a/src/signer/opensc-crypto.h +++ b/src/signer/opensc-crypto.h @@ -13,6 +13,6 @@ struct sc_priv_data int ref_count, reader_id; }; -extern RSA_METHOD * sc_get_method(); +extern RSA_METHOD * sc_get_method(void); #endif diff --git a/src/tests/print.c b/src/tests/print.c index f540cce4..23f488fc 100644 --- a/src/tests/print.c +++ b/src/tests/print.c @@ -95,6 +95,7 @@ static void print_pin(const struct sc_pkcs15_object *obj) static void print_prkey(const struct sc_pkcs15_object *obj) { int i; + size_t j; const char *usages[] = { "encrypt", "decrypt", "sign", "signRecover", @@ -131,8 +132,8 @@ static void print_prkey(const struct sc_pkcs15_object *obj) printf("\tNative : %s\n", prkey->native ? "yes" : "no"); if (prkey->path.len) { printf("\tPath : "); - for (i = 0; i < prkey->path.len; i++) - printf("%02X", prkey->path.value[i]); + for (j = 0; j < prkey->path.len; j++) + printf("%02X", prkey->path.value[j]); if (prkey->path.type == SC_PATH_TYPE_PATH_PROT) printf(" (protected)"); printf("\n"); @@ -143,6 +144,7 @@ static void print_prkey(const struct sc_pkcs15_object *obj) static void print_pubkey(const struct sc_pkcs15_object *obj) { int i; + size_t j; const char *usages[] = { "encrypt", "decrypt", "sign", "signRecover", @@ -178,8 +180,8 @@ static void print_pubkey(const struct sc_pkcs15_object *obj) printf("\tKey ref : %d\n", pubkey->key_reference); printf("\tNative : %s\n", pubkey->native ? "yes" : "no"); printf("\tPath : "); - for (i = 0; i < pubkey->path.len; i++) - printf("%02X", pubkey->path.value[i]); + for (j = 0; j < pubkey->path.len; j++) + printf("%02X", pubkey->path.value[j]); printf("\n"); printf("\tID : %s\n", sc_pkcs15_print_id(&pubkey->id)); } diff --git a/src/tests/sc-test.h b/src/tests/sc-test.h index d06bd826..1af23d8d 100644 --- a/src/tests/sc-test.h +++ b/src/tests/sc-test.h @@ -13,7 +13,7 @@ struct sc_pkcs15_card; struct sc_pkcs15_object; int sc_test_init(int *argc, char *argv[]); -void sc_test_cleanup(); +void sc_test_cleanup(void); void sc_test_print_card(const sc_pkcs15_card_t *); void sc_test_print_object(const struct sc_pkcs15_object *); diff --git a/src/tools/opensc-explorer.c b/src/tools/opensc-explorer.c index 4da2d2ed..4fad63fa 100644 --- a/src/tools/opensc-explorer.c +++ b/src/tools/opensc-explorer.c @@ -129,7 +129,7 @@ static int arg_to_path(const char *arg, sc_path_t *path, int is_id) path->type = SC_PATH_TYPE_DF_NAME; } else { /* file id */ - int buf[2]; + unsigned int buf[2]; u8 cbuf[2]; if (strlen(arg) != 4) { @@ -534,7 +534,7 @@ static int do_create(int argc, char **argv) if (arg_to_path(argv[0], &path, 1) != 0) goto usage; /* %z isn't supported everywhere */ - if (sscanf(argv[1], "%d", &size) != 1) + if (sscanf(argv[1], "%u", &size) != 1) goto usage; file = sc_file_new(); file->id = (path.value[0] << 8) | path.value[1]; @@ -564,7 +564,7 @@ static int do_mkdir(int argc, char **argv) goto usage; if (arg_to_path(argv[0], &path, 1) != 0) goto usage; - if (sscanf(argv[1], "%d", &size) != 1) + if (sscanf(argv[1], "%u", &size) != 1) goto usage; file = sc_file_new(); file->id = (path.value[0] << 8) | path.value[1]; diff --git a/src/tools/piv-tool.c b/src/tools/piv-tool.c index 63098977..313ee578 100644 --- a/src/tools/piv-tool.c +++ b/src/tools/piv-tool.c @@ -121,7 +121,8 @@ static int load_cert(const char * cert_id, const char * cert_file, derlen = stat_buf.st_size; der = malloc(derlen); if (der == NULL) { - printf("file %s is too big, %d\n", cert_file, derlen); + printf("file %s is too big, %lu\n", + cert_file, (unsigned long)derlen); return-1 ; } if (1 != fread(der, derlen, 1, fp)) { diff --git a/src/tools/pkcs15-init.c b/src/tools/pkcs15-init.c index 2b6f7804..2a23a1a5 100644 --- a/src/tools/pkcs15-init.c +++ b/src/tools/pkcs15-init.c @@ -107,7 +107,7 @@ static int do_read_certificate(const char *, const char *, X509 **); static void parse_commandline(int argc, char **argv); static void read_options_file(const char *); static void ossl_print_errors(void); -static void set_userpin_ref(); +static void set_userpin_ref(void); enum {