fixed pointless array comparisons

This commit is contained in:
Frank Morgner 2015-01-28 07:39:35 +01:00
parent bd3cfcf5ef
commit 2e04fa99c1
7 changed files with 10 additions and 19 deletions

View File

@ -883,7 +883,7 @@ static unsigned int pgp_strip_path(sc_card_t *card, const sc_path_t *path)
{
unsigned int start_point = 0;
/* start_point will move through the path string */
if (path->value == NULL || path->len == 0)
if (path->len == 0)
return 0;
/* Ignore 3F00 (MF) at the beginning */

View File

@ -784,8 +784,6 @@ static int piv_find_aid(sc_card_t * card, sc_file_t *aid_file)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
card->ops->process_fci(card, aid_file, apdu.resp+2, apdu.resp[1]);
if (aid_file->name == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NO_CARD_SUPPORT);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, i);
}

View File

@ -161,8 +161,6 @@ static int tcos_construct_fci(const sc_file_t *file,
/* Directory name */
if (file->type == SC_FILE_TYPE_DF) {
if (file->namelen) {
if (file->namelen > 16 || !file->name)
return SC_ERROR_INVALID_ARGUMENTS;
sc_asn1_put_tag(0x84, file->name, file->namelen,
p, 16, &p);
}

View File

@ -782,10 +782,8 @@ awp_encode_key_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *obj
if (obj->type == COSM_TYPE_PUBKEY_RSA || obj->type == COSM_TYPE_PRKEY_RSA)
ki->flags |= COSM_GENERATED;
if (obj->label) {
ki->label.value = (unsigned char *)strdup(obj->label);
ki->label.len = strlen(obj->label);
}
ki->label.value = (unsigned char *)strdup(obj->label);
ki->label.len = strlen(obj->label);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "cosm_encode_key_info() label(%i):%s",ki->label.len, ki->label.value);
/*
@ -1088,10 +1086,8 @@ awp_encode_data_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
di->flags = 0x0000;
if (obj->label) {
di->label.value = (unsigned char *)strdup(obj->label);
di->label.len = strlen(obj->label);
}
di->label.value = (unsigned char *)strdup(obj->label);
di->label.len = strlen(obj->label);
di->app.len = strlen(data_info->app_label);
if (di->app.len) {

View File

@ -4217,7 +4217,7 @@ static void test_kpgen_certwrite(CK_SLOT_ID slot, CK_SESSION_HANDLE session)
return;
tmp = getID(session, priv_key, (CK_ULONG *) &opt_object_id_len);
if (opt_object_id == NULL || opt_object_id_len == 0) {
if (opt_object_id_len == 0) {
printf("ERR: newly generated private key has no (or an empty) CKA_ID\n");
return;
}
@ -4372,7 +4372,7 @@ static void test_ec(CK_SLOT_ID slot, CK_SESSION_HANDLE session)
return;
tmp = getID(session, priv_key, (CK_ULONG *) &opt_object_id_len);
if (opt_object_id == NULL || opt_object_id_len == 0) {
if (opt_object_id_len == 0) {
printf("ERR: newly generated private key has no (or an empty) CKA_ID\n");
return;
}

View File

@ -1010,8 +1010,7 @@ is_cacert_already_present(struct sc_pkcs15init_certargs *args)
if (!cinfo->authority)
continue;
if (args->label && objs[i]->label
&& strcmp(args->label, objs[i]->label))
if (strcmp(args->label, objs[i]->label))
continue;
/* XXX we should also match the usage field here */
@ -2839,7 +2838,7 @@ static int verify_pin(struct sc_pkcs15_card *p15card, char *auth_id_str)
if (opt_no_prompt)
return SC_ERROR_OBJECT_NOT_FOUND;
if (pin_obj->label)
if (0 < strnlen(pin_obj->label, sizeof pin_obj->label))
snprintf(pin_label, sizeof(pin_label), "User PIN [%s]", pin_obj->label);
else
snprintf(pin_label, sizeof(pin_label), "User PIN");

View File

@ -455,7 +455,7 @@ static int list_data_objects(void)
int idx;
struct sc_pkcs15_data_info *cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
if (objs[i]->label)
if (0 < strnlen(objs[i]->label, sizeof objs[i]->label))
printf("Data object '%s'\n", objs[i]->label);
else
printf("Data object <%i>\n", i);