Skip to content

Commit 8fd6df6

Browse files
committed
project Many small misc changes
1 parent c63fc52 commit 8fd6df6

File tree

17 files changed

+153
-139
lines changed

17 files changed

+153
-139
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ target_compile_options(ktool PUBLIC
2828
-Wstrict-overflow=5 -Wundef -Wnull-dereference -funsigned-char
2929
-fno-exceptions -Wcast-align -Wfloat-equal -Wredundant-decls
3030
-Wstrict-overflow=5 -Wundef -Wnull-dereference -funsigned-char -Wformat=2
31-
-DBUILD_KERNEL -Wno-address-of-packed-member)
31+
-DBUILD_KERNEL -Wno-address-of-packed-member -Wthread-safety)
3232

3333
target_link_options(ktool PUBLIC -stdlib=libc++)
3434
target_link_options(ktool PUBLIC -fuse-ld=lld)
@@ -45,7 +45,8 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
4545
"-fsanitize=address" "-fsanitize=undefined")
4646
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
4747
set_target_properties(ktool PROPERTIES OUTPUT_NAME "ktool_release")
48-
target_compile_options(ktool PRIVATE "-O3" "-Wno-unused-parameter" "-Wno-gnu-statement-expression-from-macro-expansion")
48+
target_compile_options(ktool PRIVATE "-O3" "-Wno-unused-parameter"
49+
"-Wno-gnu-statement-expression-from-macro-expansion")
4950
target_link_options(ktool PRIVATE "-O3")
5051
endif()
5152

include/ADT/Range.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ namespace ADT {
4949
}
5050

5151
[[nodiscard]] constexpr static
52-
auto FromEnd(const uint64_t Begin, const uint64_t End) noexcept {
53-
assert(Begin <= End);
54-
return Range::FromSize(Begin, (End - Begin));
52+
auto FromEnd(const uint64_t Begin, const uint64_t End) noexcept
53+
-> std::optional<Range>
54+
{
55+
if (Begin <= End) {
56+
return Range::FromSize(Begin, (End - Begin));
57+
}
58+
59+
return std::nullopt;
5560
}
5661

5762
[[nodiscard]] constexpr auto front() const noexcept {

include/MachO/ExportTrie.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,8 @@ namespace MachO {
540540
return this->Kind;
541541
}
542542

543-
[[nodiscard]]
544-
constexpr auto string() const noexcept -> std::string_view {
545-
return this->String;
543+
[[nodiscard]] constexpr auto string() const noexcept {
544+
return std::string_view(this->String);
546545
}
547546

548547
constexpr auto setKind(const ExportTrieExportKind Kind) noexcept

include/Objects/DscImage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace Objects {
6262

6363
constexpr Error(const OpenError Kind) noexcept : Kind(Kind) {}
6464

65+
[[nodiscard]]
6566
static inline auto invalidAddress(const uint64_t Address) noexcept {
6667
auto Result = Error(OpenError::InvalidAddress);
6768
Result.InvalidAddress.Address = Address;

include/Utils/Print.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ namespace Utils {
104104
: Begin(Begin), Size(Size) {}
105105

106106
explicit PrintRange(const ADT::Range Range) noexcept
107-
: Begin(Range.front()), Size(Range.size()) {}
107+
: Begin(static_cast<T>(Range.front())),
108+
Size(static_cast<U>(Range.size())) {}
108109

109110
[[nodiscard]] constexpr auto front() const noexcept {
110111
return this->Begin;
@@ -140,17 +141,6 @@ namespace Utils {
140141
bool Value;
141142
};
142143

143-
auto
144-
PrintOffsetSizeInfo(FILE *OutFile,
145-
const ADT::Range Range,
146-
bool Is64Bit,
147-
bool IsSize64Bit,
148-
bool IsOutOfBounds,
149-
std::string_view OffsetKey,
150-
std::string_view SizeKey,
151-
std::string_view Prefix = "",
152-
std::string_view Suffix = "") noexcept -> int;
153-
154144
auto
155145
PrintDylibOrdinalPath(FILE *OutFile,
156146
uint8_t DylibOrdinal,

src/ADT/Trie.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ namespace ADT {
3838
return Error::InvalidFormat;
3939
}
4040

41-
const auto Range = ADT::Range::FromEnd(Offset, OffsetEndOpt.value());
41+
const auto RangeOpt = ADT::Range::FromEnd(Offset, OffsetEndOpt.value());
42+
if (!RangeOpt.has_value()) {
43+
return Error::InvalidFormat;
44+
}
45+
46+
const auto Range = RangeOpt.value();
4247
const auto Predicate = [Range](const ADT::Range RhsRange) noexcept {
4348
return Range.overlaps(RhsRange);
4449
};

src/MachO/SegmentList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ namespace MachO {
129129
for (const auto &SegInfo : this->List | std::views::filter(Filter)) {
130130
const uint64_t VmIndex = SegInfo.VmRange.indexForLoc(VmAddr);
131131
if (!SegInfo.FileRange.hasIndex(VmIndex)) {
132-
return std::nullopt;
132+
continue;
133133
}
134134

135135
if (!SegInfo.FileRange.hasEndIndex(VmIndex + Size)) {
136-
return std::nullopt;
136+
continue;
137137
}
138138

139139
return SegInfo.FileRange.locForIndex(VmIndex);

src/Objects/DscImage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace Objects {
111111

112112
auto FileSize = uint64_t();
113113
if (Header->is64Bit()) {
114-
for (const auto &Segment :
114+
for (const auto Segment :
115115
LoadCommandsMap |
116116
::MachO::LCMapFilterType<
117117
::MachO::SegmentCommand64>(IsBigEndian))
@@ -140,7 +140,7 @@ namespace Objects {
140140
FileSize = NewFileSize.value();
141141
}
142142
} else {
143-
for (const auto &Segment :
143+
for (const auto Segment :
144144
LoadCommandsMap |
145145
::MachO::LCMapFilterType<
146146
::MachO::SegmentCommand>(IsBigEndian))

src/Objects/MachO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ namespace Objects {
122122
});
123123
}
124124

125-
return ADT::Range::FromEnd(Base, End);
125+
return ADT::Range::FromEnd(Base, End).value();
126126
}
127127
}

src/Operations/PrintBindOpcodeList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ namespace Operations {
4545
if (!Flags.empty()) {
4646
std::println(OutFile, "");
4747
if (Flags.hasNonWeakDefinition()) {
48-
std::println(OutFile, "\t\tHas Non-Weak Definition");
48+
std::println(OutFile, "\t\t" "Has Non-Weak Definition");
4949
}
5050

5151
if (Flags.isWeakImport()) {
52-
std::println(OutFile, "\t\tWeak-Import");
52+
std::println(OutFile, "\t\t" "Weak-Import");
5353
}
5454
} else {
5555
std::println(OutFile, " None");

0 commit comments

Comments
 (0)