Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit c155f16

Browse files
committed
Simplify the logic for truncating UID and GID. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313933 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 08eb053 commit c155f16

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

lib/Object/ArchiveWriter.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,12 @@ Expected<NewArchiveMember> NewArchiveMember::getFile(StringRef FileName,
111111
}
112112

113113
template <typename T>
114-
static void printWithSpacePadding(raw_fd_ostream &OS, T Data, unsigned Size,
115-
bool MayTruncate = false) {
114+
static void printWithSpacePadding(raw_fd_ostream &OS, T Data, unsigned Size) {
116115
uint64_t OldPos = OS.tell();
117116
OS << Data;
118117
unsigned SizeSoFar = OS.tell() - OldPos;
119-
if (Size > SizeSoFar) {
120-
OS.indent(Size - SizeSoFar);
121-
} else if (Size < SizeSoFar) {
122-
assert(MayTruncate && "Data doesn't fit in Size");
123-
// Some of the data this is used for (like UID) can be larger than the
124-
// space available in the archive format. Truncate in that case.
125-
OS.seek(OldPos + Size);
126-
}
118+
assert(SizeSoFar <= Size && "Data doesn't fit in Size");
119+
OS.indent(Size - SizeSoFar);
127120
}
128121

129122
static bool isBSDLike(object::Archive::Kind Kind) {
@@ -153,8 +146,12 @@ static void printRestOfMemberHeader(
153146
raw_fd_ostream &Out, const sys::TimePoint<std::chrono::seconds> &ModTime,
154147
unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
155148
printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
156-
printWithSpacePadding(Out, UID, 6, true);
157-
printWithSpacePadding(Out, GID, 6, true);
149+
150+
// The format has only 6 chars for uid and gid. Truncate if the provided
151+
// values don't fit.
152+
printWithSpacePadding(Out, UID % 1000000, 6);
153+
printWithSpacePadding(Out, GID % 1000000, 6);
154+
158155
printWithSpacePadding(Out, format("%o", Perms), 8);
159156
printWithSpacePadding(Out, Size, 10);
160157
Out << "`\n";

0 commit comments

Comments
 (0)