summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ctor.cc4
-rw-r--r--src/bootstrap.cc6
-rw-r--r--src/build.cc18
-rw-r--r--src/configure.cc39
-rw-r--r--src/ctor.h34
-rw-r--r--src/externals_manual.cc2
m---------src/getoptpp0
-rw-r--r--src/libctor.cc13
-rw-r--r--src/rebuild.cc14
-rw-r--r--src/task.cc15
-rw-r--r--src/task.h2
-rw-r--r--src/task_ar.cc14
-rw-r--r--src/task_cc.cc14
-rw-r--r--src/task_fn.cc12
-rw-r--r--src/task_ld.cc18
-rw-r--r--src/task_so.cc14
-rw-r--r--src/tasks.cc13
-rw-r--r--src/tools.cc10
-rw-r--r--src/util.cc4
19 files changed, 137 insertions, 109 deletions
diff --git a/ctor.cc b/ctor.cc
index d0d53d8..92135c2 100644
--- a/ctor.cc
+++ b/ctor.cc
@@ -37,6 +37,10 @@ ctor::build_configurations ctorConfigs(const ctor::settings& settings)
"-g",
"-Wall",
"-Werror",
+ "-Wextra",
+ "-Wshadow",
+ "-Wconversion",
+// "-Wnrvo",
"-Isrc",
},
},
diff --git a/src/bootstrap.cc b/src/bootstrap.cc
index 57db670..471c844 100644
--- a/src/bootstrap.cc
+++ b/src/bootstrap.cc
@@ -4,6 +4,7 @@
#include <iostream>
#include <array>
#include <cstdlib>
+#include <span>
#define BOOTSTRAP
@@ -82,9 +83,10 @@ const std::string& ctor::configuration::get(const std::string& key, const std::s
int main(int argc, char* argv[])
{
- if(argc > 1)
+ auto args = std::span(argv, static_cast<std::size_t>(argc));
+ if(args.size() > 1)
{
- std::cerr << "This is a minimal bootstrap version of " << argv[0] <<
+ std::cerr << "This is a minimal bootstrap version of " << args[0] <<
" which doesn't support any arguments\n";
return 1;
}
diff --git a/src/build.cc b/src/build.cc
index 3e64cca..906c3ea 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -142,11 +142,11 @@ std::vector<std::shared_ptr<Task>> getDepTasks(std::shared_ptr<Task> task)
for(const auto& dep : deps)
{
auto depSet = getDepTasks(dep);
- for(const auto& dep : depSet)
+ for(const auto& dep_inner : depSet)
{
- if(std::find(tasks.begin(), tasks.end(), dep) == tasks.end())
+ if(std::find(tasks.begin(), tasks.end(), dep_inner) == tasks.end())
{
- tasks.push_back(dep);
+ tasks.push_back(dep_inner);
}
}
}
@@ -169,11 +169,11 @@ int build(const ctor::settings& settings,
auto depSet = getDepTasks(task);
std::vector<std::shared_ptr<Task>> ts;
- for(const auto& task : depSet)
+ for(const auto& task_inner : depSet)
{
- if(std::find(ts.begin(), ts.end(), task) == ts.end())
+ if(std::find(ts.begin(), ts.end(), task_inner) == ts.end())
{
- ts.push_back(task);
+ ts.push_back(task_inner);
}
}
@@ -215,11 +215,11 @@ int build(const ctor::settings& settings,
task_found = true;
auto depSet = getDepTasks(task);
- for(const auto& task : depSet)
+ for(const auto& task_inner : depSet)
{
- if(std::find(ts.begin(), ts.end(), task) == ts.end())
+ if(std::find(ts.begin(), ts.end(), task_inner) == ts.end())
{
- ts.push_back(task);
+ ts.push_back(task_inner);
}
}
}
diff --git a/src/configure.cc b/src/configure.cc
index 26d3575..995e340 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -7,6 +7,7 @@
#include <filesystem>
#include <fstream>
#include <optional>
+#include <span>
#include <getoptpp/getoptpp.hpp>
@@ -321,19 +322,19 @@ int regenerateCache(ctor::settings& settings,
}
auto add_path_args =
- [&](const std::string& name)
+ [&](const std::string& arg_name)
{
- opt.add(name + "-includedir", required_argument, key++,
- "Set path to " + name + " header file.",
+ opt.add(arg_name + "-includedir", required_argument, key++,
+ "Set path to " + arg_name + " header file.",
[&]() {
- external_includedir[name] = optarg;
+ external_includedir[arg_name] = optarg;
return 0;
});
- opt.add(name + "-libdir", required_argument, key++,
- "Set path to " + name + " libraries.",
+ opt.add(arg_name + "-libdir", required_argument, key++,
+ "Set path to " + arg_name + " libraries.",
[&]() {
- external_libdir[name] = optarg;
+ external_libdir[arg_name] = optarg;
return 0;
});
};
@@ -366,7 +367,7 @@ int regenerateCache(ctor::settings& settings,
return 0;
});
- opt.process(vargs.size(), vargs.data());
+ opt.process(static_cast<int>(vargs.size()), vargs.data());
if(host_arch_prefix.empty())
{
@@ -821,12 +822,14 @@ int regenerateCache(ctor::settings& settings,
int configure(const ctor::settings& global_settings, int argc, char* argv[])
{
+ auto args_span = std::span(argv, static_cast<std::size_t>(argc));
+
ctor::settings settings{global_settings};
std::vector<std::string> args;
- for(int i = 2; i < argc; ++i) // skip command and the first 'configure' arg
+ for(std::size_t i = 2; i < args_span.size(); ++i) // skip command and the first 'configure' arg
{
- args.emplace_back(argv[i]);
+ args.emplace_back(args_span[i]);
}
std::map<std::string, std::string> env;
@@ -860,7 +863,7 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[])
env["PATH"] = path_env;
}
- auto ret = regenerateCache(settings, argv[0], args, env);
+ auto ret = regenerateCache(settings, args_span[0], args, env);
if(ret != 0)
{
return ret;
@@ -873,19 +876,21 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[])
int reconfigure(const ctor::settings& global_settings, int argc, char* argv[])
{
+ auto args_span = std::span(argv, static_cast<std::size_t>(argc));
+
ctor::settings settings{global_settings};
bool no_rerun{false};
std::vector<std::string> args;
- for(int i = 2; i < argc; ++i) // skip executable name and 'reconfigure' arg
+ for(std::size_t i = 2; i < args_span.size(); ++i) // skip executable name and 'reconfigure' arg
{
- if(i == 2 && std::string(argv[i]) == "--no-rerun")
+ if(i == 2 && std::string(args_span[i]) == "--no-rerun")
{
no_rerun = true;
continue;
}
- args.emplace_back(argv[i]);
+ args.emplace_back(args_span[i]);
}
const auto& cfg = ctor::get_configuration();
@@ -895,14 +900,14 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[])
{
std::cout << e.first << "=\"" << e.second << "\" ";
}
- std::cout << argv[0] << " configure ";
+ std::cout << args_span[0] << " configure ";
for(const auto& arg : cfg.args)
{
std::cout << arg << " ";
}
std::cout << "\n";
- auto ret = regenerateCache(settings, argv[0], cfg.args, cfg.env);
+ auto ret = regenerateCache(settings, args_span[0], cfg.args, cfg.env);
if(ret != 0)
{
return ret;
@@ -915,5 +920,5 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[])
return 0; // this was originally invoked by configure, don't loop
}
- return execute(settings, argv[0], args);
+ return execute(settings, args_span[0], args);
}
diff --git a/src/ctor.h b/src/ctor.h
index 1de4aec..e0e2bef 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -63,20 +63,20 @@ enum class toolchain
struct source
{
- constexpr source(const char* file) : file(file) {} // convenience ctor
+ source(const char* file_) : file(file_) {} // convenience ctor
- constexpr source(std::string_view file) : source(file, ctor::language::automatic) {}
- constexpr source(std::string_view file, ctor::language lang) : file(file), language(lang) {}
+ source(std::string_view file_) : source(file_, ctor::language::automatic) {}
+ source(std::string_view file_, ctor::language lang_) : file(file_), language(lang_) {}
- constexpr source(std::string_view file, std::string_view output) : file(file), output(output) {}
- constexpr source(std::string_view file, ctor::language lang, std::string_view output) : file(file), language(lang), output(output) {}
+ source(std::string_view file_, std::string_view output_) : file(file_), output(output_) {}
+ source(std::string_view file_, ctor::language lang_, std::string_view output_) : file(file_), language(lang_), output(output_) {}
- constexpr source(ctor::toolchain toolchain, std::string_view file) : file(file), toolchain(toolchain) {}
- constexpr source(ctor::toolchain toolchain, std::string_view file, ctor::language lang) : file(file), toolchain(toolchain), language(lang) {}
+ source(ctor::toolchain toolchain_, std::string_view file_) : file(file_), toolchain(toolchain_) {}
+ source(ctor::toolchain toolchain_, std::string_view file_, ctor::language lang_) : file(file_), toolchain(toolchain_), language(lang_) {}
- constexpr source(ctor::toolchain toolchain, std::string_view file, std::string_view output) : file(file), toolchain(toolchain), output(output) {}
+ source(ctor::toolchain toolchain_, std::string_view file_, std::string_view output_) : file(file_), toolchain(toolchain_), output(output_) {}
- constexpr source(ctor::toolchain toolchain, std::string_view file, ctor::language lang, std::string_view output) : file(file), toolchain(toolchain), language(lang), output(output) {}
+ source(ctor::toolchain toolchain_, std::string_view file_, ctor::language lang_, std::string_view output_) : file(file_), toolchain(toolchain_), language(lang_), output(output_) {}
std::string file;
ctor::toolchain toolchain{ctor::toolchain::any};
@@ -156,17 +156,17 @@ template<typename T>
class flag
{
public:
- flag(const std::string& str);
+ flag(std::string_view str);
flag(const char* str);
- flag(T opt) : opt(opt) {}
- flag(T opt, const std::string& arg) : opt(opt), arg(arg) {}
- flag(T opt, const char* arg) : opt(opt), arg(arg) {}
- flag(ctor::toolchain toolchain, T opt) : toolchain(toolchain), opt(opt) {}
- flag(ctor::toolchain toolchain, T opt, const char* arg) : toolchain(toolchain), opt(opt), arg(arg) {}
- flag(ctor::toolchain toolchain, T opt, const std::string& arg) : toolchain(toolchain), opt(opt), arg(arg) {}
+ flag(T opt_) : opt(opt_) {}
+ flag(T opt_, std::string_view arg_) : opt(opt_), arg(arg_) {}
+ flag(T opt_, const char* arg_) : opt(opt_), arg(arg_) {}
+ flag(ctor::toolchain toolchain_, T opt_) : toolchain(toolchain_), opt(opt_) {}
+ flag(ctor::toolchain toolchain_, T opt_, const char* arg_) : toolchain(toolchain_), opt(opt_), arg(arg_) {}
+ flag(ctor::toolchain toolchain_, T opt_, std::string_view arg_) : toolchain(toolchain_), opt(opt_), arg(arg_) {}
ctor::toolchain toolchain{ctor::toolchain::any};
- T opt;
+ T opt{};
std::string arg;
};
diff --git a/src/externals_manual.cc b/src/externals_manual.cc
index 2434d71..0563a5e 100644
--- a/src/externals_manual.cc
+++ b/src/externals_manual.cc
@@ -13,7 +13,7 @@
extern std::map<std::string, std::string> external_includedir;
extern std::map<std::string, std::string> external_libdir;
-int resolv(const ctor::settings& settings, const ctor::external_configuration& config,
+int resolv([[maybe_unused]]const ctor::settings& settings, const ctor::external_configuration& config,
const ctor::external_manual& ext, ctor::flags& flags)
{
flags = ext.flags;
diff --git a/src/getoptpp b/src/getoptpp
-Subproject 9ff20ef857429619267e3f156a4f81ad9e1eb8c
+Subproject 5aba94355ec638c6f8612f86be309ed684979ae
diff --git a/src/libctor.cc b/src/libctor.cc
index 9be14b2..b1fbaea 100644
--- a/src/libctor.cc
+++ b/src/libctor.cc
@@ -15,6 +15,7 @@
#include <deque>
#include <fstream>
#include <cstdlib>
+#include <span>
#include <getoptpp/getoptpp.hpp>
@@ -27,6 +28,8 @@
int main(int argc, char* argv[])
{
+ auto args = std::span(argv, static_cast<std::size_t>(argc));
+
ctor::settings settings{};
const auto& c = ctor::get_configuration();
@@ -34,12 +37,12 @@ int main(int argc, char* argv[])
settings.parallel_processes =
std::max(1u, std::thread::hardware_concurrency()) * 2 - 1;
- if(argc > 1 && std::string(argv[1]) == "configure")
+ if(args.size() > 1 && std::string(args[1]) == "configure")
{
return configure(settings, argc, argv);
}
- if(argc > 1 && std::string(argv[1]) == "reconfigure")
+ if(args.size() > 1 && std::string(args[1]) == "reconfigure")
{
return reconfigure(settings, argc, argv);
}
@@ -64,7 +67,8 @@ int main(int argc, char* argv[])
[&]() {
try
{
- settings.parallel_processes = std::stoi(optarg);
+ settings.parallel_processes =
+ static_cast<std::size_t>(std::stoi(optarg));
}
catch(...)
{
@@ -156,7 +160,7 @@ int main(int argc, char* argv[])
opt.add("help", no_argument, 'h',
"Print this help text.",
[&]() {
- std::cout << "Usage: " << argv[0] << " [options] [target] ...\n";
+ std::cout << "Usage: " << args[0] << " [options] [target] ...\n";
std::cout <<
R"_( where target can be either:
configure - run configuration step (cannot be used with other targets).
@@ -270,7 +274,6 @@ Options:
if(print_configure_db)
{
no_default_build = true;
- const auto& c = ctor::get_configuration();
for(const auto& config : c.tools)
{
std::cout << config.first << ": " << config.second << "\n";
diff --git a/src/rebuild.cc b/src/rebuild.cc
index c176744..1db5e83 100644
--- a/src/rebuild.cc
+++ b/src/rebuild.cc
@@ -8,6 +8,7 @@
#include <algorithm>
#include <source_location>
#include <cstring>
+#include <span>
#include "configure.h"
#include "ctor.h"
@@ -105,7 +106,7 @@ int unreg(const char* location)
}
}
- return found;
+ return static_cast<int>(found);
}
std::array<ExternalConfigurationEntry, 1024> externalConfigFiles;
@@ -150,6 +151,8 @@ bool contains(const std::vector<ctor::source>& sources, const std::string& file)
bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[],
bool relaunch_allowed)
{
+ auto args_span = std::span(argv, static_cast<std::size_t>(argc));
+
using namespace std::string_literals;
if(global_settings.verbose > 1)
@@ -187,7 +190,7 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[
{
std::filesystem::path buildfile = settings.builddir;
- std::filesystem::path currentfile = argv[0];
+ std::filesystem::path currentfile = args_span[0];
config.target = std::filesystem::relative(currentfile, buildfile).string();
}
@@ -267,11 +270,12 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[
{
args.emplace_back("--no-rerun");
}
- for(int i = 1; i < argc; ++i)
+ for(std::size_t i = 1; i < args_span.size(); ++i)
{
- args.emplace_back(argv[i]);
+ args.emplace_back(args_span[i]);
}
- auto ret = execute(settings, argv[0], args);
+
+ auto ret = execute(settings, args_span[0], args);
//if(ret != 0)
{
exit(ret);
diff --git a/src/task.cc b/src/task.cc
index 680dbf8..a9c0fee 100644
--- a/src/task.cc
+++ b/src/task.cc
@@ -8,12 +8,12 @@
#include <algorithm>
#include <utility>
-Task::Task(const ctor::build_configuration& config, const ctor::settings& settings,
- std::string sourceDir)
- : config(config)
+Task::Task(const ctor::build_configuration& config_, const ctor::settings& settings_,
+ std::string sourceDir_)
+ : config(config_)
, output_system(config.system)
- , settings(settings)
- , sourceDir(std::move(sourceDir))
+ , settings(settings_)
+ , sourceDir(std::move(sourceDir_))
{
}
@@ -145,6 +145,7 @@ std::string Task::compiler() const
case ctor::output_system::build:
return c.get(ctor::cfg::build_cc, "/usr/bin/gcc");
}
+ break;
case ctor::language::cpp:
switch(outputSystem())
{
@@ -153,11 +154,15 @@ std::string Task::compiler() const
case ctor::output_system::build:
return c.get(ctor::cfg::build_cxx, "/usr/bin/g++");
}
+ break;
default:
std::cerr << "Unknown CC target type\n";
exit(1);
break;
}
+
+ std::cerr << "Unhandled compiler!\n";
+ exit(1);
}
std::vector<std::shared_ptr<Task>> Task::getDependsTasks()
diff --git a/src/task.h b/src/task.h
index 0303b2e..e930a54 100644
--- a/src/task.h
+++ b/src/task.h
@@ -28,7 +28,7 @@ public:
virtual ~Task() = default;
int registerDepTasks(const std::vector<std::shared_ptr<Task>>& tasks);
- virtual int registerDepTasksInner(const std::vector<std::shared_ptr<Task>>& tasks) { return 0; }
+ virtual int registerDepTasksInner([[maybe_unused]]const std::vector<std::shared_ptr<Task>>& tasks) { return 0; }
bool operator==(const std::string& dep);
diff --git a/src/task_ar.cc b/src/task_ar.cc
index 25a49a2..b16a2f9 100644
--- a/src/task_ar.cc
+++ b/src/task_ar.cc
@@ -11,16 +11,16 @@
#include "util.h"
#include "tools.h"
-TaskAR::TaskAR(const ctor::build_configuration& config,
- const ctor::settings& settings,
+TaskAR::TaskAR(const ctor::build_configuration& config_,
+ const ctor::settings& settings_,
const std::string& target,
const std::vector<std::string>& objects,
- const std::string& sourceDir)
- : Task(config, settings, sourceDir)
+ const std::string& sourceDir_)
+ : Task(config_, settings_, sourceDir_)
, _targetFile(target)
- , config(config)
- , settings(settings)
- , sourceDir(sourceDir)
+ , config(config_)
+ , settings(settings_)
+ , sourceDir(sourceDir_)
{
target_type = ctor::target_type::static_library;
output_system = config.system;
diff --git a/src/task_cc.cc b/src/task_cc.cc
index 49aef78..e1f3023 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -13,13 +13,13 @@
#include "util.h"
#include "tools.h"
-TaskCC::TaskCC(const ctor::build_configuration& config, const ctor::settings& settings,
- const std::string& sourceDir, const ctor::source& source)
- : Task(config, settings, sourceDir)
- , sourceFile(sourceDir)
- , config(config)
- , settings(settings)
- , sourceDir(sourceDir)
+TaskCC::TaskCC(const ctor::build_configuration& config_, const ctor::settings& settings_,
+ const std::string& sourceDir_, const ctor::source& source)
+ : Task(config_, settings_, sourceDir_)
+ , sourceFile(sourceDir_)
+ , config(config_)
+ , settings(settings_)
+ , sourceDir(sourceDir_)
, _source(source)
{
sourceFile /= source.file;
diff --git a/src/task_fn.cc b/src/task_fn.cc
index 0ad697a..2fa0ad6 100644
--- a/src/task_fn.cc
+++ b/src/task_fn.cc
@@ -11,12 +11,12 @@
#include "execute.h"
#include "util.h"
-TaskFn::TaskFn(const ctor::build_configuration& config, const ctor::settings& settings,
- const std::string& sourceDir, const ctor::source& source)
- : Task(config, settings, sourceDir)
- , sourceFile(sourceDir)
- , config(config)
- , settings(settings)
+TaskFn::TaskFn(const ctor::build_configuration& config_, const ctor::settings& settings_,
+ const std::string& sourceDir_, const ctor::source& source)
+ : Task(config_, settings_, sourceDir_)
+ , sourceFile(sourceDir_)
+ , config(config_)
+ , settings(settings_)
{
sourceFile /= source.file;
diff --git a/src/task_ld.cc b/src/task_ld.cc
index aad6947..c8cd1ea 100644
--- a/src/task_ld.cc
+++ b/src/task_ld.cc
@@ -11,17 +11,17 @@
#include "util.h"
#include "tools.h"
-TaskLD::TaskLD(const ctor::build_configuration& config,
- const ctor::settings& settings,
+TaskLD::TaskLD(const ctor::build_configuration& config_,
+ const ctor::settings& settings_,
const std::string& target,
const std::vector<std::string>& objects,
- const std::string& sourceDir,
- bool is_self)
- : Task(config, settings, sourceDir)
- , config(config)
- , settings(settings)
- , sourceDir(sourceDir)
- , is_self(is_self)
+ const std::string& sourceDir_,
+ bool is_self_)
+ : Task(config_, settings_, sourceDir_)
+ , config(config_)
+ , settings(settings_)
+ , sourceDir(sourceDir_)
+ , is_self(is_self_)
{
target_type = config.type;
output_system = config.system;
diff --git a/src/task_so.cc b/src/task_so.cc
index 5453100..75b5f3c 100644
--- a/src/task_so.cc
+++ b/src/task_so.cc
@@ -11,15 +11,15 @@
#include "util.h"
#include "tools.h"
-TaskSO::TaskSO(const ctor::build_configuration& config,
- const ctor::settings& settings,
+TaskSO::TaskSO(const ctor::build_configuration& config_,
+ const ctor::settings& settings_,
const std::string& target,
const std::vector<std::string>& objects,
- const std::string& sourceDir)
- : Task(config, settings, sourceDir)
- , config(config)
- , settings(settings)
- , sourceDir(sourceDir)
+ const std::string& sourceDir_)
+ : Task(config_, settings_, sourceDir_)
+ , config(config_)
+ , settings(settings_)
+ , sourceDir(sourceDir_)
{
std::filesystem::path base = sourceDir;
diff --git a/src/tasks.cc b/src/tasks.cc
index 0e59097..2f9e47a 100644
--- a/src/tasks.cc
+++ b/src/tasks.cc
@@ -8,6 +8,7 @@
#include <list>
#include <iostream>
#include <algorithm>
+#include <span>
#include "ctor.h"
#include "task.h"
@@ -24,20 +25,22 @@
const std::deque<Target>& getTargets(const ctor::settings& settings,
bool resolve_externals)
{
+ auto config_files = std::span(configFiles).subspan(0, numConfigFiles);
+
static bool initialised{false};
static std::deque<Target> targets;
if(!initialised)
{
const auto& externals = ctor::get_configuration().externals;
- for(std::size_t i = 0; i < numConfigFiles; ++i)
+ for(const auto& config_file : config_files)
{
std::string path =
- std::filesystem::path(configFiles[i].file).parent_path().string();
+ std::filesystem::path(config_file.file).parent_path().string();
if(settings.verbose > 1)
{
- std::cout << configFiles[i].file << " in path " << path << "\n";
+ std::cout << config_file.file << " in path " << path << "\n";
}
- auto configs = configFiles[i].cb(settings);
+ auto configs = config_file.cb(settings);
for(auto& config : configs)
{
if(resolve_externals)
@@ -167,7 +170,7 @@ std::vector<std::shared_ptr<Task>> taskFactory(const ctor::build_configuration&
return tasks;
}
-std::shared_ptr<Task> getNextTask(const std::vector<std::shared_ptr<Task>>& allTasks,
+std::shared_ptr<Task> getNextTask([[maybe_unused]]const std::vector<std::shared_ptr<Task>>& allTasks,
std::vector<std::shared_ptr<Task>>& dirtyTasks)
{
for(auto dirtyTask = dirtyTasks.begin();
diff --git a/src/tools.cc b/src/tools.cc
index be94794..394a91c 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -175,10 +175,11 @@ std::string get_arch(ctor::output_system system)
std::string arch;
while(!feof(pipe))
{
- char buf[1024];
- if(fgets(buf, sizeof(buf), pipe) != nullptr)
+ constexpr auto buffer_size{1024};
+ std::array<char, buffer_size> buf{};
+ if(fgets(buf.data(), buf.size(), pipe) != nullptr)
{
- arch = buf;
+ arch = buf.data();
if(arch.starts_with("Target:"))
{
break;
@@ -195,7 +196,8 @@ std::string get_arch(ctor::output_system system)
}
// Remove 'Target: ' prefix
- arch = arch.substr(8);
+ constexpr auto prefix_length{8};
+ arch = arch.substr(prefix_length);
return arch;
}
diff --git a/src/util.cc b/src/util.cc
index 76d380b..73b158d 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -22,10 +22,10 @@ std::string readFile(const std::string& fileName)
std::ifstream::pos_type fileSize = ifs.tellg();
ifs.seekg(0, std::ios::beg);
- std::vector<char> bytes(fileSize);
+ std::vector<char> bytes(static_cast<std::size_t>(fileSize));
ifs.read(bytes.data(), fileSize);
- return std::string(bytes.data(), fileSize);
+ return {bytes.data(), static_cast<std::size_t>(fileSize)};
}
std::vector<std::string> readDeps(const std::string& depFile)