fixed compiler warnings

This commit is contained in:
Frank Morgner 2017-08-02 23:12:58 +02:00
parent 189368e49f
commit 04a7075290
27 changed files with 68 additions and 43 deletions

View File

@ -133,8 +133,8 @@ case "${host}" in
;; ;;
esac esac
AX_CHECK_COMPILE_FLAG(-Wno-error=unused-but-set-variable, [have_unused_but_set_variable="yes"], [have_unused_but_set_variable="no"], [-Werror -Wunknown-warning-option]) AX_CHECK_COMPILE_FLAG(-Wunknown-warning-option, [have_unknown_warning_option="yes"], [have_unknown_warning_option="no"], [-Werror])
AM_CONDITIONAL([HAVE_UNUSED_BUT_SET_VARIABLE], [test "${have_unused_but_set_variable}" = "yes"]) AM_CONDITIONAL([HAVE_UNKNOWN_WARNING_OPTION], [test "${have_unknown_warning_option}" = "yes"])
AC_ARG_ENABLE( AC_ARG_ENABLE(
[strict], [strict],

View File

@ -7,14 +7,20 @@
#if defined(_MSC_VER) && (_MSC_VER >= 1900) #if defined(_MSC_VER) && (_MSC_VER >= 1900)
// needed for OpenSSL static link // needed for OpenSSL static link
// only for vs 2015 or later // only for vs 2015 or later
//
// this is a horrible hack, the correct fix would be to recompile OpenSSL with
// VS 2015 or later. However, since in OpenSC, we don't need OpenSSL to send
// output to any of these buffers, we don't need to cope with runtime errors
// induced by this hack. See https://stackoverflow.com/a/34655235 for details.
//
#pragma comment(lib, "legacy_stdio_definitions.lib") #pragma comment(lib, "legacy_stdio_definitions.lib")
#include <stdio.h> #include <stdio.h>
FILE * __cdecl __iob_func(void) FILE * __cdecl __iob_func(void)
{ {
static FILE *my_iob[3]; static FILE my_iob[3];
my_iob[0] = stdin; my_iob[0] = *stdin;
my_iob[1] = stdout; my_iob[1] = *stdout;
my_iob[2] = stderr; my_iob[2] = *stderr;
return my_iob; return my_iob;
} }
#endif #endif

View File

@ -559,8 +559,8 @@ static int cardos_set_file_attributes(sc_card_t *card, sc_file_t *file)
status[0] = 0x01; status[0] = 0x01;
if (file->type == SC_FILE_TYPE_DF) { if (file->type == SC_FILE_TYPE_DF) {
status[1] = file->size >> 8; status[1] = (file->size >> 8) & 0xFF;
status[2] = file->size; status[2] = file->size & 0xFF;
} else { } else {
status[1] = status[2] = 0x00; /* not used */ status[1] = status[2] = 0x00; /* not used */
} }

View File

@ -805,15 +805,15 @@ static int sc_hsm_write_ef(sc_card_t *card,
*p++ = idx & 0xFF; *p++ = idx & 0xFF;
*p++ = 0x53; *p++ = 0x53;
if (count < 128) { if (count < 128) {
*p++ = count; *p++ = (u8) count;
len = 6; len = 6;
} else if (count < 256) { } else if (count < 256) {
*p++ = 0x81; *p++ = 0x81;
*p++ = count; *p++ = (u8) count;
len = 7; len = 7;
} else { } else {
*p++ = 0x82; *p++ = 0x82;
*p++ = count >> 8; *p++ = (count >> 8) & 0xFF;
*p++ = count & 0xFF; *p++ = count & 0xFF;
len = 8; len = 8;
} }
@ -1199,8 +1199,11 @@ static int sc_hsm_initialize(sc_card_t *card, sc_cardctl_sc_hsm_init_param_t *pa
memcpy(p, params->options, 2); memcpy(p, params->options, 2);
p += 2; p += 2;
if (params->user_pin_len > 0xFF) {
return SC_ERROR_INVALID_ARGUMENTS;
}
*p++ = 0x81; // User PIN *p++ = 0x81; // User PIN
*p++ = params->user_pin_len; *p++ = (u8) params->user_pin_len;
memcpy(p, params->user_pin, params->user_pin_len); memcpy(p, params->user_pin, params->user_pin_len);
p += params->user_pin_len; p += params->user_pin_len;

View File

@ -21,8 +21,9 @@
#include "config.h" #include "config.h"
#endif #endif
#include "internal.h"
#include "asn1.h" #include "asn1.h"
#include "internal.h"
#include <stdlib.h>
static int static int
sc_parse_ef_gdo_content(const unsigned char *gdo, size_t gdo_len, sc_parse_ef_gdo_content(const unsigned char *gdo, size_t gdo_len,

View File

@ -828,8 +828,10 @@ iso7816_set_security_env(struct sc_card *card,
*p++ = env->algorithm_ref & 0xFF; *p++ = env->algorithm_ref & 0xFF;
} }
if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) { if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
if (env->file_ref.len > 0xFF)
return SC_ERROR_INVALID_ARGUMENTS;
*p++ = 0x81; *p++ = 0x81;
*p++ = env->file_ref.len; *p++ = (u8) env->file_ref.len;
assert(sizeof(sbuf) - (p - sbuf) >= env->file_ref.len); assert(sizeof(sbuf) - (p - sbuf) >= env->file_ref.len);
memcpy(p, env->file_ref.value, env->file_ref.len); memcpy(p, env->file_ref.value, env->file_ref.len);
p += env->file_ref.len; p += env->file_ref.len;
@ -839,7 +841,9 @@ iso7816_set_security_env(struct sc_card *card,
*p++ = 0x83; *p++ = 0x83;
else else
*p++ = 0x84; *p++ = 0x84;
*p++ = env->key_ref_len; if (env->key_ref_len > 0xFF)
return SC_ERROR_INVALID_ARGUMENTS;
*p++ = env->key_ref_len & 0xFF;
assert(sizeof(sbuf) - (p - sbuf) >= env->key_ref_len); assert(sizeof(sbuf) - (p - sbuf) >= env->key_ref_len);
memcpy(p, env->key_ref, env->key_ref_len); memcpy(p, env->key_ref, env->key_ref_len);
p += env->key_ref_len; p += env->key_ref_len;

View File

@ -494,7 +494,7 @@ static int escape_pin_cmd_to_buf(sc_context_t *ctx,
/* GLP PIN length is encoded in 4 bits and block size is always 8 bytes */ /* GLP PIN length is encoded in 4 bits and block size is always 8 bytes */
bmPINBlockString = 0x40 | 0x08; bmPINBlockString = 0x40 | 0x08;
} else if (pin_ref->encoding == SC_PIN_ENCODING_ASCII && data->flags & SC_PIN_CMD_NEED_PADDING) { } else if (pin_ref->encoding == SC_PIN_ENCODING_ASCII && data->flags & SC_PIN_CMD_NEED_PADDING) {
bmPINBlockString = pin_ref->pad_length; bmPINBlockString = (uint8_t) pin_ref->pad_length;
} else { } else {
bmPINBlockString = 0x00; bmPINBlockString = 0x00;
} }
@ -566,11 +566,11 @@ static int escape_pin_cmd_to_buf(sc_context_t *ctx,
modify->bmPINLengthFormat = bmPINLengthFormat; modify->bmPINLengthFormat = bmPINLengthFormat;
if (!(data->flags & SC_PIN_CMD_IMPLICIT_CHANGE) if (!(data->flags & SC_PIN_CMD_IMPLICIT_CHANGE)
&& data->pin1.offset) { && data->pin1.offset) {
modify->bInsertionOffsetOld = data->pin1.offset - 5; modify->bInsertionOffsetOld = (uint8_t) data->pin1.offset - 5;
} else { } else {
modify->bInsertionOffsetOld = 0; modify->bInsertionOffsetOld = 0;
} }
modify->bInsertionOffsetNew = data->pin2.offset ? data->pin2.offset - 5 : 0; modify->bInsertionOffsetNew = data->pin2.offset ? (uint8_t) data->pin2.offset - 5 : 0;
modify->wPINMaxExtraDigit = wPINMaxExtraDigit; modify->wPINMaxExtraDigit = wPINMaxExtraDigit;
modify->bConfirmPIN = CCID_PIN_CONFIRM_NEW modify->bConfirmPIN = CCID_PIN_CONFIRM_NEW
| (data->flags & SC_PIN_CMD_IMPLICIT_CHANGE ? 0 : CCID_PIN_INSERT_OLD); | (data->flags & SC_PIN_CMD_IMPLICIT_CHANGE ? 0 : CCID_PIN_INSERT_OLD);

View File

@ -244,7 +244,7 @@ int sc_build_pin(u8 *buf, size_t buflen, struct sc_pin_cmd_pin *pin, int pad)
if (pin->data[i] < '0' || pin->data[i] > '9') if (pin->data[i] < '0' || pin->data[i] > '9')
return SC_ERROR_INVALID_ARGUMENTS; return SC_ERROR_INVALID_ARGUMENTS;
} }
buf[0] = 0x20 | pin_len; buf[0] = 0x20 | (u8) pin_len;
buf++; buf++;
buflen--; buflen--;
} }

View File

@ -2864,7 +2864,7 @@ static const char *md_get_ui_str(PCARD_DATA pCardData, enum ui_str id)
return str; return str;
} }
static INT_PTR CALLBACK md_dialog_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData) static HRESULT CALLBACK md_dialog_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData)
{ {
LONG_PTR param; LONG_PTR param;
int timeout; int timeout;

View File

@ -175,6 +175,7 @@ static const struct {
const CK_BYTE gostr3411_94_cryptopro_paramset_encoded_oid[] = { 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x1e, 0x01 }; const CK_BYTE gostr3411_94_cryptopro_paramset_encoded_oid[] = { 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x1e, 0x01 };
const unsigned int gostr3411_94_cryptopro_paramset_oid[] = {1, 2, 643, 2, 2, 30, 1, (unsigned int)-1}; const unsigned int gostr3411_94_cryptopro_paramset_oid[] = {1, 2, 643, 2, 2, 30, 1, (unsigned int)-1};
#ifdef USE_PKCS15_INIT
static const struct { static const struct {
const CK_BYTE *encoded_oid; const CK_BYTE *encoded_oid;
const unsigned int encoded_oid_size; const unsigned int encoded_oid_size;
@ -186,6 +187,7 @@ static const struct {
&gostr3411_94_cryptopro_paramset_oid[0], &gostr3411_94_cryptopro_paramset_oid[0],
sizeof(gostr3411_94_cryptopro_paramset_oid)} sizeof(gostr3411_94_cryptopro_paramset_oid)}
}; };
#endif
static int __pkcs15_release_object(struct pkcs15_any_object *); static int __pkcs15_release_object(struct pkcs15_any_object *);
static CK_RV register_mechanisms(struct sc_pkcs11_card *p11card); static CK_RV register_mechanisms(struct sc_pkcs11_card *p11card);
@ -978,7 +980,7 @@ pkcs15_add_object(struct sc_pkcs11_slot *slot, struct pkcs15_any_object *obj,
unsigned int i; unsigned int i;
struct pkcs15_fw_data *card_fw_data; struct pkcs15_fw_data *card_fw_data;
CK_OBJECT_HANDLE handle = CK_OBJECT_HANDLE handle =
(CK_OBJECT_HANDLE)obj; /* cast pointer to long, will truncate on Win64 */ (CK_OBJECT_HANDLE)(uintptr_t)obj; /* cast pointer to long, will truncate on Win64 */
if (obj == NULL || slot == NULL) if (obj == NULL || slot == NULL)
return; return;

View File

@ -1684,8 +1684,9 @@ static int npa_gen_auth_ca(sc_card_t *card, const BUF_MEM *eph_pub_key,
} }
c_data->eph_pub_key = ASN1_OCTET_STRING_new(); c_data->eph_pub_key = ASN1_OCTET_STRING_new();
if (!c_data->eph_pub_key if (!c_data->eph_pub_key
|| !ASN1_OCTET_STRING_set( c_data->eph_pub_key, || !ASN1_OCTET_STRING_set(c_data->eph_pub_key,
eph_pub_key->data, eph_pub_key->length)) { (const unsigned char *) eph_pub_key->data,
eph_pub_key->length)) {
ssl_error(card->ctx); ssl_error(card->ctx);
r = SC_ERROR_INTERNAL; r = SC_ERROR_INTERNAL;
goto err; goto err;

View File

@ -156,15 +156,15 @@ static int format_le(size_t le, struct sc_asn1_entry *le_entry,
switch (*le_len) { switch (*le_len) {
case 1: case 1:
p[0] = le; p[0] = le & 0xff;
break; break;
case 2: case 2:
p[0] = le >> 8; p[0] = (le >> 8) & 0xff;
p[1] = le & 0xff; p[1] = le & 0xff;
break; break;
case 3: case 3:
p[0] = 0x00; p[0] = 0x00;
p[1] = le >> 8; p[1] = (le >> 8) & 0xff;
p[2] = le & 0xff; p[2] = le & 0xff;
break; break;
default: default:

View File

@ -113,7 +113,10 @@ npa-tool.1:
opensc_notify_SOURCES = opensc-notify.c $(OPENSC_NOTIFY_BUILT_SOURCES) opensc_notify_SOURCES = opensc-notify.c $(OPENSC_NOTIFY_BUILT_SOURCES)
opensc_notify_LDADD = $(top_builddir)/src/libopensc/libopensc.la $(OPTIONAL_NOTIFY_LIBS) opensc_notify_LDADD = $(top_builddir)/src/libopensc/libopensc.la $(OPTIONAL_NOTIFY_LIBS)
opensc_notify_CFLAGS = -I$(top_srcdir)/src $(OPTIONAL_NOTIFY_CFLAGS) opensc_notify_CFLAGS = -I$(top_srcdir)/src $(OPTIONAL_NOTIFY_CFLAGS)
opensc_notify_CFLAGS += -Wno-unused-but-set-variable -Wno-unknown-warning-option opensc_notify_CFLAGS += -Wno-unused-but-set-variable
if HAVE_UNKNOWN_WARNING_OPTION
opensc_notify_CFLAGS += -Wno-unknown-warning-option
endif
opensc-notify.c: $(abs_builddir)/opensc-notify.ggo $(OPENSC_NOTIFY_BUILT_SOURCES) opensc-notify.c: $(abs_builddir)/opensc-notify.ggo $(OPENSC_NOTIFY_BUILT_SOURCES)
@ -137,7 +140,10 @@ opensc-notify.1:
egk_tool_SOURCES = egk-tool.c $(EGK_TOOL_BUILT_SOURCES) egk_tool_SOURCES = egk-tool.c $(EGK_TOOL_BUILT_SOURCES)
egk_tool_LDADD = $(top_builddir)/src/libopensc/libopensc.la $(OPTIONAL_ZLIB_LIBS) egk_tool_LDADD = $(top_builddir)/src/libopensc/libopensc.la $(OPTIONAL_ZLIB_LIBS)
egk_tool_CFLAGS = -I$(top_srcdir)/src $(OPTIONAL_ZLIB_CFLAGS) egk_tool_CFLAGS = -I$(top_srcdir)/src $(OPTIONAL_ZLIB_CFLAGS)
egk_tool_CFLAGS += -Wno-unused-but-set-variable -Wno-unknown-warning-option egk_tool_CFLAGS += -Wno-unused-but-set-variable
if HAVE_UNKNOWN_WARNING_OPTION
egk_tool_CFLAGS += -Wno-unknown-warning-option
endif
egk-tool.c: $(abs_builddir)/egk-tool.ggo $(EGK_TOOL_BUILT_SOURCES) egk-tool.c: $(abs_builddir)/egk-tool.ggo $(EGK_TOOL_BUILT_SOURCES)

View File

@ -1027,7 +1027,7 @@ static int cardos_change_startkey(const char *change_startkey_apdu) {
} }
#endif #endif
int main(int argc, char *const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int do_info = 0; int do_info = 0;

View File

@ -978,7 +978,7 @@ static int create_pin(void)
return create_pin_file(&path, opt_pin_num, ""); return create_pin_file(&path, opt_pin_num, "");
} }
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int action_count = 0; int action_count = 0;

View File

@ -60,8 +60,8 @@ int uncompress_gzip(void* uncompressed, size_t *uncompressed_len,
return SC_SUCCESS; return SC_SUCCESS;
} }
#else #else
int uncompress_gzip(const void* compressed, size_t compressed_len, int uncompress_gzip(void* uncompressed, size_t *uncompressed_len,
void* uncompressed, size_t *uncompressed_len) const void* compressed, size_t compressed_len)
{ {
return SC_ERROR_NOT_SUPPORTED; return SC_ERROR_NOT_SUPPORTED;
} }
@ -196,7 +196,7 @@ main (int argc, char **argv)
struct gengetopt_args_info cmdline; struct gengetopt_args_info cmdline;
struct sc_path path; struct sc_path path;
struct sc_context *ctx; struct sc_context *ctx;
struct sc_reader *reader; struct sc_reader *reader = NULL;
struct sc_card *card; struct sc_card *card;
unsigned char *data = NULL; unsigned char *data = NULL;
size_t data_len = 0; size_t data_len = 0;

View File

@ -23,6 +23,8 @@
#include <stdio.h> #include <stdio.h>
#ifndef _WIN32 #ifndef _WIN32
#include <unistd.h> #include <unistd.h>
#else
#include <process.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -466,7 +466,7 @@ static int print_info(sc_card_t *card) {
return SC_SUCCESS; return SC_SUCCESS;
} }
int main(int argc, char * const argv[]) int main(int argc, char * argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int action_count = 0; int action_count = 0;

View File

@ -197,7 +197,7 @@ static int list_apps(FILE *fout)
return 0; return 0;
} }
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int do_list_sdos = 0; int do_list_sdos = 0;

View File

@ -1867,7 +1867,7 @@ static char *read_cmdline(FILE *script, char *prompt)
return buf; return buf;
} }
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int r, c, long_optind = 0, err = 0; int r, c, long_optind = 0, err = 0;
char *line; char *line;

