Skip to content

Commit

Permalink
Merge branch 'topic/bbannier/coverity'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Jan 13, 2025
2 parents 5f1e396 + 9140803 commit cf21f50
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.13.0-dev.66 | 2025-01-13 22:09:19 +0100

* Prevent copies in various places. (Benjamin Bannier, Corelight)

1.13.0-dev.64 | 2025-01-10 09:55:22 +0100

* Address a FIXME. (Benjamin Bannier, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.13.0-dev.64
1.13.0-dev.66
2 changes: 1 addition & 1 deletion hilti/runtime/include/types/integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ inline Bytes pack(integer::safe<T> i, ByteOrder fmt) {
template<typename T, typename D>
inline Result<std::tuple<integer::safe<T>, D>> unpack(D b, ByteOrder fmt) {
if ( fmt == ByteOrder::Host )
return unpack<T>(b, systemByteOrder());
return unpack<T>(std::move(b), systemByteOrder());

if ( b.size() < static_cast<int64_t>(sizeof(T)) )
return result::Error("insufficient data to unpack integer");
Expand Down
2 changes: 1 addition & 1 deletion hilti/runtime/src/types/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Bytes string::encode(std::string s, unicode::Charset cs, unicode::DecodeErrorStr
case unicode::Charset::UTF16BE: [[fallthrough]];
case unicode::Charset::UTF16LE: {
// HILTI `string` is always UTF-8, but we could be invoked with raw bags of bytes here as well, so validate.
auto t8 = string::encode(s, unicode::Charset::UTF8, errors).str();
auto t8 = string::encode(std::move(s), unicode::Charset::UTF8, errors).str();

auto t = utf8::utf8to16(t8);

Expand Down
2 changes: 1 addition & 1 deletion hilti/toolchain/bin/hilti-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char** argv) try {
continue;
}

options.push_back(opt);
options.push_back(std::move(opt));
}

hilti::configuration().initLocation(hilti::util::currentExecutable());
Expand Down
2 changes: 1 addition & 1 deletion hilti/toolchain/include/ast/statements/switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Case final : public Node {
}

removeChildren(_end_exprs, {});
addChildren(ctx, exprs);
addChildren(ctx, std::move(exprs));
}

std::string _dump() const final;
Expand Down
4 changes: 2 additions & 2 deletions hilti/toolchain/src/base/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::vector<std::string> util::split(std::string s, const std::string& delim) {
s = s.substr(p + delim.size(), std::string::npos);
}

l.push_back(s);
l.push_back(std::move(s));
return l;
}

Expand Down Expand Up @@ -285,7 +285,7 @@ std::vector<std::string> util::flattenParts(const std::vector<std::string>& in)
if ( s.empty() )
continue;

out.push_back(s);
out.push_back(std::move(s));
}
}

Expand Down
6 changes: 3 additions & 3 deletions hilti/toolchain/src/compiler/codegen/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ struct GlobalsVisitor : hilti::visitor::PostOrder {

// Record the global for now, final declarations will be added later
// once the visitor knows all globals.
globals.push_back(x);
globals.push_back(std::move(x));
}

void operator()(declaration::Constant* n) final {
Expand Down Expand Up @@ -441,9 +441,9 @@ struct GlobalsVisitor : hilti::visitor::PostOrder {

if ( include_implementation ) {
// Tell linker about our implementation.
auto hook_join = cxx::linker::Join{.id = id_hook_stub,
auto hook_join = cxx::linker::Join{.id = std::move(id_hook_stub),
.callee = d,
.aux_types = aux_types,
.aux_types = std::move(aux_types),
.priority = priority,
.declare_only = (! f->body())};

Expand Down
4 changes: 2 additions & 2 deletions hilti/toolchain/src/compiler/codegen/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ struct VisitorDeclaration : hilti::visitor::PreOrder {
}

d.ftype = cxx::declaration::Function::Free;
auto hook = cxx::linker::Join{.id = cxx::ID(id_hook),
auto hook = cxx::linker::Join{.id = cxx::ID(std::move(id_hook)),
.callee = d,
.aux_types = aux_types,
.aux_types = std::move(aux_types),
.declare_only = true};

auto vref =
Expand Down
4 changes: 2 additions & 2 deletions hilti/toolchain/src/compiler/cxx/elements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ std::string cxx::type::Struct::str() const {
auto cassign = fmt("%s& operator=(const %s&) = default;", type_name, type_name);
auto massign = fmt("%s& operator=(%s&&) = default;", type_name, type_name);

for ( const auto& x : {dctor, cctor, mctor, cassign, massign} )
struct_fields.emplace_back(x);
for ( auto x : {std::move(dctor), std::move(cctor), std::move(mctor), std::move(cassign), std::move(massign)} )
struct_fields.emplace_back(std::move(x));

auto locals_user = util::filter(members, [](const auto& m) {
auto l = std::get_if<declaration::Local>(&m);
Expand Down
2 changes: 1 addition & 1 deletion hilti/toolchain/src/compiler/cxx/formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Formatter::pushNamespace(std::string relative_ns) {
f.eol();
}

_namespaces.push_back(relative_ns);
_namespaces.push_back(std::move(relative_ns));
}

void Formatter::enterNamespace(const std::string& absolute_ns) {
Expand Down
2 changes: 1 addition & 1 deletion hilti/toolchain/src/compiler/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Result<hilti::rt::filesystem::path> Driver::writeToTemp(std::ifstream& in, const
close(fd);

if ( ! util::copyStream(in, out) )
return error("Error writing to file", std::string(name));
return error("Error writing to file", {std::move(name)});

_tmp_files.insert(name);
return hilti::rt::filesystem::path(name);
Expand Down
2 changes: 1 addition & 1 deletion hilti/toolchain/src/compiler/jit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ hilti::Result<Nothing> JIT::_compile() {

args.emplace_back("-o");
args.push_back(obj);
_objects.push_back(obj);
_objects.push_back(std::move(obj));

args.push_back(hilti::rt::filesystem::canonical(path));

Expand Down
4 changes: 2 additions & 2 deletions spicy/runtime/src/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ Result<hilti::rt::Nothing> Driver::processPreBatchedInput(std::istream& in) {
continue;
}

connections[cid] = driver::ConnectionState{.orig_id = orig_id,
.resp_id = resp_id,
connections[cid] = driver::ConnectionState{.orig_id = std::move(orig_id),
.resp_id = std::move(resp_id),
.orig_state = orig_state,
.resp_state = resp_state};
_total_connections++;
Expand Down
11 changes: 5 additions & 6 deletions spicy/toolchain/bin/spicy-batch-extract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ static void processPreBatchedInput(std::string needle, std::istream& in, std::os
if ( m.size() != 7 )
error("unexpected number of argument for @begin-conn");

auto cid = std::string(m[1]);
auto orig_id = std::string(m[3]);
auto resp_id = std::string(m[5]);

if ( is_needle(cid) ) {
needles.insert(orig_id);
needles.insert(resp_id);
if ( const auto& cid = std::string(m[1]); is_needle(cid) ) {
auto orig_id = std::string(m[3]);
auto resp_id = std::string(m[5]);
needles.insert(std::move(orig_id));
needles.insert(std::move(resp_id));
out << cmd << '\n';
}
}
Expand Down
2 changes: 1 addition & 1 deletion spicy/toolchain/bin/spicy-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int main(int argc, char** argv) try {
continue;
}

options.push_back(opt);
options.push_back(std::move(opt));
}

hilti::configuration().initLocation(hilti::util::currentExecutable());
Expand Down

0 comments on commit cf21f50

Please sign in to comment.