summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2023-02-04 15:33:45 +0100
committerJoel Rosdahl <joel@rosdahl.net>2023-02-05 21:06:39 +0100
commitd45a55885c3437baa836a35224d8881f8bbff57a (patch)
treee508981cb4e631d02e88d2ecc0705b0e3e007d17
parent3781f2567d92f11a41fe5ba8099f8c9a6b5497d2 (diff)
downloadccache-d45a55885c3437baa836a35224d8881f8bbff57a.tar.gz
fix: Don't read first character of empty strings
-rw-r--r--src/argprocessing.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp
index 331bc904..f7f68007 100644
--- a/src/argprocessing.cpp
+++ b/src/argprocessing.cpp
@@ -268,7 +268,7 @@ std::string
make_dash_option(const Config& config, const std::string& arg)
{
std::string new_arg = arg;
- if (config.is_compiler_group_msvc() && arg[0] == '/') {
+ if (config.is_compiler_group_msvc() && util::starts_with(arg, "/")) {
// MSVC understands both /option and -option, so convert all /option to
// -option to simplify our handling.
new_arg[0] = '-';
@@ -303,7 +303,7 @@ process_option_arg(const Context& ctx,
std::string arg = make_dash_option(ctx.config, args[i]);
// Exit early if we notice a non-option argument right away.
- if (arg[0] != '-' && arg[0] != '@') {
+ if (arg.empty() || (arg[0] != '-' && arg[0] != '@')) {
return std::nullopt;
}