Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bunch of coverity issues. #2312

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/crypto/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace dsa {

class Signature {
public:
mpi r;
mpi s;
mpi r{};
mpi s{};
};

class Key {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class Curve {

class Signature {
public:
mpi r;
mpi s;
mpi r{};
mpi s{};
};

class Key {
Expand Down
12 changes: 6 additions & 6 deletions src/lib/crypto/elgamal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Signature {
public:
/* This is kept only for packet reading. Implementation MUST
* not create elgamal signatures */
mpi r;
mpi s;
mpi r{};
mpi s{};
};

class Encrypted {
Expand All @@ -51,11 +51,11 @@ class Encrypted {

class Key {
public:
mpi p;
mpi g;
mpi y;
mpi p{};
mpi g{};
mpi y{};
/* secret mpi */
mpi x;
mpi x{};

void
clear_secret()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/rsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace rsa {

class Signature {
public:
mpi s;
mpi s{};
};

class Encrypted {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4514,7 +4514,7 @@ parse_keygen_common_fields(json_object * jso,
std::string str;
std::vector<std::string> strs;
if (json_get_str(jso, "usage", str)) {
strs.push_back(str);
strs.push_back(std::move(str));
} else {
json_get_str_arr(jso, "usage", strs);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librepgp/stream-ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rnp_ctx_t::add_encryption_password(const std::string &password,
if (!pgp_s2k_derive_key(&info.s2k, password.c_str(), info.key.data(), info.key.size())) {
return RNP_ERROR_GENERIC;
}
passwords.push_back(info);
passwords.push_back(std::move(info));
return RNP_SUCCESS;
}

Expand Down
4 changes: 2 additions & 2 deletions src/librepgp/stream-parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ encrypted_read_packet_data(pgp_source_encrypted_param_t *param)
errors++;
continue;
}
param->symencs.push_back(skey);
param->symencs.push_back(std::move(skey));
break;
}
case PGP_PKT_PK_SESSION_KEY: {
Expand All @@ -2087,7 +2087,7 @@ encrypted_read_packet_data(pgp_source_encrypted_param_t *param)
errors++;
continue;
}
param->pubencs.push_back(pkey);
param->pubencs.push_back(std::move(pkey));
break;
}
case PGP_PKT_SE_DATA:
Expand Down
6 changes: 3 additions & 3 deletions src/librepgp/stream-write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ encrypted_add_password_v4_single(pgp_dest_encrypted_param_t &param,
skey.alg = param.ctx.ealg;
skey.enckeylen = 0;
key.assign(pass.key.data(), pass.key.data() + keylen);
param.skesks.push_back(skey);
param.skesks.push_back(std::move(skey));
}

static bool
Expand All @@ -700,7 +700,7 @@ encrypted_add_password_v4(pgp_dest_encrypted_param_t & param,
}
pgp_cipher_cfb_encrypt(&kcrypt, skey.enckey, skey.enckey, skey.enckeylen);
pgp_cipher_cfb_finish(&kcrypt);
param.skesks.push_back(skey);
param.skesks.push_back(std::move(skey));
return true;
}

Expand Down Expand Up @@ -749,7 +749,7 @@ encrypted_add_password_v5(pgp_dest_encrypted_param_t & param,

pgp_cipher_aead_destroy(&kcrypt);
if (res) {
param.skesks.push_back(skey);
param.skesks.push_back(std::move(skey));
}
return res;
#endif
Expand Down
10 changes: 5 additions & 5 deletions src/rnp/fficli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ rnp_ask_filename(const std::string &msg, std::string &res, cli_rnp_t &rnp)
}
path = path + std::string(fname);
if (rnp::strip_eol(path)) {
res = path;
res = std::move(path);
return true;
}
if (path.size() >= 2048) {
Expand Down Expand Up @@ -284,7 +284,7 @@ rnp_get_output_filename(const std::string &path, std::string &res, cli_rnp_t &rn

while (true) {
if (!rnp_file_exists(newpath.c_str())) {
res = newpath;
res = std::move(newpath);
return true;
}
if (rnp.cfg().get_bool(CFG_OVERWRITE) ||
Expand All @@ -293,7 +293,7 @@ rnp_get_output_filename(const std::string &path, std::string &res, cli_rnp_t &rn
"File '%s' already exists. Would you like to overwrite it?",
newpath.c_str())) {
rnp_unlink(newpath.c_str());
res = newpath;
res = std::move(newpath);
return true;
}

Expand Down Expand Up @@ -1242,7 +1242,7 @@ static const std::string alg_aliases[] = {
"SHA-512", "SHA512", "RIPEMD-160", "RIPEMD160"};

const std::string
cli_rnp_alg_to_ffi(const std::string alg)
cli_rnp_alg_to_ffi(const std::string &alg)
{
size_t count = sizeof(alg_aliases) / sizeof(alg_aliases[0]);
assert((count % 2) == 0);
Expand Down Expand Up @@ -2540,7 +2540,7 @@ output_strip_extension(Operation op, const std::string &in)
}

static std::string
extract_filename(const std::string path)
extract_filename(const std::string &path)
{
size_t lpos = path.find_last_of("/\\");
if (lpos == std::string::npos) {
Expand Down
2 changes: 1 addition & 1 deletion src/rnp/fficli.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void cli_rnp_print_feature(FILE *fp, const char *type, const char *printe
* @return string with FFI algorithm's name. In case alias is not found the source string will
* be returned.
*/
const std::string cli_rnp_alg_to_ffi(const std::string alg);
const std::string cli_rnp_alg_to_ffi(const std::string &alg);

/**
* @brief Attempt to set hash algorithm using the value provided.
Expand Down
Loading