Răsfoiți Sursa

Merge topic 'linker-prefix-crash'

3993dc4214 Merge branch 'backport-linker-prefix-crash' into linker-prefix-crash
76f4fc7dd0 LINK_OPTIONS: Fix crash on empty LINKER: prefix

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !10066
Brad King 11 luni în urmă
părinte
comite
5d5aca82f1

+ 4 - 3
Source/cmGeneratorTarget_Options.cxx

@@ -548,8 +548,9 @@ std::vector<BT<std::string>>& cmGeneratorTarget::ResolvePrefixWrapper(
   const std::string SHELL{ "SHELL:" };
   const std::string PREFIX_SHELL = cmStrCat(PREFIX, SHELL);
 
-  for (auto entry = result.begin(); entry != result.end(); ++entry) {
+  for (auto entry = result.begin(); entry != result.end();) {
     if (entry->Value.compare(0, PREFIX.length(), PREFIX) != 0) {
+      ++entry;
       continue;
     }
 
@@ -594,10 +595,10 @@ std::vector<BT<std::string>>& cmGeneratorTarget::ResolvePrefixWrapper(
         entry,
         cmJoin(cmMakeRange(processedOptions.begin(), processedOptions.end()),
                " "_s));
-      entry = std::next(result.begin(), index);
+      entry = std::next(result.begin(), index + 1);
     } else {
       result.insert(entry, processedOptions.begin(), processedOptions.end());
-      entry = std::next(result.begin(), index + processedOptions.size() - 1);
+      entry = std::next(result.begin(), index + processedOptions.size());
     }
   }
   return result;

+ 1 - 0
Tests/RunCMake/target_link_options/LINKER_expansion.cmake

@@ -26,6 +26,7 @@ endfunction()
 # Use LINKER alone
 add_test_library(linker)
 target_link_options(linker PRIVATE "LINKER:-foo,bar")
+target_link_options(linker PRIVATE "LINKER:") # empty
 
 # Use LINKER with SHELL
 add_test_library(linker_shell)