Skip to content

Commit fc4ad9d

Browse files
committed
[clang-doc] lower filename length limit by 5
The previous limit did not take into account filename extensions. Since the extensions we use (.yaml, .json, .html, .md) are at most 5 characters, we can lower the limit by 5. Also add some tests to make sure the rules are observed and don't explicitly crash clang-doc.
1 parent 790bee9 commit fc4ad9d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang-tools-extra/clang-doc/Serialize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,9 @@ static void populateSymbolInfo(SymbolInfo &I, const T *D, const FullComment *C,
778778
Mangler->mangleCXXVTable(CXXD, MangledStream);
779779
else
780780
MangledStream << D->getNameAsString();
781-
if (MangledName.size() > 255)
781+
// A 250 length limit was chosen since 255 is a common limit across
782+
// different filesystems, with a 5 character buffer for file extensions.
783+
if (MangledName.size() > 250)
782784
// File creation fails if the mangled name is too long, so default to the
783785
// USR. We should look for a better check since filesystems differ in
784786
// maximum filename length
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: clang-doc --output=%t --format=mustache --executor=standalone %s
3+
// RUN: ls %t/json | FileCheck %s -check-prefix=CHECK-JSON
4+
// RUN: ls %t/html | FileCheck %s -check-prefix=CHECK-HTML
5+
6+
struct ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12 {};
7+
8+
// This name is 1 character over the limit, so it will be serialized as a USR.
9+
struct ThisStructHasANameThatResultsInAMangledNameThatIsExactly251CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd123 {};
10+
11+
// CHECK-JSON: ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12.json
12+
// CHECK-JSON: {{[0-9A-F]*}}.json
13+
// CHECK-HTML: ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12.html
14+
// CHECK-HTML: {{[0-9A-F]*}}.html

0 commit comments

Comments
 (0)