Skip to content

Commit

Permalink
Fixed warining reported by MSVC compiler (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx authored and antonsviridenko committed Aug 1, 2023
1 parent ce57bbc commit 0e46e67
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
-DCRYPTO_BACKEND=${{ matrix.backend }} \
-DCMAKE_PREFIX_PATH=${{ env.VCPKG_DIR }}/installed/${{ matrix.arch.triplet }} .
- name: Compile
- name: Build
shell: bash
run: |
export PATH=${{ env.VCPKG_DIR_U }}/installed/${{ matrix.arch.triplet }}/bin:$PATH
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ if(NOT MSVC)
)
endif(NOT MSVC)

# THis works both for MSVC and CL on Windows
# This works both for MSVC and CL on Windows
if(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
endif(WIN32)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/crypto.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2020, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2017-2023, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -128,7 +128,9 @@ pgp_generate_seckey(const rnp_keygen_crypto_params_t &crypto,
seckey.material.ec.curve = crypto.ecc.curve;
break;
}
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
case PGP_PKA_ECDSA:
case PGP_PKA_SM2:
if (!curve_supported(crypto.ecc.curve)) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/crypto/symmetric.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2017-2023, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -224,7 +224,7 @@ pgp_cipher_cfb_encrypt(pgp_crypt_t *crypt, uint8_t *out, const uint8_t *in, size
uint64_t buf64[512]; // 4KB - page size
uint64_t iv64[2];
size_t blocks, blockb;
unsigned blsize = crypt->blocksize;
size_t blsize = crypt->blocksize;

/* encrypting till the block boundary */
while (bytes && crypt->cfb.remaining) {
Expand Down Expand Up @@ -306,7 +306,7 @@ pgp_cipher_cfb_decrypt(pgp_crypt_t *crypt, uint8_t *out, const uint8_t *in, size
uint64_t outbuf64[512];
uint64_t iv64[2];
size_t blocks, blockb;
unsigned blsize = crypt->blocksize;
size_t blsize = crypt->blocksize;

/* decrypting till the block boundary */
while (bytes && crypt->cfb.remaining) {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/crypto/symmetric_ossl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2021 Ribose Inc.
* Copyright (c) 2021-2023 Ribose Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -149,7 +149,7 @@ pgp_cipher_cfb_encrypt(pgp_crypt_t *crypt, uint8_t *out, const uint8_t *in, size
uint64_t buf64[512]; // 4KB - page size
uint64_t iv64[2];
size_t blocks, blockb;
unsigned blsize = crypt->blocksize;
size_t blsize = crypt->blocksize;

/* encrypting till the block boundary */
while (bytes && crypt->cfb.remaining) {
Expand Down Expand Up @@ -218,7 +218,7 @@ pgp_cipher_cfb_encrypt(pgp_crypt_t *crypt, uint8_t *out, const uint8_t *in, size
int outlen = blsize;
EVP_EncryptUpdate(crypt->cfb.obj, crypt->cfb.iv, &outlen, crypt->cfb.iv, (int) blsize);
if (outlen != (int) blsize) {
RNP_LOG("Bad outlen: must be %u", blsize);
RNP_LOG("Bad outlen: must be %zu", blsize);
}
crypt->cfb.remaining = blsize;

Expand All @@ -243,7 +243,7 @@ pgp_cipher_cfb_decrypt(pgp_crypt_t *crypt, uint8_t *out, const uint8_t *in, size
uint64_t outbuf64[512];
uint64_t iv64[2];
size_t blocks, blockb;
unsigned blsize = crypt->blocksize;
size_t blsize = crypt->blocksize;

/* decrypting till the block boundary */
while (bytes && crypt->cfb.remaining) {
Expand Down Expand Up @@ -315,7 +315,7 @@ pgp_cipher_cfb_decrypt(pgp_crypt_t *crypt, uint8_t *out, const uint8_t *in, size
int outlen = blsize;
EVP_EncryptUpdate(crypt->cfb.obj, crypt->cfb.iv, &outlen, crypt->cfb.iv, (int) blsize);
if (outlen != (int) blsize) {
RNP_LOG("Bad outlen: must be %u", blsize);
RNP_LOG("Bad outlen: must be %zu", blsize);
}
crypt->cfb.remaining = blsize;

Expand Down
5 changes: 4 additions & 1 deletion src/lib/rnp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2017-2021, Ribose Inc.
* Copyright (c) 2017-2023, Ribose Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -7633,7 +7633,10 @@ key_to_json(json_object *jso, rnp_key_handle_t handle, uint32_t flags)
return RNP_ERROR_OUT_OF_MEMORY;
}
}

#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
case PGP_PKA_ECDSA:
case PGP_PKA_EDDSA:
case PGP_PKA_SM2: {
Expand Down
4 changes: 3 additions & 1 deletion src/librepgp/stream-sig.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2022, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2018-2023, [Ribose Inc](https://www.ribose.com).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -1393,7 +1393,9 @@ pgp_signature_t::parse_material(pgp_signature_material_t &material) const
if (version < PGP_V4) {
RNP_LOG("Warning! v3 EdDSA signature.");
}
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
case PGP_PKA_ECDSA:
case PGP_PKA_SM2:
case PGP_PKA_ECDH:
Expand Down
8 changes: 7 additions & 1 deletion src/rnp/rnp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2021 [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2017-2023 [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -297,7 +297,9 @@ setcmd(rnp_cfg &cfg, int cmd, const char *arg)
break;
case CMD_CLEARSIGN:
cfg.set_bool(CFG_CLEARTEXT, true);
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
case CMD_SIGN:
cfg.set_bool(CFG_NEEDSSECKEY, true);
cfg.set_bool(CFG_SIGN_NEEDED, true);
Expand All @@ -314,7 +316,9 @@ setcmd(rnp_cfg &cfg, int cmd, const char *arg)
case CMD_VERIFY:
/* single verify will discard output, decrypt will not */
cfg.set_bool(CFG_NO_OUTPUT, true);
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
case CMD_VERIFY_CAT:
newcmd = CMD_PROCESS;
break;
Expand Down Expand Up @@ -588,7 +592,9 @@ set_short_option(rnp_cfg &cfg, int ch, const char *arg)
cfg.set_bool(CFG_KEYSTORE_DISABLED, true);
break;
case 'h':
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
default:
return setcmd(cfg, CMD_HELP, optarg);
}
Expand Down
6 changes: 4 additions & 2 deletions src/rnpkeys/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2017-2023, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -41,7 +41,7 @@
extern struct option options[];
extern const char * usage;

optdefs_t
static optdefs_t
get_short_cmd(int ch)
{
switch (ch) {
Expand All @@ -52,7 +52,9 @@ get_short_cmd(int ch)
case 'l':
return CMD_LIST_KEYS;
case 'h':
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
default:
return CMD_HELP;
}
Expand Down
6 changes: 3 additions & 3 deletions src/rnpkeys/rnpkeys.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2021, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2017-2023, [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -262,8 +262,8 @@ import_keys(cli_rnp_t *rnp, rnp_input_t input, const std::string &inname)
} while (1);

// print statistics
ERR_MSG("Import finished: %lu key%s processed, %lu new public keys, %lu new secret keys, "
"%lu updated, %lu unchanged.",
ERR_MSG("Import finished: %zu key%s processed, %zu new public keys, %zu new secret keys, "
"%zu updated, %zu unchanged.",
processed_keys,
(processed_keys != 1) ? "s" : "",
new_pub_keys.size(),
Expand Down
4 changes: 2 additions & 2 deletions src/tests/ffi-enc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2020-2023 [Ribose Inc](https://www.ribose.com).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -598,7 +598,7 @@ TEST_F(rnp_tests, test_ffi_encrypt_pk)
rnp_ffi_destroy(ffi);
}

bool
static bool
first_key_password_provider(rnp_ffi_t ffi,
void * app_ctx,
rnp_key_handle_t key,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ffi-key.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2022-2023 [Ribose Inc](https://www.ribose.com).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down
6 changes: 4 additions & 2 deletions src/tests/ffi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2020 [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2017-2023 [Ribose Inc](https://www.ribose.com).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -29,6 +29,7 @@
#include <string>
#include <set>
#include <utility>
#include <cstdint>

#include <rnp/rnp.h>
#include "rnp_tests.h"
Expand Down Expand Up @@ -2659,7 +2660,8 @@ TEST_F(rnp_tests, test_ffi_revocations)
assert_rnp_failure(rnp_uid_is_revoked(uid_handle, NULL));
assert_rnp_success(rnp_uid_is_revoked(uid_handle, &revoked));
assert_false(revoked);
rnp_signature_handle_t sig = (rnp_signature_handle_t) 0xdeadbeef;
const uintptr_t p_sig = 0xdeadbeef;
rnp_signature_handle_t sig = reinterpret_cast<rnp_signature_handle_t>(p_sig);
assert_rnp_failure(rnp_uid_get_revocation_signature(NULL, &sig));
assert_rnp_failure(rnp_uid_get_revocation_signature(uid_handle, NULL));
assert_rnp_success(rnp_uid_get_revocation_signature(uid_handle, &sig));
Expand Down
8 changes: 6 additions & 2 deletions src/tests/support.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2019 [Ribose Inc](https://www.ribose.com).
* Copyright (c) 2017-2023 [Ribose Inc](https://www.ribose.com).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -184,6 +184,7 @@ path_mkdir(mode_t mode, const char *first, ...)
assert_int_equal(0, RNP_MKDIR(buffer, mode));
}

#ifndef WINSHELLAPI
static int
remove_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
Expand All @@ -193,6 +194,7 @@ remove_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ft

return ret;
}
#endif

static const char *
get_tmp()
Expand Down Expand Up @@ -737,7 +739,9 @@ check_json_field_bool(json_object *obj, const std::string &field, bool value)
if (!json_object_is_type(fld, json_type_boolean)) {
return false;
}
return json_object_get_boolean(fld) == value;
// 'json_object_get_boolean' returns 'json_bool' which is 'int' on Windows
// but bool on other platforms
return (json_object_get_boolean(fld) ? true : false) == value;
}

bool
Expand Down

0 comments on commit 0e46e67

Please sign in to comment.