From 07818329ab93d0bce94fe6e8db3746f81f8110fb Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Mon, 27 May 2013 12:24:30 +0200 Subject: [PATCH] made sc_apdu_t.data 'const' (which it used to be) fixes a lot of warnings which pass a const buffer to the APDU's data Note that a non-const data member is only required for sc_allocate_apdu sc_free_apdu. They are currently used with an explicit typecast. However, sc_allocate_apdu and sc_free_apdu both are not used once in the entire project. One might also simply throw both functions away. -- Both are thrown away. (VT) --- src/libopensc/card.c | 49 --------------------------------- src/libopensc/libopensc.exports | 2 -- src/libopensc/opensc.h | 3 -- src/libopensc/types.h | 2 +- 4 files changed, 1 insertion(+), 55 deletions(-) diff --git a/src/libopensc/card.c b/src/libopensc/card.c index 5c6b5043..de82d7ec 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -61,55 +61,6 @@ void sc_format_apdu(sc_card_t *card, sc_apdu_t *apdu, apdu->p2 = (u8) p2; } -struct sc_apdu * -sc_allocate_apdu(struct sc_apdu *copy_from, unsigned flags) -{ - struct sc_apdu *apdu = NULL; - - assert(copy_from != NULL); - apdu = (struct sc_apdu *)malloc(sizeof(struct sc_apdu)); - if (!copy_from || !apdu) - return apdu; - memcpy(apdu, copy_from, sizeof(struct sc_apdu)); - apdu->data = apdu->resp = NULL; - apdu->next = NULL; - apdu->datalen = apdu->resplen = 0; - apdu->allocation_flags = SC_APDU_ALLOCATE_FLAG; - - if ((flags & SC_APDU_ALLOCATE_FLAG_DATA) && copy_from->data && copy_from->datalen) { - apdu->data = malloc(copy_from->datalen); - if (!apdu->data) - return NULL; - memcpy(apdu->data, copy_from->data, copy_from->datalen); - apdu->datalen = copy_from->datalen; - apdu->allocation_flags |= SC_APDU_ALLOCATE_FLAG_DATA; - } - - if ((flags & SC_APDU_ALLOCATE_FLAG_RESP) && copy_from->resp && copy_from->resplen) { - apdu->resp = malloc(copy_from->resplen); - if (!apdu->resp) - return NULL; - memcpy(apdu->resp, copy_from->resp, copy_from->resplen); - apdu->resplen = copy_from->resplen; - apdu->allocation_flags |= SC_APDU_ALLOCATE_FLAG_RESP; - } - return apdu; -} - -void -sc_free_apdu(struct sc_apdu *apdu) -{ - if (!apdu) - return; - if (apdu->allocation_flags & SC_APDU_ALLOCATE_FLAG_DATA) - free (apdu->data); - if (apdu->allocation_flags & SC_APDU_ALLOCATE_FLAG_RESP) - free (apdu->resp); - if (apdu->allocation_flags & SC_APDU_ALLOCATE_FLAG) - free (apdu); -} - - static sc_card_t * sc_card_new(sc_context_t *ctx) { sc_card_t *card; diff --git a/src/libopensc/libopensc.exports b/src/libopensc/libopensc.exports index 19a5b427..b3059289 100644 --- a/src/libopensc/libopensc.exports +++ b/src/libopensc/libopensc.exports @@ -99,8 +99,6 @@ sc_file_set_sec_attr sc_file_set_type_attr sc_file_valid sc_format_apdu -sc_allocate_apdu -sc_free_apdu sc_bytes2apdu sc_format_asn1_entry sc_format_oid diff --git a/src/libopensc/opensc.h b/src/libopensc/opensc.h index 660592f3..5de4c125 100644 --- a/src/libopensc/opensc.h +++ b/src/libopensc/opensc.h @@ -726,9 +726,6 @@ void sc_format_apdu(struct sc_card *, struct sc_apdu *, int, int, int, int); int sc_check_apdu(struct sc_card *, const struct sc_apdu *); -struct sc_apdu *sc_allocate_apdu(struct sc_apdu *, unsigned); -void sc_free_apdu(struct sc_apdu *); - /** Transforms an APDU from binary to its @c sc_apdu_t representation * @param ctx sc_context_t object (used for logging) * @param buf APDU to be encoded as an @c sc_apdu_t object diff --git a/src/libopensc/types.h b/src/libopensc/types.h index b79363d2..6db06e99 100644 --- a/src/libopensc/types.h +++ b/src/libopensc/types.h @@ -280,7 +280,7 @@ typedef struct sc_apdu { int cse; /* APDU case */ unsigned char cla, ins, p1, p2; /* CLA, INS, P1 and P2 bytes */ size_t lc, le; /* Lc and Le bytes */ - unsigned char *data; /* C-APDU data */ + const unsigned char *data; /* C-APDU data */ size_t datalen; /* length of data in C-APDU */ unsigned char *resp; /* R-APDU data buffer */ size_t resplen; /* in: size of R-APDU buffer,