[mlir] [lldb] [libc] [libcxxabi] [flang] [compiler-rt] [lld] [clang-tools-extra] [libcxx] [clang] [llvm] [libunwind] PR#72453 : Exceeding maximum file name length (PR #72654)

Todd A. Anderson via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 18 08:01:18 PST 2023


================
@@ -83,10 +85,29 @@ struct DOTGraphTraitsViewer
   StringRef Name;
 };
 
+static void shortenFileName(std::string &FN, unsigned char len = 250) {
+
+  FN = FN.substr(0, len);
+  if (nameObj.empty())
+    nameObj.push_back(FN);
+
+  else {
+    for (auto it = nameObj.begin(); it != nameObj.end(); it++) {
+      if (*it == FN) {
+        FN = FN.substr(0, --len);
----------------
DrTodd13 wrote:

Let's say that I have 3 filenames submitted in a row that share the same first 250 characters.  Line 92 will add the first one truncated to 250.  Then, line 97 will add the second one truncated to 249.  But then, for the third one, the first time through the nameObj list, it is going to match with the first name you added, decrement len by 1 and then add to nameObj.  So, I think the 2nd and 3rd names in your list are going to be duplicates.

Maybe a more classic way of doing this would be to use a set instead of a list, check if the FN truncated to 250 is in the set and if not add it.  If it is then truncate to 249 and repeat the process of checking if it is in the set.  Add if it isn't and if it is then truncate to 248 and keep repeating the process until it can be added.  Of course, this approach has the problem that if you have more than 250 names that shared the first 250 characters then len would go to 0 and you'd try to have a filename that was empty.  Then the 251st time you tried it you'd have a negative substr len.  If that is equivalent to 0 len then you could end up in an infinite loop.

https://github.com/llvm/llvm-project/pull/72654


More information about the cfe-commits mailing list