coverity scan AUTO_CAUSES_COPY findings
awelzel opened this issue · comments
Coverity reported warnings around AUTO_USES_COPY zeek/zeek#2341.
Just pasting here from an email, happy to just do them if they seem like reasonable reportings. @Neverlord ?
*** CID 1491340: Performance inefficiencies (AUTO_CAUSES_COPY)
/home/runner/work/zeek/zeek/auxil/broker/bindings/python/set_bind.h: 98 in _ZZN8pybind116detail25set_if_insertion_operatorISt3setIN6broker4dataESt4lessIS4_ESaIS4_EENS_6class_IS8_JSt10unique_ptrIS8_St14default_deleteIS8_EEEEEEEDTcmlsclsr3stdE7declvalIRSoEEclsr3stdE7declvalINT_10value_typeEEEcvvLi0EERT0_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEENKUlRS8_E_clB5cxx11EST_()
92 cl.def(
93 "__repr__",
94 [name](Set& s) {
95 std::ostringstream t;
96 bool first = true;
97 t << name << "{";
>>> CID 1491340: Performance inefficiencies (AUTO_CAUSES_COPY)
>>> Using the "auto" keyword without an "&" causes the copy of an object of type data.
98 for (auto i : s) {
99 if (!first)
100 t << ", ";
101 t << i;
102 first = false;
103 }
home/runner/work/zeek/zeek/auxil/broker/include/broker/internal/with_native_labels.hh: 25 in broker::internal::with_native_labels<broker::telemetry::int_histogram_get_or_add(broker::telemetry::metric_family_hdl *, broker::span<const std::pair<std::basic_string_view<char, std::char_traits<char>>, std::basic_string_view<char, std::char_traits<char>>>>)::[lambda(T1) (instance 1)]>(broker::span<const std::pair<std::basic_string_view<char, std::char_traits<char>>, std::basic_string_view<char, std::char_traits<char>>>>, T1)()
19 };
20 for (size_t index = 0; index < xs.size(); ++index)
21 buf[index] = ct::label_view{xs[index].first, xs[index].second};
22 return continuation(span{buf, xs.size()});
23 } else {
24 std::vector<ct::label_view> buf;
>>> CID 1491339: (AUTO_CAUSES_COPY)
>>> Using the "auto" keyword without an "&" causes the copy of an object of type pair.
25 for (auto x : xs)
26 buf.emplace_back(x.first, x.second);
27 return continuation(span{buf});
28 }
29 }
/home/runner/work/zeek/zeek/auxil/broker/include/broker/internal/with_native_labels.hh: 40 in broker::internal::with_native_labels<broker::telemetry::<unnamed>::impl_base::int_histogram_fam(std::basic_string_view<char, std::char_traits<char>>, std::basic_string_view<char, std::char_traits<char>>, broker::span<const std::basic_string_view<char, std::char_traits<char>>>, broker::span<const long>, std::basic_string_view<char, std::char_traits<char>>, std::basic_string_view<char, std::char_traits<char>>, bool)::[lambda(T1) (instance 1)]>(broker::span<const std::basic_string_view<char, std::char_traits<char>>>, T1)()
34 caf::string_view buf[10];
35 for (size_t index = 0; index < xs.size(); ++index)
36 buf[index] = xs[index];
37 return continuation(span{buf, xs.size()});
38 } else {
39 std::vector<caf::string_view> buf;
>>> CID 1491339: (AUTO_CAUSES_COPY)
>>> Using the "auto" keyword without an "&" causes the copy of an object of type basic_string_view.
40 for (auto x : xs)
41 buf.emplace_back(x);
42 return continuation(span{buf});
43 }
44 }
45
happy to just do them if they seem like reasonable reportings
@awelzel I'd appreciate it if you'd file a PR! The last two are probably inconsequential, since a string view is just a pointer and a size. I'd fix them regardless, though. Using the const-ref doesn't hurt either and making the static analyzers happy is worth it.