View File

@ -173,7 +173,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowC
LPWSTR *wargv = NULL; LPWSTR *wargv = NULL;
char **argv = NULL; char **argv = NULL;
int argc = 0, i; int argc = 0, i;
struct gengetopt_args_info cmdline;
wargv = CommandLineToArgvW(GetCommandLineW(), &argc); wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (wargv == NULL) { if (wargv == NULL) {

View File

@ -668,7 +668,7 @@ static int card_reset(const char *reset_type)
return 0; return 0;
} }
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int do_info = 0; int do_info = 0;

View File

@ -459,7 +459,7 @@ static void print_serial(sc_card_t *in_card)
util_hex_dump_asc(stdout, serial.value, serial.len, -1); util_hex_dump_asc(stdout, serial.value, serial.len, -1);
} }
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int do_send_apdu = 0; int do_send_apdu = 0;

View File

@ -352,7 +352,7 @@ static int get_key(unsigned int usage, sc_pkcs15_object_t **result)
return 0; return 0;
} }
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int do_decipher = 0; int do_decipher = 0;

View File

@ -2031,7 +2031,7 @@ end:
return 0; return 0;
} }
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int do_read_cert = 0; int do_read_cert = 0;

View File

@ -1654,7 +1654,7 @@ static int unwrap_key(sc_card_t *card, int keyid, const char *inf, const char *p
int main(int argc, char * const argv[]) int main(int argc, char *argv[])
{ {
int err = 0, r, c, long_optind = 0; int err = 0, r, c, long_optind = 0;
int action_count = 0; int action_count = 0;

View File

@ -20,8 +20,9 @@
#include "libopensc/internal.h" #include "libopensc/internal.h"
#include "ui/strings.h" #include "ui/strings.h"
#include <string.h>
#include <locale.h> #include <locale.h>
#include <stdlib.h>
#include <string.h>
enum ui_langs { enum ui_langs {
EN, EN,