]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Don't read first character of empty strings
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 4 Feb 2023 14:33:45 +0000 (15:33 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Feb 2023 20:06:39 +0000 (21:06 +0100)
src/argprocessing.cpp

index 331bc90455a96104401b060da438a954940c7b02..f7f68007574b37221edda2339646a7025b6f2df2 100644 (file)
@@ -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;
   }