Some refactoring and fixes based on static source code analysis

This commit is contained in:
Lukas Matena 2021-04-16 14:44:36 +02:00
parent 807f380d3f
commit 96a6c8538f
10 changed files with 15 additions and 13 deletions

View File

@ -552,7 +552,7 @@ static CircleBed to_circle(const Point &center, const Points& points) {
std::vector<double> vertex_distances; std::vector<double> vertex_distances;
double avg_dist = 0; double avg_dist = 0;
for (auto pt : points) for (const Point& pt : points)
{ {
double distance = distance_to(center, pt); double distance = distance_to(center, pt);
vertex_distances.push_back(distance); vertex_distances.push_back(distance);

View File

@ -306,7 +306,7 @@ ConfigOptionDef* ConfigDef::add_nullable(const t_config_option_key &opt_key, Con
std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults, std::function<bool(const ConfigOptionDef &)> filter) const std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults, std::function<bool(const ConfigOptionDef &)> filter) const
{ {
// prepare a function for wrapping text // prepare a function for wrapping text
auto wrap = [](std::string text, size_t line_length) -> std::string { auto wrap = [](const std::string& text, size_t line_length) -> std::string {
std::istringstream words(text); std::istringstream words(text);
std::ostringstream wrapped; std::ostringstream wrapped;
std::string word; std::string word;
@ -335,7 +335,7 @@ std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults, s
categories.insert(def.category); categories.insert(def.category);
} }
for (auto category : categories) { for (const std::string& category : categories) {
if (category != "") { if (category != "") {
out << category << ":" << std::endl; out << category << ":" << std::endl;
} else if (categories.size() > 1) { } else if (categories.size() > 1) {

View File

@ -41,7 +41,7 @@ extern void check_mode_for_custom_gcode_per_print_z(Info& info)
return; return;
bool is_single_extruder = true; bool is_single_extruder = true;
for (auto item : info.gcodes) for (const Item& item : info.gcodes)
{ {
if (item.type == ToolChange) { if (item.type == ToolChange) {
info.mode = MultiAsSingle; info.mode = MultiAsSingle;

View File

@ -125,7 +125,7 @@ protected:
unsigned int /* thickness_layers */, unsigned int /* thickness_layers */,
const std::pair<float, Point> & /* direction */, const std::pair<float, Point> & /* direction */,
ExPolygon /* expolygon */, ExPolygon /* expolygon */,
Polylines & /* polylines_out */) {}; Polylines & /* polylines_out */) {}
virtual float _layer_angle(size_t idx) const { return (idx & 1) ? float(M_PI/2.) : 0; } virtual float _layer_angle(size_t idx) const { return (idx & 1) ? float(M_PI/2.) : 0; }

View File

@ -18,7 +18,7 @@ class PrintObject;
namespace FillAdaptive { namespace FillAdaptive {
struct Octree; struct Octree;
}; }
namespace FillLightning { namespace FillLightning {
class Generator; class Generator;

View File

@ -903,7 +903,7 @@ indexed_triangle_set ModelObject::raw_indexed_triangle_set() const
size_t j = out.indices.size(); size_t j = out.indices.size();
append(out.vertices, v->mesh().its.vertices); append(out.vertices, v->mesh().its.vertices);
append(out.indices, v->mesh().its.indices); append(out.indices, v->mesh().its.indices);
auto m = v->get_matrix(); const Transform3d& m = v->get_matrix();
for (; i < out.vertices.size(); ++ i) for (; i < out.vertices.size(); ++ i)
out.vertices[i] = (m * out.vertices[i].cast<double>()).cast<float>().eval(); out.vertices[i] = (m * out.vertices[i].cast<double>()).cast<float>().eval();
if (v->is_left_handed()) { if (v->is_left_handed()) {

View File

@ -1498,7 +1498,7 @@ void PhysicalPrinter::update_preset_names_in_config()
if (!preset_names.empty()) { if (!preset_names.empty()) {
std::vector<std::string>& values = config.option<ConfigOptionStrings>("preset_names")->values; std::vector<std::string>& values = config.option<ConfigOptionStrings>("preset_names")->values;
values.clear(); values.clear();
for (auto preset : preset_names) for (const std::string& preset : preset_names)
values.push_back(preset); values.push_back(preset);
// temporary workaround for compatibility with older Slicer // temporary workaround for compatibility with older Slicer
@ -1571,7 +1571,7 @@ void PhysicalPrinter::set_name(const std::string& name)
this->name = name; this->name = name;
} }
std::string PhysicalPrinter::get_full_name(std::string preset_name) const std::string PhysicalPrinter::get_full_name(const std::string& preset_name) const
{ {
return name + separator() + preset_name; return name + separator() + preset_name;
} }
@ -1888,7 +1888,7 @@ std::vector<std::string> PhysicalPrinterCollection::get_printers_with_only_prese
{ {
std::vector<std::string> printers; std::vector<std::string> printers;
for (auto printer : m_printers) for (const PhysicalPrinter& printer : m_printers)
if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name) if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name)
printers.emplace_back(printer.name); printers.emplace_back(printer.name);

View File

@ -675,7 +675,7 @@ public:
bool operator<(const PhysicalPrinter& other) const { return this->name < other.name; } bool operator<(const PhysicalPrinter& other) const { return this->name < other.name; }
// get full printer name included a name of the preset // get full printer name included a name of the preset
std::string get_full_name(std::string preset_name) const; std::string get_full_name(const std::string &preset_name) const;
// get printer name from the full name uncluded preset name // get printer name from the full name uncluded preset name
static std::string get_short_name(std::string full_name); static std::string get_short_name(std::string full_name);

View File

@ -267,7 +267,7 @@ PresetsConfigSubstitutions PresetBundle::load_presets(AppConfig &config, Forward
std::string errors_cummulative; std::string errors_cummulative;
std::tie(substitutions, errors_cummulative) = this->load_system_presets(substitution_rule); std::tie(substitutions, errors_cummulative) = this->load_system_presets(substitution_rule);
const std::string dir_user_presets = data_dir() const std::string& dir_user_presets = data_dir()
#ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR #ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
// Store the print/filament/printer presets into a "presets" directory. // Store the print/filament/printer presets into a "presets" directory.
+ "/presets" + "/presets"

View File

@ -961,9 +961,11 @@ std::string string_printf(const char *format, ...)
buffer.resize(size_t(bufflen) + 1); buffer.resize(size_t(bufflen) + 1);
::vsnprintf(buffer.data(), buffer.size(), format, args2); ::vsnprintf(buffer.data(), buffer.size(), format, args2);
} }
va_end(args1);
va_end(args2);
buffer.resize(bufflen); buffer.resize(bufflen);
return buffer; return buffer;
} }