after a discussion with an expert I believe the proper handling of size_t with
printf is:
a) use "%lu" format for unsigned long and
b) always cast size_t to unsigned log.
for openct no changes are necessary, for opensc attached patch
adds the type casts.
do you agree? should I commit that patch? trunk only or also
opensc 0.11.0?
Thanks for your help.
Regards, Andreas
diff -udrNPp --exclude=.svn opensc.orig/src/common/main.c opensc/src/common/main.c
--- opensc.orig/src/common/main.c 2005-12-29 13:36:28.000000000 +0100
+++ opensc/src/common/main.c 2006-04-29 16:09:58.000000000 +0200
@@ -119,9 +119,7 @@ handle(char *progname,
{
fprintf(stderr,
"%s: %lu bytes copied from `%s' to `%s'\n",
- progname,
- bytes_copied,
- infilename,
+ (unsigned long) progname, bytes_copied, infilename,
outfilename);
}
return 0;
diff -udrNPp --exclude=.svn opensc.orig/src/libopensc/apdu.c opensc/src/libopensc/apdu.c
--- opensc.orig/src/libopensc/apdu.c 2006-04-26 12:14:53.000000000 +0200
+++ opensc/src/libopensc/apdu.c 2006-04-29 16:12:17.000000000 +0200
@@ -336,9 +336,10 @@ error:
"resp=%p resplen=%lu data=%p datelen=%lu",
apdu->cse & SC_APDU_SHORT_MASK,
(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
- apdu->cse, apdu->cla, apdu->ins, apdu->p1,
- apdu->p2, apdu->lc, apdu->le, apdu->resp,
- apdu->resplen, apdu->data, apdu->datalen);
+ apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
+ (unsigned long) apdu->lc, (unsigned long) apdu->le,
+ apdu->resp, (unsigned long) apdu->resplen,
+ apdu->data, (unsigned long) apdu->datalen);
return SC_ERROR_INVALID_ARGUMENTS;
}
diff -udrNPp --exclude=.svn opensc.orig/src/libopensc/card.c opensc/src/libopensc/card.c
--- opensc.orig/src/libopensc/card.c 2006-03-25 22:33:47.000000000 +0100
+++ opensc/src/libopensc/card.c 2006-04-29 16:10:19.000000000 +0200
@@ -680,7 +680,8 @@ sc_card_ctl(sc_card_t *card, unsigned lo
/* suppress "not supported" error messages */
if (r == SC_ERROR_NOT_SUPPORTED) {
- sc_debug(card->ctx, "card_ctl(%lu) not supported\n", cmd);
+ sc_debug(card->ctx, "card_ctl(%lu) not supported\n",
+ (unsigned long) cmd);
return r;
}
SC_FUNC_RETURN(card->ctx, 2, r);
diff -udrNPp --exclude=.svn opensc.orig/src/libopensc/card-flex.c opensc/src/libopensc/card-flex.c
--- opensc.orig/src/libopensc/card-flex.c 2006-01-22 23:27:40.000000000 +0100
+++ opensc/src/libopensc/card-flex.c 2006-04-29 16:10:30.000000000 +0200
@@ -1195,7 +1195,8 @@ static int flex_get_serialnr(sc_card_t *
len = tfile->size;
sc_file_free(tfile);
if (len != 8) {
- sc_debug(card->ctx, "unexpected file length of EF_ICCSN (%lu)\n", len);
+ sc_debug(card->ctx, "unexpected file length of EF_ICCSN (%lu)\n",
+ (unsigned long) len);
return SC_ERROR_INTERNAL;
}
r = sc_read_binary(card, 0, buf, len, 0);
diff -udrNPp --exclude=.svn opensc.orig/src/libopensc/ui.c opensc/src/libopensc/ui.c
--- opensc.orig/src/libopensc/ui.c 2006-03-14 22:55:39.000000000 +0100
+++ opensc/src/libopensc/ui.c 2006-04-29 16:10:42.000000000 +0200
@@ -310,14 +310,14 @@ __sc_ui_read_pin(sc_context_t *ctx, cons
if (len < pin_info->min_length) {
fprintf(stderr,
"PIN too short (min %lu characters)\n",
- (unsigned long)pin_info->min_length);
+ (unsigned long) pin_info->min_length);
continue;
}
if (pin_info->max_length
&& len > pin_info->max_length) {
fprintf(stderr,
"PIN too long (max %lu characters)\n",
- (unsigned long)pin_info->max_length);
+ (unsigned long) pin_info->max_length);
continue;
}
}
diff -udrNPp --exclude=.svn opensc.orig/src/pkcs11/pkcs11-display.c opensc/src/pkcs11/pkcs11-display.c
--- opensc.orig/src/pkcs11/pkcs11-display.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/pkcs11/pkcs11-display.c 2006-04-29 16:09:31.000000000 +0200
@@ -819,7 +819,8 @@ void print_mech_info(FILE *f, CK_MECHANI
fprintf(f, "Unknown Mechanism (%08lx) : ", type);
}
fprintf(f, "min:%lu max:%lu flags:0x%lX ",
- minfo->ulMinKeySize, minfo->ulMaxKeySize, minfo->flags);
+ (unsigned long) minfo->ulMinKeySize,
+ (unsigned long) minfo->ulMaxKeySize, minfo->flags);
printf("( %s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n",
#endif
(minfo->flags & CKF_HW) ? "Hardware " : "",
diff -udrNPp --exclude=.svn opensc.orig/src/pkcs15init/pkcs15-cardos.c opensc/src/pkcs15init/pkcs15-cardos.c
--- opensc.orig/src/pkcs15init/pkcs15-cardos.c 2006-02-15 09:53:00.000000000 +0100
+++ opensc/src/pkcs15init/pkcs15-cardos.c 2006-04-29 16:10:06.000000000 +0200
@@ -318,7 +318,8 @@ cardos_generate_key(sc_profile_t *profil
rsa_max_size = (card->caps & SC_CARD_CAP_RSA_2048) ? 2048 : 1024;
keybits = key_info->modulus_length & ~7UL;
if (keybits > rsa_max_size) {
- sc_error(card->ctx, "Unable to generate key, max size is %lu", rsa_max_size);
+ sc_error(card->ctx, "Unable to generate key, max size is %lu",
+ (unsigned long) rsa_max_size);
return SC_ERROR_INVALID_ARGUMENTS;
}
diff -udrNPp --exclude=.svn opensc.orig/src/tests/print.c opensc/src/tests/print.c
--- opensc.orig/src/tests/print.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tests/print.c 2006-04-29 16:05:06.000000000 +0200
@@ -65,7 +65,10 @@ static void print_pin(const struct sc_pk
printf(", %s", pin_flags[i]);
}
printf("\n");
- printf("\tLength : min_len:%lu, max_len:%lu, stored_len:%lu\n", pin->min_length, pin->max_length, pin->stored_length);
+ printf("\tLength : min_len:%lu, max_len:%lu, stored_len:%lu\n",
+ (unsigned long) pin->min_length,
+ (unsigned long) pin->max_length,
+ (unsigned long) pin->stored_length);
printf("\tPad char : 0x%02X\n", pin->pad_char);
printf("\tReference : %d\n", pin->reference);
printf("\tEncoding : ");
@@ -122,7 +125,8 @@ static void print_prkey(const struct sc_
}
printf("\n");
if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA)
- printf("\tModLength : %lu\n", prkey->modulus_length);
+ printf("\tModLength : %lu\n",
+ (unsigned long) prkey->modulus_length);
printf("\tKey ref : %d\n", prkey->key_reference);
printf("\tNative : %s\n", prkey->native ? "yes" : "no");
if (prkey->path.len) {
@@ -169,7 +173,8 @@ static void print_pubkey(const struct sc
}
printf("\n");
if (obj->type == SC_PKCS15_TYPE_PUBKEY_RSA)
- printf("\tModLength : %lu\n", pubkey->modulus_length);
+ printf("\tModLength : %lu\n",
+ (unsigned long) pubkey->modulus_length);
printf("\tKey ref : %d\n", pubkey->key_reference);
printf("\tNative : %s\n", pubkey->native ? "yes" : "no");
printf("\tPath : ");
diff -udrNPp --exclude=.svn opensc.orig/src/tools/netkey-tool.c opensc/src/tools/netkey-tool.c
--- opensc.orig/src/tools/netkey-tool.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tools/netkey-tool.c 2006-04-29 16:08:50.000000000 +0200
@@ -96,7 +96,7 @@ void show_pin(
f->prop_attr_len!=5 || f->prop_attr[0]!=0x01 || f->prop_attr[1]!=0x80
){
printf("\nInvald PIN-file: Type=%d, EF-Structure=%d, Prop-Len=%lu %02X:%02X:%02X\n",
- f->type, f->ef_structure, f->prop_attr_len,
+ f->type, f->ef_structure, (unsigned long) f->prop_attr_len,
f->prop_attr[0], f->prop_attr[1], f->prop_attr[2]
);
return;
@@ -133,7 +133,8 @@ void show_certs(
printf("\n");
for(i=0;i<sizeof(certlist)/sizeof(certlist[0]);++i){
- printf("Certificate %lu: %s", i, certlist[i].label); fflush(stdout);
+ printf("Certificate %lu: %s",
+ (unsigned long) i, certlist[i].label); fflush(stdout);
sc_format_path(certlist[i].path,&p);
if((j=sc_select_file(card,&p,&f))<0){
@@ -150,7 +151,7 @@ void show_certs(
printf(", Cannot read Cert-file, %s\n", sc_strerror(j));
continue;
}
- printf(", Maxlen=%lu", f->size);
+ printf(", Maxlen=%lu", (unsigned long) f->size);
q=buf;
if(q[0]==0x30 && q[1]==0x82){
if(q[4]==6 && q[5]<10 && q[q[5]+6]==0x30 && q[q[5]+7]==0x82) q+=q[5]+6;
@@ -234,7 +235,7 @@ void show_card(
file->size!=12 || (len=sc_read_binary(card,0,buf,12,0))!=12 || buf[0]!=0x5A || buf[1]!=0x0A
){
printf("\nInvald Serial-Number: Type=%d, EF-Structure=%d, Size=%lu\n",
- file->type, file->ef_structure, file->size
+ file->type, file->ef_structure, (unsigned long) file->size
);
return;
}
@@ -588,7 +589,8 @@ int main(
printf("%d Reader detected\n", sc_ctx_get_reader_count(ctx));
for(i=0; i < sc_ctx_get_reader_count(ctx); ++i){
sc_reader_t *reader = sc_ctx_get_reader(ctx, i);
- printf("%lu: %s, Driver: %s, %d Slot(s)\n", i, reader->name,
+ printf("%lu: %s, Driver: %s, %d Slot(s)\n",
+ (unsigned long) i, reader->name,
reader->driver->name, reader->slot_count);
}
if(reader < 0 || reader >= (int)sc_ctx_get_reader_count(ctx)){
diff -udrNPp --exclude=.svn opensc.orig/src/tools/opensc-explorer.c opensc/src/tools/opensc-explorer.c
--- opensc.orig/src/tools/opensc-explorer.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tools/opensc-explorer.c 2006-04-29 16:06:06.000000000 +0200
@@ -418,7 +418,7 @@ static int do_info(int argc, char **argv
printf("%02X", path.value[i]);
}
}
- printf("\n%-15s%lu bytes\n", "File size:", file->size);
+ printf("\n%-15s%lu bytes\n", "File size:", (unsigned long) file->size);
if (file->type == SC_FILE_TYPE_DF) {
const char *ops[] = {
diff -udrNPp --exclude=.svn opensc.orig/src/tools/opensc-tool.c opensc/src/tools/opensc-tool.c
--- opensc.orig/src/tools/opensc-tool.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tools/opensc-tool.c 2006-04-29 16:07:19.000000000 +0200
@@ -173,7 +173,7 @@ static int print_file(sc_card_t *in_card
};
printf("ef structure: %s, ", structs[file->ef_structure]);
}
- printf("size: %lu\n", file->size);
+ printf("size: %lu\n", (unsigned long) file->size);
for (r = 0; r < depth; r++)
printf(" ");
if (file->type == SC_FILE_TYPE_DF)
@@ -311,7 +311,7 @@ static int send_apdu(void)
apdu.datalen = apdu.lc;
if (len < apdu.lc) {
fprintf(stderr, "APDU too short (need %lu bytes).\n",
- apdu.lc-len);
+ (unsigned long) apdu.lc-len);
return 2;
}
len -= apdu.lc;
@@ -324,7 +324,8 @@ static int send_apdu(void)
} else
apdu.cse = SC_APDU_CASE_3_SHORT;
if (len) {
- fprintf(stderr, "APDU too long (%lu bytes extra).\n", len);
+ fprintf(stderr, "APDU too long (%lu bytes extra).\n",
+ (unsigned long) len);
return 2;
}
} else if (len == 1) {
diff -udrNPp --exclude=.svn opensc.orig/src/tools/piv-tool.c opensc/src/tools/piv-tool.c
--- opensc.orig/src/tools/piv-tool.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tools/piv-tool.c 2006-04-29 16:07:48.000000000 +0200
@@ -280,7 +280,7 @@ static int send_apdu(void)
apdu.datalen = apdu.lc;
if (len < apdu.lc) {
fprintf(stderr, "APDU too short (need %lu bytes).\n",
- apdu.lc-len);
+ (unsigned long) apdu.lc-len);
return 2;
}
len -= apdu.lc;
diff -udrNPp --exclude=.svn opensc.orig/src/tools/pkcs11-tool.c opensc/src/tools/pkcs11-tool.c
--- opensc.orig/src/tools/pkcs11-tool.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tools/pkcs11-tool.c 2006-04-29 16:09:14.000000000 +0200
@@ -1597,12 +1597,14 @@ show_key(CK_SESSION_HANDLE sess, CK_OBJE
switch (key_type) {
case CKK_RSA:
if (pub)
- printf("; RSA %lu bits\n", getMODULUS_BITS(sess, obj));
+ printf("; RSA %lu bits\n",
+ (unsigned long) getMODULUS_BITS(sess, obj));
else
printf("; RSA \n");
break;
default:
- printf("; unknown key algorithm %lu\n", key_type);
+ printf("; unknown key algorithm %lu\n",
+ (unsigned long) key_type);
break;
}
@@ -3463,7 +3465,7 @@ p11_mechanism_to_name(CK_MECHANISM_TYPE
if (mi->mech == mech)
return mi->name;
}
- snprintf(temp, sizeof(temp), "mechtype-%lu", mech);
+ snprintf(temp, sizeof(temp), "mechtype-%lu", (unsigned long) mech);
return temp;
}
diff -udrNPp --exclude=.svn opensc.orig/src/tools/pkcs15-crypt.c opensc/src/tools/pkcs15-crypt.c
--- opensc.orig/src/tools/pkcs15-crypt.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tools/pkcs15-crypt.c 2006-04-29 16:07:40.000000000 +0200
@@ -252,7 +252,7 @@ static int sign_ext(struct sc_pkcs15_obj
else {
fprintf(stderr,
"Invalid input size (%lu bytes)\n",
- len);
+ (unsigned long) len);
return SC_ERROR_INVALID_ARGUMENTS;
}
}
@@ -294,7 +294,7 @@ static int sign(struct sc_pkcs15_object
&& !(opt_crypt_flags & SC_ALGORITHM_RSA_PAD_PKCS1)
&& (size_t)c != key->modulus_length/8) {
fprintf(stderr, "Input has to be exactly %lu bytes, when using no padding.\n",
- key->modulus_length/8);
+ (unsigned long) key->modulus_length/8);
return 2;
}
if (!key->native) {
diff -udrNPp --exclude=.svn opensc.orig/src/tools/pkcs15-tool.c opensc/src/tools/pkcs15-tool.c
--- opensc.orig/src/tools/pkcs15-tool.c 2006-04-26 13:52:17.000000000 +0200
+++ opensc/src/tools/pkcs15-tool.c 2006-04-29 16:06:50.000000000 +0200
@@ -216,7 +216,7 @@ list_data_object(const char *kind, const
{
size_t i;
- printf("%s (%lu bytes): <", kind, data_len);
+ printf("%s (%lu bytes): <", kind, (unsigned long) data_len);
for (i = 0; i < data_len; i++)
printf(" %02X", data[i]);
printf(" >\n");
@@ -239,13 +239,15 @@ print_data_object(const char *kind, cons
}
for (i=0; i < data_len; i++)
fprintf(outf, "%c", data[i]);
- printf("Dumping (%lu bytes) to file <%s>: <", data_len, opt_outfile);
+ printf("Dumping (%lu bytes) to file <%s>: <",
+ (unsigned long) data_len, opt_outfile);
for (i=0; i < data_len; i++)
printf(" %02X", data[i]);
printf(" >\n");
fclose(outf);
} else {
- printf("%s (%lu bytes): <", kind, data_len);
+ printf("%s (%lu bytes): <",
+ kind, (unsigned long) data_len);
for (i=0; i < data_len; i++)
printf(" %02X", data[i]);
printf(" >\n");
_______________________________________________
opensc-devel mailing list
[email protected]
http://www.opensc-project.org/mailman/listinfo/opensc-devel