Skip to content

Commit

Permalink
Fix bunch of Coverity issues (uninitialized fields/copy instead of mo…
Browse files Browse the repository at this point in the history
…ve).
  • Loading branch information
ni4 committed Jan 30, 2025
1 parent 2c1e39d commit 0b57972
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
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
4 changes: 2 additions & 2 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 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

0 comments on commit 0b57972

Please sign in to comment.