diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c index 3a4361f0..b88e43c2 100644 --- a/src/libopensc/asn1.c +++ b/src/libopensc/asn1.c @@ -454,7 +454,7 @@ static int encode_bit_string(const u8 * inbuf, size_t bits_left, u8 **outbuf, int skipped = 0; bytes = (bits_left + 7)/8 + 1; - *outbuf = out = (u8 *) malloc(bytes); + *outbuf = out = malloc(bytes); if (out == NULL) return SC_ERROR_OUT_OF_MEMORY; *outlen = bytes; @@ -561,7 +561,7 @@ static int asn1_encode_integer(int in, u8 ** obj, size_t * objsize) skip_sign = 0; skip_zero= 1; } - *obj = p = (u8 *) malloc(sizeof(in)+1); + *obj = p = malloc(sizeof(in)+1); if (*obj == NULL) return SC_ERROR_OUT_OF_MEMORY; do { @@ -677,7 +677,7 @@ int sc_asn1_encode_object_id(u8 **buf, size_t *buflen, /* an OID must have at least two components */ return SC_ERROR_INVALID_ARGUMENTS; *buflen = count = p - temp; - *buf = (u8 *) malloc(count); + *buf = malloc(count); if (!*buf) return SC_ERROR_OUT_OF_MEMORY; memcpy(*buf, temp, count); @@ -750,7 +750,7 @@ static int asn1_write_element(sc_context_t *ctx, unsigned int tag, c++; } *outlen = 2 + c + datalen; - buf = (u8 *) malloc(*outlen); + buf = malloc(*outlen); if (buf == NULL) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_OUT_OF_MEMORY); *out = p = buf; @@ -1075,7 +1075,7 @@ static int asn1_decode_entry(sc_context_t *ctx,struct sc_asn1_entry *entry, } if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = (u8 *) malloc(objlen-1); + *buf = malloc(objlen-1); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1109,7 +1109,7 @@ static int asn1_decode_entry(sc_context_t *ctx,struct sc_asn1_entry *entry, /* Allocate buffer if needed */ if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = (u8 *) malloc(objlen); + *buf = malloc(objlen); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1129,7 +1129,7 @@ static int asn1_decode_entry(sc_context_t *ctx,struct sc_asn1_entry *entry, assert(len != NULL); if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = (u8 *) malloc(objlen); + *buf = malloc(objlen); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1153,7 +1153,7 @@ static int asn1_decode_entry(sc_context_t *ctx,struct sc_asn1_entry *entry, assert(len != NULL); if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = (u8 *) malloc(objlen+1); + *buf = malloc(objlen+1); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1371,7 +1371,7 @@ static int asn1_encode_entry(sc_context_t *ctx, const struct sc_asn1_entry *entr buflen = 0; break; case SC_ASN1_BOOLEAN: - buf = (u8 *) malloc(1); + buf = malloc(1); if (buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1399,7 +1399,7 @@ static int asn1_encode_entry(sc_context_t *ctx, const struct sc_asn1_entry *entr case SC_ASN1_OCTET_STRING: case SC_ASN1_UTF8STRING: assert(len != NULL); - buf = (u8 *) malloc(*len + 1); + buf = malloc(*len + 1); if (buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1416,7 +1416,7 @@ static int asn1_encode_entry(sc_context_t *ctx, const struct sc_asn1_entry *entr break; case SC_ASN1_GENERALIZEDTIME: assert(len != NULL); - buf = (u8 *) malloc(*len); + buf = malloc(*len); if (buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1434,7 +1434,7 @@ static int asn1_encode_entry(sc_context_t *ctx, const struct sc_asn1_entry *entr { const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) parm; - buf = (u8 *) malloc(id->len); + buf = malloc(id->len); if (buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1573,7 +1573,7 @@ sc_der_copy(sc_pkcs15_der_t *dst, const sc_pkcs15_der_t *src) { memset(dst, 0, sizeof(*dst)); if (src->len) { - dst->value = (u8 *) malloc(src->len); + dst->value = malloc(src->len); if (!dst->value) return; dst->len = src->len; diff --git a/src/libopensc/card-atrust-acos.c b/src/libopensc/card-atrust-acos.c index 6c102ace..7fe276e6 100644 --- a/src/libopensc/card-atrust-acos.c +++ b/src/libopensc/card-atrust-acos.c @@ -105,7 +105,7 @@ static int atrust_acos_init(struct sc_card *card) unsigned int flags; atrust_acos_ex_data *ex_data; - ex_data = (atrust_acos_ex_data *) calloc(1, sizeof(atrust_acos_ex_data)); + ex_data = calloc(1, sizeof(atrust_acos_ex_data)); if (ex_data == NULL) return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/card-belpic.c b/src/libopensc/card-belpic.c index 4334e049..75cad9e7 100644 --- a/src/libopensc/card-belpic.c +++ b/src/libopensc/card-belpic.c @@ -996,7 +996,7 @@ static int belpic_init(sc_card_t *card) if (card->type < 0) card->type = SC_CARD_TYPE_BELPIC_EID; /* Unknown card: assume it's the Belpic Card */ - priv = (struct belpic_priv_data *) calloc(1, sizeof(struct belpic_priv_data)); + priv = calloc(1, sizeof(struct belpic_priv_data)); if (priv == NULL) return SC_ERROR_OUT_OF_MEMORY; card->drv_data = priv; diff --git a/src/libopensc/card-entersafe.c b/src/libopensc/card-entersafe.c index 866b79ae..10ea97f3 100644 --- a/src/libopensc/card-entersafe.c +++ b/src/libopensc/card-entersafe.c @@ -1319,7 +1319,7 @@ static int entersafe_gen_key(sc_card_t *card, sc_entersafe_gen_key_data *data) SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed"); SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe get pukey failed"); - data->modulus = (u8 *) malloc(len); + data->modulus = malloc(len); if (!data->modulus) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_ERROR_OUT_OF_MEMORY); diff --git a/src/libopensc/card-flex.c b/src/libopensc/card-flex.c index aee0cdd5..84ffeeb7 100644 --- a/src/libopensc/card-flex.c +++ b/src/libopensc/card-flex.c @@ -169,7 +169,7 @@ static int flex_init(sc_card_t *card) { struct flex_private_data *data; - if (!(data = (struct flex_private_data *) malloc(sizeof(*data)))) + if (!(data = malloc(sizeof(*data)))) return SC_ERROR_OUT_OF_MEMORY; card->drv_data = data; diff --git a/src/libopensc/card-gpk.c b/src/libopensc/card-gpk.c index 324fb792..7aeaae22 100644 --- a/src/libopensc/card-gpk.c +++ b/src/libopensc/card-gpk.c @@ -154,7 +154,7 @@ gpk_init(sc_card_t *card) unsigned long exponent, flags, kg; unsigned char info[13]; - card->drv_data = priv = (struct gpk_private_data *) calloc(1, sizeof(*priv)); + card->drv_data = priv = calloc(1, sizeof(*priv)); if (card->drv_data == NULL) return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/card-jcop.c b/src/libopensc/card-jcop.c index 3a93c8d7..edaf46e0 100644 --- a/src/libopensc/card-jcop.c +++ b/src/libopensc/card-jcop.c @@ -101,7 +101,7 @@ static int jcop_init(sc_card_t *card) sc_file_t *f; int flags; - drvdata=(struct jcop_private_data *) malloc(sizeof(struct jcop_private_data)); + drvdata=malloc(sizeof(struct jcop_private_data)); if (!drvdata) return SC_ERROR_OUT_OF_MEMORY; memset(drvdata, 0, sizeof(struct jcop_private_data)); @@ -472,7 +472,7 @@ static int jcop_process_fci(sc_card_t *card, sc_file_t *file, u8 *filelist; nfiles=file->prop_attr[4]; if (nfiles) { - filelist=(u8 *) malloc(2*nfiles); + filelist=malloc(2*nfiles); if (!filelist) return SC_ERROR_OUT_OF_MEMORY; memcpy(filelist, &file->prop_attr[5], 2*nfiles); diff --git a/src/libopensc/card-mcrd.c b/src/libopensc/card-mcrd.c index a0a1516a..c6f4cc36 100644 --- a/src/libopensc/card-mcrd.c +++ b/src/libopensc/card-mcrd.c @@ -125,7 +125,7 @@ static struct df_info_s *get_df_info(sc_card_t * card) return dfi; } /* Not found, create it. */ - dfi = (struct df_info_s *)calloc(1, sizeof *dfi); + dfi = calloc(1, sizeof *dfi); if (!dfi) { sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "out of memory while allocating df_info\n"); return NULL; @@ -280,7 +280,7 @@ static int mcrd_init(sc_card_t * card) struct mcrd_priv_data *priv; sc_path_t tmppath; - priv = (struct mcrd_priv_data *)calloc(1, sizeof *priv); + priv = calloc(1, sizeof *priv); if (!priv) return SC_ERROR_OUT_OF_MEMORY; card->name = "MICARDO 2.1"; @@ -359,7 +359,7 @@ static int load_special_files(sc_card_t * card) else if (r < 0) { SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r); } else { - rule = (struct rule_record_s *)malloc(sizeof *rule + r); + rule = malloc(sizeof *rule + r); if (!rule) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); rule->recno = recno; @@ -390,7 +390,7 @@ static int load_special_files(sc_card_t * card) else if (r < 0) { SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r); } else { - keyd = (struct keyd_record_s *)malloc(sizeof *keyd + r); + keyd = malloc(sizeof *keyd + r); if (!keyd) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); keyd->recno = recno; diff --git a/src/libopensc/card-oberthur.c b/src/libopensc/card-oberthur.c index 0e407387..fc4e7128 100644 --- a/src/libopensc/card-oberthur.c +++ b/src/libopensc/card-oberthur.c @@ -230,7 +230,7 @@ auth_init(struct sc_card *card) unsigned long flags; int rv = 0; - data = (struct auth_private_data *) calloc(1, sizeof(struct auth_private_data)); + data = calloc(1, sizeof(struct auth_private_data)); if (!data) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); @@ -1288,7 +1288,7 @@ auth_generate_key(struct sc_card *card, int use_sm, } sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x46, 0x00, 0x00); - apdu.resp = (unsigned char *) calloc(1, data->key_bits/8+8); + apdu.resp = calloc(1, data->key_bits/8+8); if (!apdu.resp) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); @@ -2141,7 +2141,7 @@ auth_read_binary(struct sc_card *card, unsigned int offset, for (jj=0; jjctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot read RSA public key component"); - bn[1].data = (unsigned char *) calloc(1, rv); + bn[1].data = calloc(1, rv); bn[1].len = rv; memcpy(bn[1].data, resp, rv); diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c index d5c35417..4c6285ba 100644 --- a/src/libopensc/card-openpgp.c +++ b/src/libopensc/card-openpgp.c @@ -130,7 +130,7 @@ pgp_init(sc_card_t *card) struct do_info *info; int r; - priv = (struct pgp_priv_data *) calloc (1, sizeof *priv); + priv = calloc (1, sizeof *priv); if (!priv) return SC_ERROR_OUT_OF_MEMORY; card->name = "OpenPGP"; @@ -195,7 +195,7 @@ pgp_set_blob(struct blob *blob, const u8 *data, size_t len) free(blob->data); blob->len = len; blob->status = 0; - blob->data = (unsigned char *) malloc(len); + blob->data = malloc(len); memcpy(blob->data, data, len); blob->file->size = len; @@ -209,7 +209,7 @@ pgp_new_blob(struct blob *parent, unsigned int file_id, sc_file_t *file = sc_file_new(); struct blob *blob, **p; - blob = (struct blob *) calloc(1, sizeof(*blob)); + blob = calloc(1, sizeof(*blob)); blob->parent = parent; blob->id = file_id; blob->file = file; @@ -639,7 +639,7 @@ pgp_decipher(sc_card_t *card, const u8 *in, size_t inlen, /* There's some funny padding indicator that must be * prepended... hmm. */ - if (!(temp = (u8 *) malloc(inlen + 1))) + if (!(temp = malloc(inlen + 1))) return SC_ERROR_OUT_OF_MEMORY; temp[0] = '\0'; memcpy(temp + 1, in, inlen); diff --git a/src/libopensc/card-piv.c b/src/libopensc/card-piv.c index e2717788..0b25705f 100644 --- a/src/libopensc/card-piv.c +++ b/src/libopensc/card-piv.c @@ -331,7 +331,7 @@ static int piv_general_io(sc_card_t *card, int ins, int p1, int p2, /* if using internal buffer, alloc new one */ if (rbuf == rbufinitbuf) { - *recvbuf = (u8 *)malloc(rbuflen); + *recvbuf = malloc(rbuflen); sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "DEE got buffer %p len %d",*recvbuf, rbuflen); if (*recvbuf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; @@ -665,7 +665,7 @@ static int piv_get_data(sc_card_t * card, int enumtag, taglen = put_tag_and_len(0x99, derlen, NULL); *buf_len = put_tag_and_len(0x53, taglen, NULL); - *buf = (u8*) malloc(*buf_len); + *buf = malloc(*buf_len); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto err; @@ -714,7 +714,7 @@ static int piv_get_data(sc_card_t * card, int enumtag, } sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,"get buffer for #%d len %d", enumtag, *buf_len); if (*buf == NULL && *buf_len > 0) { - *buf = (u8*)malloc(*buf_len); + *buf = malloc(*buf_len); if (*buf == NULL ) { r = SC_ERROR_OUT_OF_MEMORY; goto err; @@ -853,7 +853,7 @@ static int piv_cache_internal_data(sc_card_t *card, int enumtag) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED); #endif } else { - if (!(priv->obj_cache[enumtag].internal_obj_data = (u8*)malloc(taglen))) + if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen))) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen); @@ -870,7 +870,7 @@ static int piv_cache_internal_data(sc_card_t *card, int enumtag) if (taglen == 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_FILE_NOT_FOUND); - if (!(priv->obj_cache[enumtag].internal_obj_data = (u8*)malloc(taglen))) + if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen))) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen); @@ -988,7 +988,7 @@ static int piv_put_data(sc_card_t *card, int tag, tag_len = piv_objects[tag].tag_len; sbuflen = put_tag_and_len(0x5c, tag_len, NULL) + buf_len; - if (!(sbuf = (u8 *) malloc(sbuflen))) + if (!(sbuf = malloc(sbuflen))) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); p = sbuf; @@ -1027,7 +1027,7 @@ static int piv_write_certificate(sc_card_t *card, sbuflen = put_tag_and_len(0x53, taglen, NULL); - sbuf = (u8*) malloc(sbuflen); + sbuf = malloc(sbuflen); if (sbuf == NULL) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); p = sbuf; @@ -1105,7 +1105,7 @@ static int piv_write_binary(sc_card_t *card, unsigned int idx, if (priv->w_buf_len == 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INTERNAL); - priv->w_buf = (u8 *)malloc(priv->w_buf_len); + priv->w_buf = malloc(priv->w_buf_len); priv-> rwb_state = 0; } @@ -1865,7 +1865,7 @@ static int piv_init(sc_card_t *card) piv_private_data_t *priv; SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); - priv = (piv_private_data_t *) calloc(1, sizeof(piv_private_data_t)); + priv = calloc(1, sizeof(piv_private_data_t)); if (!priv) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); diff --git a/src/libopensc/card-starcos.c b/src/libopensc/card-starcos.c index c6dbea0c..43a59b60 100644 --- a/src/libopensc/card-starcos.c +++ b/src/libopensc/card-starcos.c @@ -86,7 +86,7 @@ static int starcos_init(sc_card_t *card) unsigned int flags; starcos_ex_data *ex_data; - ex_data = (starcos_ex_data *) calloc(1, sizeof(starcos_ex_data)); + ex_data = calloc(1, sizeof(starcos_ex_data)); if (ex_data == NULL) return SC_ERROR_OUT_OF_MEMORY; @@ -985,7 +985,7 @@ static int starcos_gen_key(sc_card_t *card, sc_starcos_gen_key_data *data) if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00) return sc_check_sw(card, apdu.sw1, apdu.sw2); - data->modulus = (u8 *) malloc(len); + data->modulus = malloc(len); if (!data->modulus) return SC_ERROR_OUT_OF_MEMORY; p = data->modulus; diff --git a/src/libopensc/card-tcos.c b/src/libopensc/card-tcos.c index 04e0d8ca..b985314b 100644 --- a/src/libopensc/card-tcos.c +++ b/src/libopensc/card-tcos.c @@ -83,7 +83,7 @@ static int tcos_init(sc_card_t *card) { unsigned long flags; - tcos_data *data = (tcos_data *) malloc(sizeof(tcos_data)); + tcos_data *data = malloc(sizeof(tcos_data)); if (!data) return SC_ERROR_OUT_OF_MEMORY; card->name = "TCOS"; diff --git a/src/libopensc/card.c b/src/libopensc/card.c index 33c92575..f7b910f1 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -62,10 +62,10 @@ static sc_card_t * sc_card_new(sc_context_t *ctx) if (ctx == NULL) return NULL; - card = (sc_card_t *) calloc(1, sizeof(struct sc_card)); + card = calloc(1, sizeof(struct sc_card)); if (card == NULL) return NULL; - card->ops = (struct sc_card_operations *) malloc(sizeof(struct sc_card_operations)); + card->ops = malloc(sizeof(struct sc_card_operations)); if (card->ops == NULL) { free(card); return NULL; diff --git a/src/libopensc/dir.c b/src/libopensc/dir.c index ad501261..da240410 100644 --- a/src/libopensc/dir.c +++ b/src/libopensc/dir.c @@ -109,7 +109,7 @@ static int parse_dir_record(sc_card_t *card, u8 ** buf, size_t *buflen, sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "AID is too long.\n"); return SC_ERROR_INVALID_ASN1_OBJECT; } - app = (sc_app_info_t *) malloc(sizeof(sc_app_info_t)); + app = malloc(sizeof(sc_app_info_t)); if (app == NULL) return SC_ERROR_OUT_OF_MEMORY; @@ -135,7 +135,7 @@ static int parse_dir_record(sc_card_t *card, u8 ** buf, size_t *buflen, } else app->path.len = 0; if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) { - app->ddo = (u8 *) malloc(ddo_len); + app->ddo = malloc(ddo_len); if (app->ddo == NULL) { free(app); return SC_ERROR_OUT_OF_MEMORY; @@ -189,7 +189,7 @@ int sc_enum_apps(sc_card_t *card) u8 *buf = NULL, *p; size_t bufsize; - buf = (u8 *) malloc(file_size); + buf = malloc(file_size); if (buf == NULL) return SC_ERROR_OUT_OF_MEMORY; p = buf; diff --git a/src/libopensc/iso7816.c b/src/libopensc/iso7816.c index 52d10af8..e0e621ba 100644 --- a/src/libopensc/iso7816.c +++ b/src/libopensc/iso7816.c @@ -829,7 +829,7 @@ static int iso7816_decipher(sc_card_t *card, assert(card != NULL && crgram != NULL && out != NULL); SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL); - sbuf = (u8 *)malloc(crgram_len + 1); + sbuf = malloc(crgram_len + 1); if (sbuf == NULL) return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/muscle-filesystem.c b/src/libopensc/muscle-filesystem.c index efcfad4d..f54d263f 100644 --- a/src/libopensc/muscle-filesystem.c +++ b/src/libopensc/muscle-filesystem.c @@ -41,7 +41,7 @@ static const u8* ignoredFiles[] = { }; mscfs_t *mscfs_new(void) { - mscfs_t *fs = (mscfs_t*)malloc(sizeof(mscfs_t)); + mscfs_t *fs = malloc(sizeof(mscfs_t)); memset(fs, 0, sizeof(mscfs_t)); memcpy(fs->currentPath, "\x3F\x00", 2); return fs; diff --git a/src/libopensc/pkcs15-actalis.c b/src/libopensc/pkcs15-actalis.c index 2d12391c..369d6d13 100644 --- a/src/libopensc/pkcs15-actalis.c +++ b/src/libopensc/pkcs15-actalis.c @@ -215,12 +215,9 @@ static int sc_pkcs15emu_actalis_init(sc_pkcs15_card_t * p15card) compLen = (size[0] << 8) + size[1]; - compCert = - (unsigned char *) malloc(compLen * - sizeof(unsigned char)); + compCert = malloc(compLen * sizeof(unsigned char)); len = 3 * compLen; /*Approximation of the uncompressed size */ - cert = - (unsigned char *) malloc(len * sizeof(unsigned char)); + cert = malloc(len * sizeof(unsigned char)); sc_read_binary(card, 4, compCert, compLen, 0); diff --git a/src/libopensc/pkcs15-atrust-acos.c b/src/libopensc/pkcs15-atrust-acos.c index 2dc677c2..7c88447d 100644 --- a/src/libopensc/pkcs15-atrust-acos.c +++ b/src/libopensc/pkcs15-atrust-acos.c @@ -175,7 +175,7 @@ static int sc_pkcs15emu_atrust_acos_init(sc_pkcs15_card_t *p15card) return SC_ERROR_INTERNAL; if (p15card->serial_number) free(p15card->serial_number); - p15card->serial_number = (char *) malloc(strlen(buf2) + 1); + p15card->serial_number = malloc(strlen(buf2) + 1); if (!p15card->serial_number) return SC_ERROR_INTERNAL; strcpy(p15card->serial_number, buf2); @@ -186,7 +186,7 @@ static int sc_pkcs15emu_atrust_acos_init(sc_pkcs15_card_t *p15card) /* manufacturer ID */ if (p15card->manufacturer_id) free(p15card->manufacturer_id); - p15card->manufacturer_id = (char *) malloc(strlen(MANU_ID) + 1); + p15card->manufacturer_id = malloc(strlen(MANU_ID) + 1); if (!p15card->manufacturer_id) return SC_ERROR_INTERNAL; strcpy(p15card->manufacturer_id, MANU_ID); @@ -194,7 +194,7 @@ static int sc_pkcs15emu_atrust_acos_init(sc_pkcs15_card_t *p15card) /* card label */ if (p15card->label) free(p15card->label); - p15card->label = (char *) malloc(strlen(CARD_LABEL) + 1); + p15card->label = malloc(strlen(CARD_LABEL) + 1); if (!p15card->label) return SC_ERROR_INTERNAL; strcpy(p15card->label, CARD_LABEL); diff --git a/src/libopensc/pkcs15-cache.c b/src/libopensc/pkcs15-cache.c index e49bc64c..be028cf4 100644 --- a/src/libopensc/pkcs15-cache.c +++ b/src/libopensc/pkcs15-cache.c @@ -100,7 +100,7 @@ int sc_pkcs15_read_cached_file(struct sc_pkcs15_card *p15card, return SC_ERROR_FILE_NOT_FOUND; /* cache file bad? */ } if (*buf == NULL) { - data = (u8 *) malloc((size_t)stbuf.st_size); + data = malloc((size_t)stbuf.st_size); if (data == NULL) return SC_ERROR_OUT_OF_MEMORY; } else diff --git a/src/libopensc/pkcs15-cert.c b/src/libopensc/pkcs15-cert.c index fc517798..81df217e 100644 --- a/src/libopensc/pkcs15-cert.c +++ b/src/libopensc/pkcs15-cert.c @@ -141,7 +141,7 @@ int sc_pkcs15_read_certificate(struct sc_pkcs15_card *p15card, len = copy.len; } - cert = (struct sc_pkcs15_cert *) malloc(sizeof(struct sc_pkcs15_cert)); + cert = malloc(sizeof(struct sc_pkcs15_cert)); if (cert == NULL) { free(data); return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/pkcs15-data.c b/src/libopensc/pkcs15-data.c index 29cc0a90..b9ed0669 100644 --- a/src/libopensc/pkcs15-data.c +++ b/src/libopensc/pkcs15-data.c @@ -55,7 +55,7 @@ int sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card, r = sc_pkcs15_read_file(p15card, &info->path, &data, &len, NULL); if (r) return r; - data_object = (struct sc_pkcs15_data *) malloc(sizeof(struct sc_pkcs15_data)); + data_object = malloc(sizeof(struct sc_pkcs15_data)); if (data_object == NULL) { free(data); return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/pkcs15-esinit.c b/src/libopensc/pkcs15-esinit.c index 139e133e..7ace5f86 100644 --- a/src/libopensc/pkcs15-esinit.c +++ b/src/libopensc/pkcs15-esinit.c @@ -58,7 +58,7 @@ static int sc_pkcs15emu_entersafe_init( sc_pkcs15_card_t *p15card) return SC_ERROR_INTERNAL; if (p15card->serial_number) free(p15card->serial_number); - p15card->serial_number = (char *) malloc(strlen(buf) + 1); + p15card->serial_number = malloc(strlen(buf) + 1); if (!p15card->serial_number) return SC_ERROR_INTERNAL; strcpy(p15card->serial_number, buf); @@ -66,7 +66,7 @@ static int sc_pkcs15emu_entersafe_init( sc_pkcs15_card_t *p15card) /* the manufacturer ID, in this case Giesecke & Devrient GmbH */ if (p15card->manufacturer_id) free(p15card->manufacturer_id); - p15card->manufacturer_id = (char *) malloc(strlen(MANU_ID) + 1); + p15card->manufacturer_id = malloc(strlen(MANU_ID) + 1); if (!p15card->manufacturer_id) return SC_ERROR_INTERNAL; strcpy(p15card->manufacturer_id, MANU_ID); diff --git a/src/libopensc/pkcs15-gemsafeGPK.c b/src/libopensc/pkcs15-gemsafeGPK.c index 46d385f6..2d39acd7 100644 --- a/src/libopensc/pkcs15-gemsafeGPK.c +++ b/src/libopensc/pkcs15-gemsafeGPK.c @@ -321,7 +321,7 @@ static int sc_pkcs15emu_gemsafeGPK_init(sc_pkcs15_card_t *p15card) /* For performance reasons we will only */ /* read part of the file , as it is about 6100 bytes */ - gsdata = (unsigned char *) malloc(file->size); + gsdata = malloc(file->size); if (!gsdata) return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/pkcs15-infocamere.c b/src/libopensc/pkcs15-infocamere.c index ee8d9f20..962fdaf4 100644 --- a/src/libopensc/pkcs15-infocamere.c +++ b/src/libopensc/pkcs15-infocamere.c @@ -514,10 +514,9 @@ static int loadCertificate(sc_pkcs15_card_t * p15card, int i, sc_read_binary(card, 2, size, 2, 0); compLen = (size[0] << 8) + size[1]; - compCert = - (unsigned char *) malloc(compLen * sizeof(unsigned char)); + compCert = malloc(compLen * sizeof(unsigned char)); len = 4 * compLen; /*Approximation of the uncompressed size */ - cert = (unsigned char *) malloc(len * sizeof(unsigned char)); + cert = malloc(len * sizeof(unsigned char)); sc_read_binary(card, 4, compCert, compLen, 0); diff --git a/src/libopensc/pkcs15-postecert.c b/src/libopensc/pkcs15-postecert.c index c5d78bb5..fb8128f6 100644 --- a/src/libopensc/pkcs15-postecert.c +++ b/src/libopensc/pkcs15-postecert.c @@ -204,7 +204,7 @@ static int sc_pkcs15emu_postecert_init(sc_pkcs15_card_t * p15card) if (count < 256) return SC_ERROR_INTERNAL; - certi = (unsigned char *) malloc(count); + certi = malloc(count); if (!certi) return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/pkcs15-prkey.c b/src/libopensc/pkcs15-prkey.c index a8c37c65..cf990fba 100644 --- a/src/libopensc/pkcs15-prkey.c +++ b/src/libopensc/pkcs15-prkey.c @@ -456,7 +456,7 @@ sc_pkcs15_read_prkey(struct sc_pkcs15_card *p15card, goto fail; } - *out = (struct sc_pkcs15_prkey *) malloc(sizeof(key)); + *out = malloc(sizeof(key)); if (*out == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto fail; diff --git a/src/libopensc/pkcs15-pubkey.c b/src/libopensc/pkcs15-pubkey.c index 6afedb3b..1b145d53 100644 --- a/src/libopensc/pkcs15-pubkey.c +++ b/src/libopensc/pkcs15-pubkey.c @@ -545,7 +545,7 @@ sc_pkcs15_read_pubkey(struct sc_pkcs15_card *p15card, return r; } - pubkey = (struct sc_pkcs15_pubkey *) calloc(1, sizeof(struct sc_pkcs15_pubkey)); + pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey)); if (pubkey == NULL) { free(data); return SC_ERROR_OUT_OF_MEMORY; @@ -588,7 +588,7 @@ sc_pkcs15_pubkey_from_prvkey(struct sc_context *ctx, assert(prvkey && out); *out = NULL; - pubkey = (struct sc_pkcs15_pubkey *) calloc(1, sizeof(struct sc_pkcs15_pubkey)); + pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey)); if (!pubkey) return SC_ERROR_OUT_OF_MEMORY; @@ -639,7 +639,7 @@ sc_pkcs15_pubkey_from_cert(struct sc_context *ctx, assert(cert_blob && out); - pubkey = (struct sc_pkcs15_pubkey *) calloc(1, sizeof(struct sc_pkcs15_pubkey)); + pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey)); if (!pubkey) SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate pubkey"); diff --git a/src/libopensc/pkcs15-starcert.c b/src/libopensc/pkcs15-starcert.c index 9cbecefa..514b3f78 100644 --- a/src/libopensc/pkcs15-starcert.c +++ b/src/libopensc/pkcs15-starcert.c @@ -167,7 +167,7 @@ static int sc_pkcs15emu_starcert_init(sc_pkcs15_card_t *p15card) return SC_ERROR_INTERNAL; if (p15card->serial_number) free(p15card->serial_number); - p15card->serial_number = (char *) malloc(strlen(buf) + 1); + p15card->serial_number = malloc(strlen(buf) + 1); if (!p15card->serial_number) return SC_ERROR_INTERNAL; strcpy(p15card->serial_number, buf); @@ -176,7 +176,7 @@ static int sc_pkcs15emu_starcert_init(sc_pkcs15_card_t *p15card) /* the manufacturer ID, in this case Giesecke & Devrient GmbH */ if (p15card->manufacturer_id) free(p15card->manufacturer_id); - p15card->manufacturer_id = (char *) malloc(strlen(MANU_ID) + 1); + p15card->manufacturer_id = malloc(strlen(MANU_ID) + 1); if (!p15card->manufacturer_id) return SC_ERROR_INTERNAL; strcpy(p15card->manufacturer_id, MANU_ID); diff --git a/src/libopensc/pkcs15-syn.c b/src/libopensc/pkcs15-syn.c index 7c858ff3..0ffeea4c 100644 --- a/src/libopensc/pkcs15-syn.c +++ b/src/libopensc/pkcs15-syn.c @@ -376,7 +376,7 @@ int sc_pkcs15emu_object_add(sc_pkcs15_card_t *p15card, unsigned int type, unsigned int df_type; size_t data_len; - obj = (sc_pkcs15_object_t *) calloc(1, sizeof(*obj)); + obj = calloc(1, sizeof(*obj)); if (!obj) return SC_ERROR_OUT_OF_MEMORY; memcpy(obj, in_obj, sizeof(*obj)); diff --git a/src/libopensc/pkcs15-wrap.c b/src/libopensc/pkcs15-wrap.c index 35c2c4a1..2961d588 100644 --- a/src/libopensc/pkcs15-wrap.c +++ b/src/libopensc/pkcs15-wrap.c @@ -141,7 +141,7 @@ do_cipher(EVP_CIPHER_CTX *cipher_ctx, const u8 *in, size_t in_len, size_t bl, left, total; int done; - *out = p = (u8 *) malloc(in_len + EVP_CIPHER_CTX_key_length(cipher_ctx)); + *out = p = malloc(in_len + EVP_CIPHER_CTX_key_length(cipher_ctx)); *out_len = total = 0; bl = EVP_CIPHER_CTX_block_size(cipher_ctx); diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c index 848ed684..b824ef87 100644 --- a/src/libopensc/pkcs15.c +++ b/src/libopensc/pkcs15.c @@ -148,7 +148,7 @@ int sc_pkcs15_parse_tokeninfo(sc_context_t *ctx, return r; } ti->version += 1; - ti->serial_number = (char *) malloc(serial_len * 2 + 1); + ti->serial_number = malloc(serial_len * 2 + 1); if (ti->serial_number == NULL) return SC_ERROR_OUT_OF_MEMORY; ti->serial_number[0] = 0; @@ -413,12 +413,12 @@ int sc_pkcs15_encode_odf(sc_context_t *ctx, sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "No DF's found.\n"); return SC_ERROR_OBJECT_NOT_FOUND; } - asn1_odf = (struct sc_asn1_entry *) malloc(sizeof(struct sc_asn1_entry) * (df_count + 1)); + asn1_odf = malloc(sizeof(struct sc_asn1_entry) * (df_count + 1)); if (asn1_odf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto err; } - asn1_paths = (struct sc_asn1_entry *) malloc(sizeof(struct sc_asn1_entry) * (df_count * 2)); + asn1_paths = malloc(sizeof(struct sc_asn1_entry) * (df_count * 2)); if (asn1_paths == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto err; @@ -455,7 +455,7 @@ struct sc_pkcs15_card * sc_pkcs15_card_new(void) { struct sc_pkcs15_card *p15card; - p15card = (struct sc_pkcs15_card *) calloc(1, sizeof(struct sc_pkcs15_card)); + p15card = calloc(1, sizeof(struct sc_pkcs15_card)); if (p15card == NULL) return NULL; p15card->magic = SC_PKCS15_CARD_MAGIC; @@ -1415,7 +1415,7 @@ int sc_pkcs15_add_df(struct sc_pkcs15_card *p15card, if (p->type == type) return 0; - newdf = (struct sc_pkcs15_df *) calloc(1, sizeof(struct sc_pkcs15_df)); + newdf = calloc(1, sizeof(struct sc_pkcs15_df)); if (newdf == NULL) return SC_ERROR_OUT_OF_MEMORY; newdf->path = *path; @@ -1571,7 +1571,7 @@ int sc_pkcs15_parse_df(struct sc_pkcs15_card *p15card, const u8 *oldp; size_t obj_len; - obj = (struct sc_pkcs15_object *) calloc(1, sizeof(struct sc_pkcs15_object)); + obj = calloc(1, sizeof(struct sc_pkcs15_object)); if (obj == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto ret; @@ -1627,7 +1627,7 @@ int sc_pkcs15_add_unusedspace(struct sc_pkcs15_card *p15card, return SC_ERROR_INVALID_ARGUMENTS; } - new_unusedspace = (sc_pkcs15_unusedspace_t *) calloc(1, sizeof(sc_pkcs15_unusedspace_t)); + new_unusedspace = calloc(1, sizeof(sc_pkcs15_unusedspace_t)); if (new_unusedspace == NULL) return SC_ERROR_OUT_OF_MEMORY; new_unusedspace->path = *path; @@ -1832,7 +1832,7 @@ int sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, goto fail_unlock; } } - data = (u8 *) malloc(len); + data = malloc(len); if (data == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto fail_unlock; diff --git a/src/libopensc/reader-ctapi.c b/src/libopensc/reader-ctapi.c index 5f00bf19..31f4183c 100644 --- a/src/libopensc/reader-ctapi.c +++ b/src/libopensc/reader-ctapi.c @@ -384,8 +384,8 @@ static int ctapi_load_module(sc_context_t *ctx, continue; } - reader = (sc_reader_t *) calloc(1, sizeof(sc_reader_t)); - priv = (struct ctapi_private_data *) calloc(1, sizeof(struct ctapi_private_data)); + reader = calloc(1, sizeof(sc_reader_t)); + priv = calloc(1, sizeof(struct ctapi_private_data)); if (!priv) return SC_ERROR_OUT_OF_MEMORY; reader->drv_data = priv; @@ -505,7 +505,7 @@ static int ctapi_init(sc_context_t *ctx, void **reader_data) struct ctapi_global_private_data *gpriv; scconf_block **blocks = NULL, *conf_block = NULL; - gpriv = (struct ctapi_global_private_data *) calloc(1, sizeof(struct ctapi_global_private_data)); + gpriv = calloc(1, sizeof(struct ctapi_global_private_data)); if (gpriv == NULL) return SC_ERROR_OUT_OF_MEMORY; *reader_data = gpriv; diff --git a/src/libopensc/reader-pcsc.c b/src/libopensc/reader-pcsc.c index e57a8d3d..2e1243a9 100644 --- a/src/libopensc/reader-pcsc.c +++ b/src/libopensc/reader-pcsc.c @@ -587,7 +587,7 @@ static int pcsc_init(sc_context_t *ctx, void **reader_data) *reader_data = NULL; - gpriv = (struct pcsc_global_private_data *) calloc(1, sizeof(struct pcsc_global_private_data)); + gpriv = calloc(1, sizeof(struct pcsc_global_private_data)); if (gpriv == NULL) { ret = SC_ERROR_OUT_OF_MEMORY; goto out; @@ -764,7 +764,7 @@ static int pcsc_detect_readers(sc_context_t *ctx, void *prv_data) } } while (rv != SCARD_S_SUCCESS); - reader_buf = (char *) malloc(sizeof(char) * reader_buf_size); + reader_buf = malloc(sizeof(char) * reader_buf_size); if (!reader_buf) { ret = SC_ERROR_OUT_OF_MEMORY; goto out; @@ -800,11 +800,11 @@ static int pcsc_detect_readers(sc_context_t *ctx, void *prv_data) sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Found new pcsc reader '%s'", reader_name); - if ((reader = (sc_reader_t *) calloc(1, sizeof(sc_reader_t))) == NULL) { + if ((reader = calloc(1, sizeof(sc_reader_t))) == NULL) { ret = SC_ERROR_OUT_OF_MEMORY; goto err1; } - if ((priv = (struct pcsc_private_data *) calloc(1, sizeof(struct pcsc_private_data))) == NULL) { + if ((priv = calloc(1, sizeof(struct pcsc_private_data))) == NULL) { ret = SC_ERROR_OUT_OF_MEMORY; goto err1; } @@ -988,7 +988,7 @@ static int pcsc_wait_for_event(sc_context_t *ctx, void *reader_data, } if (reader_states == NULL || *reader_states == NULL) { - rgReaderStates = (SCARD_READERSTATE *) calloc(sc_ctx_get_reader_count(ctx) + 2, sizeof(SCARD_READERSTATE)); + rgReaderStates = calloc(sc_ctx_get_reader_count(ctx) + 2, sizeof(SCARD_READERSTATE)); if (!rgReaderStates) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY); @@ -1538,7 +1538,7 @@ static int cardmod_init(sc_context_t *ctx, void **reader_data) *reader_data = NULL; - gpriv = (struct pcsc_global_private_data *) calloc(1, sizeof(struct pcsc_global_private_data)); + gpriv = calloc(1, sizeof(struct pcsc_global_private_data)); if (gpriv == NULL) { ret = SC_ERROR_OUT_OF_MEMORY; goto out; @@ -1690,11 +1690,11 @@ static int cardmod_detect_readers(sc_context_t *ctx, void *prv_data) sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "lecteur name = %s\n%s\n", reader_name,texte); } - if ((reader = (sc_reader_t *) calloc(1, sizeof(sc_reader_t))) == NULL) { + if ((reader = calloc(1, sizeof(sc_reader_t))) == NULL) { ret = SC_ERROR_OUT_OF_MEMORY; goto err1; } - if ((priv = (struct pcsc_private_data *) malloc(sizeof(struct pcsc_private_data))) == NULL) { + if ((priv = malloc(sizeof(struct pcsc_private_data))) == NULL) { ret = SC_ERROR_OUT_OF_MEMORY; goto err1; } diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index 010f3a96..b11d2b45 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -364,7 +364,7 @@ int sc_file_add_acl_entry(sc_file_t *file, unsigned int operation, return 0; } - _new = (sc_acl_entry_t *) malloc(sizeof(sc_acl_entry_t)); + _new = malloc(sizeof(sc_acl_entry_t)); if (_new == NULL) return SC_ERROR_OUT_OF_MEMORY; _new->method = method; diff --git a/src/pkcs11/framework-pkcs15.c b/src/pkcs11/framework-pkcs15.c index c19d9157..285332ba 100644 --- a/src/pkcs11/framework-pkcs15.c +++ b/src/pkcs11/framework-pkcs15.c @@ -156,7 +156,7 @@ static CK_RV pkcs15_bind(struct sc_pkcs11_card *p11card) struct pkcs15_fw_data *fw_data; int rc; - if (!(fw_data = (struct pkcs15_fw_data *) calloc(1, sizeof(*fw_data)))) + if (!(fw_data = calloc(1, sizeof(*fw_data)))) return CKR_HOST_MEMORY; p11card->fw_data = fw_data; @@ -252,7 +252,7 @@ __pkcs15_create_object(struct pkcs15_fw_data *fw_data, if (fw_data->num_objects >= MAX_OBJECTS) return SC_ERROR_TOO_MANY_OBJECTS; - if (!(obj = (struct pkcs15_any_object *) calloc(1, size))) + if (!(obj = calloc(1, size))) return SC_ERROR_OUT_OF_MEMORY; fw_data->objects[fw_data->num_objects++] = obj; @@ -724,7 +724,7 @@ static void pkcs15_init_slot(struct sc_pkcs15_card *p15card, } if (p15card->card->caps & SC_CARD_CAP_RNG) slot->token_info.flags |= CKF_RNG; - slot->fw_data = fw_data = (struct pkcs15_slot_data *) calloc(1, sizeof(*fw_data)); + slot->fw_data = fw_data = calloc(1, sizeof(*fw_data)); fw_data->auth_obj = auth; if (auth != NULL) { diff --git a/src/pkcs11/libpkcs11.c b/src/pkcs11/libpkcs11.c index e8d38266..6ae7dd38 100644 --- a/src/pkcs11/libpkcs11.c +++ b/src/pkcs11/libpkcs11.c @@ -35,7 +35,7 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs) lt_dlinit(); - mod = (sc_pkcs11_module_t *) calloc(1, sizeof(*mod)); + mod = calloc(1, sizeof(*mod)); mod->_magic = MAGIC; if (mspec == NULL) diff --git a/src/pkcs11/mechanism.c b/src/pkcs11/mechanism.c index 59964290..91d6a2a7 100644 --- a/src/pkcs11/mechanism.c +++ b/src/pkcs11/mechanism.c @@ -123,7 +123,7 @@ sc_pkcs11_new_operation(sc_pkcs11_session_t *session, { sc_pkcs11_operation_t *res; - res = (sc_pkcs11_operation_t *) calloc(1, type->obj_size); + res = calloc(1, type->obj_size); if (res) { res->session = session; res->type = type; @@ -349,7 +349,7 @@ sc_pkcs11_signature_init(sc_pkcs11_operation_t *operation, struct signature_data *data; int rv; - if (!(data = (struct signature_data *) calloc(1, sizeof(*data)))) + if (!(data = calloc(1, sizeof(*data)))) return CKR_HOST_MEMORY; data->info = NULL; @@ -566,7 +566,7 @@ sc_pkcs11_verify_init(sc_pkcs11_operation_t *operation, struct signature_data *data; int rv; - if (!(data = (struct signature_data *) calloc(1, sizeof(*data)))) + if (!(data = calloc(1, sizeof(*data)))) return CKR_HOST_MEMORY; data->info = NULL; @@ -639,7 +639,7 @@ sc_pkcs11_verify_final(sc_pkcs11_operation_t *operation, rv = key->ops->get_attribute(operation->session, key, &attr); if (rv != CKR_OK) return rv; - pubkey_value = (unsigned char *) malloc(attr.ulValueLen); + pubkey_value = malloc(attr.ulValueLen); attr.pValue = pubkey_value; rv = key->ops->get_attribute(operation->session, key, &attr); if (rv != CKR_OK) @@ -735,7 +735,7 @@ sc_pkcs11_decrypt_init(sc_pkcs11_operation_t *operation, { struct signature_data *data; - if (!(data = (struct signature_data *) calloc(1, sizeof(*data)))) + if (!(data = calloc(1, sizeof(*data)))) return CKR_HOST_MEMORY; data->key = key; @@ -773,7 +773,7 @@ sc_pkcs11_new_fw_mechanism(CK_MECHANISM_TYPE mech, { sc_pkcs11_mechanism_type_t *mt; - mt = (sc_pkcs11_mechanism_type_t *) calloc(1, sizeof(*mt)); + mt = calloc(1, sizeof(*mt)); if (mt == NULL) return mt; mt->mech = mech; @@ -839,7 +839,7 @@ sc_pkcs11_register_sign_and_hash_mechanism(struct sc_pkcs11_card *p11card, /* These hash-based mechs can only be used for sign/verify */ mech_info.flags &= (CKF_SIGN | CKF_SIGN_RECOVER | CKF_VERIFY | CKF_VERIFY_RECOVER); - info = (struct hash_signature_info *) calloc(1, sizeof(*info)); + info = calloc(1, sizeof(*info)); info->mech = mech; info->sign_type = sign_type; info->hash_type = hash_type; diff --git a/src/pkcs11/openssl.c b/src/pkcs11/openssl.c index fc3ca73d..69400a70 100644 --- a/src/pkcs11/openssl.c +++ b/src/pkcs11/openssl.c @@ -262,7 +262,7 @@ static CK_RV sc_pkcs11_openssl_md_init(sc_pkcs11_operation_t *op) if (!op || !(mt = op->type) || !(md = (EVP_MD *) mt->mech_data)) return CKR_ARGUMENTS_BAD; - if (!(md_ctx = (EVP_MD_CTX *) calloc(1, sizeof(*md_ctx)))) + if (!(md_ctx = calloc(1, sizeof(*md_ctx)))) return CKR_HOST_MEMORY; EVP_DigestInit(md_ctx, md); op->priv_data = md_ctx; @@ -307,7 +307,7 @@ do_convert_bignum(sc_pkcs15_bignum_t *dst, BIGNUM *src) if (src == 0) return 0; dst->len = BN_num_bytes(src); - dst->data = (u8 *) malloc(dst->len); + dst->data = malloc(dst->len); if (dst->data == NULL) return 0; BN_bn2bin(src, dst->data); @@ -521,7 +521,7 @@ CK_RV sc_pkcs11_verify_data(const unsigned char *pubkey, int pubkey_len, if (rsa == NULL) return CKR_DEVICE_MEMORY; - rsa_out = (unsigned char *) malloc(RSA_size(rsa)); + rsa_out = malloc(RSA_size(rsa)); if (rsa_out == NULL) { RSA_free(rsa); return CKR_DEVICE_MEMORY; diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index e2a99282..64d16523 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -42,7 +42,7 @@ extern CK_FUNCTION_LIST pkcs11_function_list; #include CK_RV mutex_create(void **mutex) { - pthread_mutex_t *m = (pthread_mutex_t *) malloc(sizeof(*mutex)); + pthread_mutex_t *m = malloc(sizeof(*mutex)); if (m == NULL) return CKR_GENERAL_ERROR;; pthread_mutex_init(m, NULL); @@ -80,7 +80,7 @@ CK_RV mutex_create(void **mutex) { CRITICAL_SECTION *m; - m = (CRITICAL_SECTION *) malloc(sizeof(*m)); + m = malloc(sizeof(*m)); if (m == NULL) return CKR_GENERAL_ERROR; InitializeCriticalSection(m); @@ -390,7 +390,7 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese card_detect_all(); - found = (CK_SLOT_ID_PTR) malloc(list_size(&virtual_slots) * sizeof(CK_SLOT_ID)); + found = malloc(list_size(&virtual_slots) * sizeof(CK_SLOT_ID)); if (found == NULL) { rv = CKR_HOST_MEMORY; diff --git a/src/pkcs11/pkcs11-object.c b/src/pkcs11/pkcs11-object.c index d7cc2c9d..93570032 100644 --- a/src/pkcs11/pkcs11-object.c +++ b/src/pkcs11/pkcs11-object.c @@ -1257,7 +1257,7 @@ int sc_pkcs11_any_cmp_attribute(struct sc_pkcs11_session *session, void *ptr, CK if (temp_attr.ulValueLen <= sizeof(temp1)) temp_attr.pValue = temp1; else { - temp2 = (u8 *) malloc(temp_attr.ulValueLen); + temp2 = malloc(temp_attr.ulValueLen); if (temp2 == NULL) return 0; temp_attr.pValue = temp2; diff --git a/src/pkcs11/pkcs11-spy.c b/src/pkcs11/pkcs11-spy.c index 6fbac81e..ffb16957 100644 --- a/src/pkcs11/pkcs11-spy.c +++ b/src/pkcs11/pkcs11-spy.c @@ -60,8 +60,7 @@ static CK_RV init_spy(void) #endif /* Allocates and initializes the pkcs11_spy structure */ - pkcs11_spy = - (CK_FUNCTION_LIST_PTR) malloc(sizeof(CK_FUNCTION_LIST)); + pkcs11_spy = malloc(sizeof(CK_FUNCTION_LIST)); if (pkcs11_spy) { /* with our own pkcs11.h we need to maintain this ourself */ pkcs11_spy->version.major = 2; diff --git a/src/pkcs11/secretkey.c b/src/pkcs11/secretkey.c index 82ab19cb..7e9a8c61 100644 --- a/src/pkcs11/secretkey.c +++ b/src/pkcs11/secretkey.c @@ -68,10 +68,10 @@ sc_pkcs11_create_secret_key(struct sc_pkcs11_session *session, CK_ATTRIBUTE_PTR attr; int n, rv; - key = (struct pkcs11_secret_key *) calloc(1, sizeof(*key)); + key = calloc(1, sizeof(*key)); if (!key) return CKR_HOST_MEMORY; - key->value = (CK_BYTE *) malloc(value_len); + key->value = malloc(value_len); if (!key->value) { pkcs11_secret_key_ops.release(key); return CKR_HOST_MEMORY; /* XXX correct? */ @@ -154,7 +154,7 @@ sc_pkcs11_secret_key_set_attribute(struct sc_pkcs11_session *session, case CKA_VALUE: if (key->value) free(key->value); - key->value = (CK_BYTE *) malloc(attr->ulValueLen); + key->value = malloc(attr->ulValueLen); if (key->value == NULL) return CKR_HOST_MEMORY; key->value_len = attr->ulValueLen; diff --git a/src/pkcs15init/pkcs15-cardos.c b/src/pkcs15init/pkcs15-cardos.c index 0b4aa6ae..09f330b4 100644 --- a/src/pkcs15init/pkcs15-cardos.c +++ b/src/pkcs15init/pkcs15-cardos.c @@ -737,7 +737,7 @@ do_cardos_extract_pubkey(sc_card_t *card, int nr, u8 tag, || buf[2] != count + 1 || buf[3] != 0) return SC_ERROR_INTERNAL; bn->len = count; - bn->data = (u8 *) malloc(count); + bn->data = malloc(count); if (bn->data == NULL) return SC_ERROR_OUT_OF_MEMORY; memcpy(bn->data, buf + 4, count); diff --git a/src/pkcs15init/pkcs15-cflex.c b/src/pkcs15init/pkcs15-cflex.c index e43714c7..1512291d 100644 --- a/src/pkcs15init/pkcs15-cflex.c +++ b/src/pkcs15init/pkcs15-cflex.c @@ -353,9 +353,9 @@ cflex_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, /* extract public key */ pubkey->algorithm = SC_ALGORITHM_RSA; pubkey->u.rsa.modulus.len = keybits / 8; - pubkey->u.rsa.modulus.data = (u8 *) malloc(keybits / 8); + pubkey->u.rsa.modulus.data = malloc(keybits / 8); pubkey->u.rsa.exponent.len = 3; - pubkey->u.rsa.exponent.data = (u8 *) malloc(3); + pubkey->u.rsa.exponent.data = malloc(3); memcpy(pubkey->u.rsa.exponent.data, "\x01\x00\x01", 3); if ((r = sc_select_file(card, &pukf->path, NULL)) < 0 || (r = sc_read_binary(card, 3, raw_pubkey, keybits / 8, 0)) < 0) diff --git a/src/pkcs15init/pkcs15-entersafe.c b/src/pkcs15init/pkcs15-entersafe.c index 2087a195..907d7fe4 100644 --- a/src/pkcs15init/pkcs15-entersafe.c +++ b/src/pkcs15init/pkcs15-entersafe.c @@ -406,7 +406,7 @@ static int entersafe_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15ca rsa->modulus.data = gendat.modulus; rsa->modulus.len = kinfo->modulus_length >> 3; /* set the exponent (always 0x10001) */ - buf = (u8 *) malloc(3); + buf = malloc(3); if (!buf) return SC_ERROR_OUT_OF_MEMORY; buf[0] = 0x01; diff --git a/src/pkcs15init/pkcs15-gpk.c b/src/pkcs15init/pkcs15-gpk.c index 76db13d6..f04436c2 100644 --- a/src/pkcs15init/pkcs15-gpk.c +++ b/src/pkcs15init/pkcs15-gpk.c @@ -915,7 +915,7 @@ gpk_add_bignum(struct pkpart *part, unsigned int tag, memset(comp, 0, sizeof(*comp)); comp->tag = tag; comp->size = size + 1; - comp->data = (u8 *) malloc(size + 1); + comp->data = malloc(size + 1); /* Add the tag */ comp->data[0] = tag; @@ -970,7 +970,7 @@ static int gpk_encode_rsa_key(sc_profile_t *profile, sc_card_t *card, unsigned int K = p->bytes / 2; u8 *crtbuf; - crtbuf = (u8 *) malloc(5 * K + 1); + crtbuf = malloc(5 * K + 1); crtbuf[0] = 0x05; gpk_bn2bin(crtbuf + 1 + 0 * K, &rsa->p, K); @@ -1113,7 +1113,7 @@ gpk_read_rsa_key(sc_card_t *card, struct sc_pkcs15_pubkey_rsa *rsa) else continue; bn->len = r - 1; - bn->data = (u8 *) malloc(bn->len); + bn->data = malloc(bn->len); for (m = 0; m < bn->len; m++) bn->data[m] = buffer[bn->len - m]; } diff --git a/src/pkcs15init/pkcs15-incrypto34.c b/src/pkcs15init/pkcs15-incrypto34.c index 17771a31..70a5a4f8 100644 --- a/src/pkcs15init/pkcs15-incrypto34.c +++ b/src/pkcs15init/pkcs15-incrypto34.c @@ -654,7 +654,7 @@ incrypto34_extract_pubkey(sc_card_t *card, int nr, u8 tag, || buf[2] != count + 1 || buf[3] != 0) return SC_ERROR_INTERNAL; bn->len = count; - bn->data = (u8 *) malloc(count); + bn->data = malloc(count); memcpy(bn->data, buf + 4, count); return 0; } diff --git a/src/pkcs15init/pkcs15-jcop.c b/src/pkcs15init/pkcs15-jcop.c index 2b29266f..a1029553 100644 --- a/src/pkcs15init/pkcs15-jcop.c +++ b/src/pkcs15init/pkcs15-jcop.c @@ -310,7 +310,7 @@ jcop_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, args.exponent = 0x10001; sc_append_file_id(&args.pub_file_ref, temppubfile->id); sc_append_file_id(&args.pri_file_ref, keyfile->id); - keybuf=(unsigned char *) malloc(keybits / 8); + keybuf = malloc(keybits / 8); if (!keybuf) { r=SC_ERROR_OUT_OF_MEMORY; goto out; @@ -327,7 +327,7 @@ jcop_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, pubkey->u.rsa.modulus.len = keybits / 8; pubkey->u.rsa.modulus.data = keybuf; pubkey->u.rsa.exponent.len = 3; - pubkey->u.rsa.exponent.data = (u8 *) malloc(3); + pubkey->u.rsa.exponent.data = malloc(3); if (!pubkey->u.rsa.exponent.data) { pubkey->u.rsa.modulus.data = NULL; r=SC_ERROR_OUT_OF_MEMORY; diff --git a/src/pkcs15init/pkcs15-lib.c b/src/pkcs15init/pkcs15-lib.c index 838adb11..b8aba9e1 100644 --- a/src/pkcs15init/pkcs15-lib.c +++ b/src/pkcs15init/pkcs15-lib.c @@ -2576,7 +2576,7 @@ sc_pkcs15init_new_object(int type, struct sc_pkcs15_object *object; unsigned int data_size = 0; - object = (struct sc_pkcs15_object *) calloc(1, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (object == NULL) return NULL; object->type = type; @@ -2845,7 +2845,7 @@ sc_pkcs15init_update_certificate(struct sc_pkcs15_card *p15card, /* Fill the remaining space in the EF (if any) with zeros */ if (certlen < file->size) { - unsigned char *tmp = (unsigned char *) calloc(file->size - certlen, 1); + unsigned char *tmp = calloc(file->size - certlen, 1); if (tmp == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto done; @@ -3531,7 +3531,7 @@ sc_pkcs15init_read_info(struct sc_card *card, struct sc_profile *profile) len = file->size; sc_file_free(file); r = SC_ERROR_OUT_OF_MEMORY; - if ((mem = (u8 *) malloc(len)) != NULL) { + if ((mem = malloc(len)) != NULL) { r = sc_read_binary(card, 0, mem, len, 0); } } else { @@ -3551,7 +3551,7 @@ set_info_string(char **strp, const u8 *p, size_t len) { char *s; - if (!(s = (char *) malloc(len+1))) + if (!(s = malloc(len+1))) return SC_ERROR_OUT_OF_MEMORY; memcpy(s, p, len); s[len] = '\0'; diff --git a/src/pkcs15init/pkcs15-myeid.c b/src/pkcs15init/pkcs15-myeid.c index 8bb97a09..6e1c6fa1 100644 --- a/src/pkcs15init/pkcs15-myeid.c +++ b/src/pkcs15init/pkcs15-myeid.c @@ -667,9 +667,9 @@ myeid_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, pubkey->algorithm = SC_ALGORITHM_RSA; pubkey->u.rsa.modulus.len = (keybits + 7) / 8; - pubkey->u.rsa.modulus.data = (u8 *) malloc(pubkey->u.rsa.modulus.len); + pubkey->u.rsa.modulus.data = malloc(pubkey->u.rsa.modulus.len); pubkey->u.rsa.exponent.len = MYEID_DEFAULT_PUBKEY_LEN; - pubkey->u.rsa.exponent.data = (u8 *) malloc(MYEID_DEFAULT_PUBKEY_LEN); + pubkey->u.rsa.exponent.data = malloc(MYEID_DEFAULT_PUBKEY_LEN); memcpy(pubkey->u.rsa.exponent.data, MYEID_DEFAULT_PUBKEY, MYEID_DEFAULT_PUBKEY_LEN); /* Get public key modulus */ diff --git a/src/pkcs15init/pkcs15-oberthur.c b/src/pkcs15init/pkcs15-oberthur.c index aae5919b..ec67875c 100644 --- a/src/pkcs15init/pkcs15-oberthur.c +++ b/src/pkcs15init/pkcs15-oberthur.c @@ -652,7 +652,7 @@ cosm_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, args.exponent = 0x10001; args.key_bits = key_info->modulus_length; args.pubkey_len = key_info->modulus_length / 8; - args.pubkey = (unsigned char *) malloc(key_info->modulus_length / 8); + args.pubkey = malloc(key_info->modulus_length / 8); if (!args.pubkey) SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate pubkey"); @@ -662,13 +662,13 @@ cosm_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, /* extract public key */ pubkey->algorithm = SC_ALGORITHM_RSA; pubkey->u.rsa.modulus.len = key_info->modulus_length / 8; - pubkey->u.rsa.modulus.data = (unsigned char *) malloc(key_info->modulus_length / 8); + pubkey->u.rsa.modulus.data = malloc(key_info->modulus_length / 8); if (!pubkey->u.rsa.modulus.data) SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate modulus buf"); /* FIXME and if the exponent length is not 3? */ pubkey->u.rsa.exponent.len = 3; - pubkey->u.rsa.exponent.data = (unsigned char *) malloc(3); + pubkey->u.rsa.exponent.data = malloc(3); if (!pubkey->u.rsa.exponent.data) SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate exponent buf"); memcpy(pubkey->u.rsa.exponent.data, "\x01\x00\x01", 3); diff --git a/src/pkcs15init/pkcs15-setcos.c b/src/pkcs15init/pkcs15-setcos.c index 9a5d0c78..e78c78b9 100644 --- a/src/pkcs15init/pkcs15-setcos.c +++ b/src/pkcs15init/pkcs15-setcos.c @@ -468,9 +468,9 @@ setcos_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, if (pubkey != NULL) { pubkey->algorithm = SC_ALGORITHM_RSA; pubkey->u.rsa.modulus.len = (keybits + 7) / 8; - pubkey->u.rsa.modulus.data = (u8 *) malloc(pubkey->u.rsa.modulus.len); + pubkey->u.rsa.modulus.data = malloc(pubkey->u.rsa.modulus.len); pubkey->u.rsa.exponent.len = SETCOS_DEFAULT_PUBKEY_LEN; - pubkey->u.rsa.exponent.data = (u8 *) malloc(SETCOS_DEFAULT_PUBKEY_LEN); + pubkey->u.rsa.exponent.data = malloc(SETCOS_DEFAULT_PUBKEY_LEN); memcpy(pubkey->u.rsa.exponent.data, SETCOS_DEFAULT_PUBKEY, SETCOS_DEFAULT_PUBKEY_LEN); /* Get public key modulus */ diff --git a/src/pkcs15init/pkcs15-starcos.c b/src/pkcs15init/pkcs15-starcos.c index 32fedd26..416ddd82 100644 --- a/src/pkcs15init/pkcs15-starcos.c +++ b/src/pkcs15init/pkcs15-starcos.c @@ -660,7 +660,7 @@ static int starcos_write_pukey(sc_profile_t *profile, sc_card_t *card, return r; len = tfile->size; sc_file_free(tfile); - buf = (u8 *) malloc(len); + buf = malloc(len); if (!buf) return SC_ERROR_OUT_OF_MEMORY; /* read the complete IPF */ @@ -867,7 +867,7 @@ static int starcos_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card rsa->modulus.data = gendat.modulus; rsa->modulus.len = kinfo->modulus_length >> 3; /* set the exponent (always 0x10001) */ - buf = (u8 *) malloc(3); + buf = malloc(3); if (!buf) return SC_ERROR_OUT_OF_MEMORY; buf[0] = 0x01; diff --git a/src/pkcs15init/profile.c b/src/pkcs15init/profile.c index f5a1f8cf..84d702bc 100644 --- a/src/pkcs15init/profile.c +++ b/src/pkcs15init/profile.c @@ -269,7 +269,7 @@ sc_profile_new(void) struct sc_pkcs15_card *p15card; struct sc_profile *pro; - pro = (struct sc_profile *) calloc(1, sizeof(*pro)); + pro = calloc(1, sizeof(*pro)); if (pro == NULL) return NULL; pro->p15_spec = p15card = sc_pkcs15_card_new(); @@ -673,7 +673,7 @@ sc_profile_instantiate_file(sc_profile_t *profile, file_info *ft, struct file_info *fi; sc_card_t *card = profile->card; - fi = (file_info *) calloc(1, sizeof(*fi)); + fi = calloc(1, sizeof(*fi)); if (fi == NULL) return NULL; fi->instance = fi; @@ -874,7 +874,7 @@ new_key(struct sc_profile *profile, unsigned int type, unsigned int ref) return ai; } - ai = (struct auth_info *) calloc(1, sizeof(*ai)); + ai = calloc(1, sizeof(*ai)); if (ai == NULL) return NULL; ai->type = type; @@ -1018,13 +1018,13 @@ process_tmpl(struct state *cur, struct block *info, return 1; } - templ = (sc_profile_t *) calloc(1, sizeof(*templ)); + templ = calloc(1, sizeof(*templ)); if (templ == NULL) { parse_error(cur, "memory allocation failed"); return 1; } - tinfo = (sc_template_t *) calloc(1, sizeof(*tinfo)); + tinfo = calloc(1, sizeof(*tinfo)); if (tinfo == NULL) { parse_error(cur, "memory allocation failed"); free(templ); @@ -1074,7 +1074,7 @@ add_file(sc_profile_t *profile, const char *name, { file_info *info; - info = (struct file_info *) calloc(1, sizeof(*info)); + info = calloc(1, sizeof(*info)); if (info == NULL) return NULL; info->instance = info; @@ -1371,7 +1371,7 @@ new_pin(struct sc_profile *profile, int id) * are usually created before we've read the card specific * profile */ - pi = (struct pin_info *) calloc(1, sizeof(*pi)); + pi = calloc(1, sizeof(*pi)); if (pi == NULL) return NULL; pi->id = id; @@ -1539,7 +1539,7 @@ new_macro(sc_profile_t *profile, const char *name, scconf_list *value) sc_macro_t *mac; if ((mac = find_macro(profile, name)) == NULL) { - mac = (sc_macro_t *) calloc(1, sizeof(*mac)); + mac = calloc(1, sizeof(*mac)); if (mac == NULL) return; mac->name = strdup(name); diff --git a/src/scconf/parse.c b/src/scconf/parse.c index a2762958..d2dbb329 100644 --- a/src/scconf/parse.c +++ b/src/scconf/parse.c @@ -106,7 +106,7 @@ static scconf_item *scconf_item_add_internal(scconf_parser * parser, int type) return item; } } - item = (scconf_item *) malloc(sizeof(scconf_item)); + item = malloc(sizeof(scconf_item)); if (!item) { return NULL; } @@ -173,7 +173,7 @@ static void scconf_block_add_internal(scconf_parser * parser) item = scconf_item_add_internal(parser, SCCONF_ITEM_TYPE_BLOCK); - block = (scconf_block *) malloc(sizeof(scconf_block)); + block = malloc(sizeof(scconf_block)); if (!block) { return; } diff --git a/src/scconf/scconf.c b/src/scconf/scconf.c index 03dcaace..6596cb4c 100644 --- a/src/scconf/scconf.c +++ b/src/scconf/scconf.c @@ -35,13 +35,13 @@ scconf_context *scconf_new(const char *filename) { scconf_context *config; - config = (scconf_context *) malloc(sizeof(scconf_context)); + config = malloc(sizeof(scconf_context)); if (!config) { return NULL; } memset(config, 0, sizeof(scconf_context)); config->filename = filename ? strdup(filename) : NULL; - config->root = (scconf_block *) malloc(sizeof(scconf_block)); + config->root = malloc(sizeof(scconf_block)); if (!config->root) { if (config->filename) { free(config->filename); @@ -178,7 +178,7 @@ int scconf_put_int(scconf_block * block, const char *option, int value) { char *str; - str = (char *) malloc(64); + str = malloc(64); if (!str) { return value; } @@ -200,7 +200,7 @@ scconf_item *scconf_item_copy(const scconf_item * src, scconf_item ** dst) { scconf_item *ptr, *_dst = NULL, *next = NULL; - next = (scconf_item *) malloc(sizeof(scconf_item)); + next = malloc(sizeof(scconf_item)); if (!next) { return NULL; } @@ -209,7 +209,7 @@ scconf_item *scconf_item_copy(const scconf_item * src, scconf_item ** dst) _dst = next; while (src) { if (!next) { - next = (scconf_item *) malloc(sizeof(scconf_item)); + next = malloc(sizeof(scconf_item)); if (!next) { scconf_item_destroy(ptr); return NULL; @@ -274,7 +274,7 @@ scconf_block *scconf_block_copy(const scconf_block * src, scconf_block ** dst) if (src) { scconf_block *_dst = NULL; - _dst = (scconf_block *) malloc(sizeof(scconf_block)); + _dst = malloc(sizeof(scconf_block)); if (!_dst) { return NULL; } @@ -304,7 +304,7 @@ scconf_list *scconf_list_add(scconf_list ** list, const char *value) { scconf_list *rec, **tmp; - rec = (scconf_list *) malloc(sizeof(scconf_list)); + rec = malloc(sizeof(scconf_list)); if (!rec) { return NULL; } @@ -378,7 +378,7 @@ const char **scconf_list_toarray(const scconf_list * list) len++; lp = lp->next; } - tp = (const char **)malloc(sizeof(char *) * (len + 1)); + tp = malloc(sizeof(char *) * (len + 1)); if (!tp) return tp; lp = list; @@ -404,7 +404,7 @@ char *scconf_list_strdup(const scconf_list * list, const char *filler) if (filler) { len += scconf_list_array_length(list) * (strlen(filler) + 1); } - buf = (char *) malloc(len); + buf = malloc(len); if (!buf) { return NULL; } @@ -542,7 +542,7 @@ static int parse_type(const scconf_context * config, const scconf_block * block, if (parm) { if (entry->flags & SCCONF_ALLOC) { char **buf = (char **) parm; - *buf = (char *) malloc(vallen + 1); + *buf = malloc(vallen + 1); if (*buf == NULL) { r = 1; break; diff --git a/src/scconf/sclex.c b/src/scconf/sclex.c index fa151404..c8bc05b9 100644 --- a/src/scconf/sclex.c +++ b/src/scconf/sclex.c @@ -44,7 +44,7 @@ static void buf_init(BUFHAN * bp, FILE * fp, const char *saved_string) { bp->fp = fp; bp->saved_char = 0; - bp->buf = (char *) malloc(256); + bp->buf = malloc(256); bp->bufmax = 256; bp->bufcur = 0; bp->buf[0] = '\0'; diff --git a/src/scconf/write.c b/src/scconf/write.c index 265c31bd..9c963e54 100644 --- a/src/scconf/write.c +++ b/src/scconf/write.c @@ -141,7 +141,7 @@ static void scconf_write_items(scconf_writer * writer, const scconf_block * bloc /* header */ name = scconf_list_get_string(subblock->name); datalen = strlen(item->key) + strlen(name) + 6; - data = (char *) malloc(datalen); + data = malloc(datalen); if (!data) { free(name); continue; @@ -162,7 +162,7 @@ static void scconf_write_items(scconf_writer * writer, const scconf_block * bloc case SCCONF_ITEM_TYPE_VALUE: name = scconf_list_get_string(item->value.list); datalen = strlen(item->key) + strlen(name) + 6; - data = (char *) malloc(datalen); + data = malloc(datalen); if (!data) { free(name); continue; diff --git a/src/tests/p15dump.c b/src/tests/p15dump.c index 7f17b75b..5c93a93b 100644 --- a/src/tests/p15dump.c +++ b/src/tests/p15dump.c @@ -39,7 +39,7 @@ static int dump_objects(const char *what, int type) } printf("%u found.\n", count); - objs = (struct sc_pkcs15_object **) calloc(count, sizeof(*objs)); + objs = calloc(count, sizeof(*objs)); if ((count = sc_pkcs15_get_objects(p15card, type, objs, count)) < 0) { fprintf(stderr, "Error enumerating %s: %s\n", what, sc_strerror(count)); diff --git a/src/tests/pintest.c b/src/tests/pintest.c index 9ed47132..06afa4b7 100644 --- a/src/tests/pintest.c +++ b/src/tests/pintest.c @@ -35,7 +35,7 @@ static int enum_pins(struct sc_pkcs15_object ***ret) fprintf(stderr, "No PIN codes found!\n"); return 0; } - objs = (struct sc_pkcs15_object **) calloc(n, sizeof(*objs)); + objs = calloc(n, sizeof(*objs)); sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, n); for (i = 0; i < n; i++) { sc_test_print_object(objs[i]); diff --git a/src/tools/cryptoflex-tool.c b/src/tools/cryptoflex-tool.c index f2fd5137..4e0a6ddf 100644 --- a/src/tools/cryptoflex-tool.c +++ b/src/tools/cryptoflex-tool.c @@ -99,7 +99,7 @@ static char *getpin(const char *prompt) pass[i] = 0; if (strlen(pass) == 0) return NULL; - buf = (char *) malloc(8); + buf = malloc(8); if (buf == NULL) return NULL; if (strlen(pass) > 8) { diff --git a/src/tools/opensc-tool.c b/src/tools/opensc-tool.c index 63450935..bc51ef8b 100644 --- a/src/tools/opensc-tool.c +++ b/src/tools/opensc-tool.c @@ -384,7 +384,7 @@ static int print_file(sc_card_t *in_card, const sc_file_t *file, if (file->ef_structure == SC_FILE_EF_TRANSPARENT) { unsigned char *buf; - if (!(buf = (unsigned char *) malloc(file->size))) { + if (!(buf = malloc(file->size))) { fprintf(stderr, "out of memory"); return 1; } diff --git a/src/tools/piv-tool.c b/src/tools/piv-tool.c index 89d7b0a5..f4f3d80b 100644 --- a/src/tools/piv-tool.c +++ b/src/tools/piv-tool.c @@ -188,7 +188,7 @@ static int load_cert(const char * cert_id, const char * cert_file, } derlen = i2d_X509(cert, NULL); - der = (u8 *) malloc(derlen); + der = malloc(derlen); p = der; i2d_X509(cert, &p); } diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c index 1f0e8111..31ac2b82 100644 --- a/src/tools/pkcs11-tool.c +++ b/src/tools/pkcs11-tool.c @@ -713,7 +713,7 @@ static void list_slots(int tokens, int refresh, int print) rv = p11->C_GetSlotList(tokens, NULL, &p11_num_slots); if (rv != CKR_OK) p11_fatal("C_GetSlotList(NULL)", rv); - p11_slots = (CK_SLOT_ID *) calloc(p11_num_slots, sizeof(CK_SLOT_ID)); + p11_slots = calloc(p11_num_slots, sizeof(CK_SLOT_ID)); if (p11_slots == NULL) { perror("calloc failed"); return; @@ -2109,7 +2109,7 @@ static CK_ULONG get_mechanisms(CK_SLOT_ID slot, CK_MECHANISM_TYPE_PTR *pList, CK_RV rv; rv = p11->C_GetMechanismList(slot, *pList, &ulCount); - *pList = (CK_MECHANISM_TYPE *) calloc(ulCount, sizeof(*pList)); + *pList = calloc(ulCount, sizeof(*pList)); if (*pList == NULL) util_fatal("calloc failed: %m"); diff --git a/src/tools/pkcs15-init.c b/src/tools/pkcs15-init.c index 63927ed5..d75a8eaf 100644 --- a/src/tools/pkcs15-init.c +++ b/src/tools/pkcs15-init.c @@ -2157,7 +2157,7 @@ do_read_data_object(const char *name, u8 **out, size_t *outlen) size_t filesize = determine_filesize(name); int c; - *out = (u8 *) malloc(filesize); + *out = malloc(filesize); if (*out == NULL) { return SC_ERROR_OUT_OF_MEMORY; } @@ -2184,7 +2184,7 @@ do_convert_bignum(sc_pkcs15_bignum_t *dst, const BIGNUM *src) if (src == 0) return 0; dst->len = BN_num_bytes(src); - dst->data = (u8 *) malloc(dst->len); + dst->data = malloc(dst->len); BN_bn2bin(src, dst->data); return 1; } @@ -2333,7 +2333,7 @@ static int do_convert_cert(sc_pkcs15_der_t *der, X509 *cert) u8 *p; der->len = i2d_X509(cert, NULL); - der->value = p = (u8 *) malloc(der->len); + der->value = p = malloc(der->len); i2d_X509(cert, &p); return 0; } diff --git a/src/tools/pkcs15-tool.c b/src/tools/pkcs15-tool.c index 40dfc02e..f71277bd 100644 --- a/src/tools/pkcs15-tool.c +++ b/src/tools/pkcs15-tool.c @@ -247,7 +247,7 @@ print_pem_object(const char *kind, const u8*data, size_t data_len) buf_len += 2 * (buf_len / 64 + 2); /* certain platforms use CRLF */ buf_len += 64; /* slack for checksum etc */ - if (!(buf = (unsigned char *) malloc(buf_len))) { + if (!(buf = malloc(buf_len))) { perror("print_pem_object"); return 1; } diff --git a/src/tools/westcos-tool.c b/src/tools/westcos-tool.c index b6f4f18a..d158f6ea 100644 --- a/src/tools/westcos-tool.c +++ b/src/tools/westcos-tool.c @@ -106,7 +106,7 @@ static int do_convert_bignum(sc_pkcs15_bignum_t *dst, BIGNUM *src) { if (src == 0) return 0; dst->len = BN_num_bytes(src); - dst->data = (u8 *) malloc(dst->len); + dst->data = malloc(dst->len); BN_bn2bin(src, dst->data); return 1; } @@ -297,7 +297,7 @@ static int cert2der(X509 *cert, u8 **value) int len; u8 *p; len = i2d_X509(cert, NULL); - p = *value = (u8*)malloc(len); + p = *value = malloc(len); i2d_X509(cert, &p); return len; } @@ -798,7 +798,7 @@ int main(int argc, char *argv[]) goto out; } - b = (u8*)malloc(file->size); + b = malloc(file->size); if(b == NULL) { printf("Not enougth memory.\n"); @@ -848,7 +848,7 @@ int main(int argc, char *argv[]) goto out; } - b = (u8*)malloc(file->size); + b = malloc(file->size); if(b == NULL) { printf("Not enougth memory.\n");