Skip to content

Commit 2a8875b

Browse files
fix: purely disabled any rtti and exceptions
1 parent c99a474 commit 2a8875b

7 files changed

Lines changed: 20 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ target_include_directories(cfbox PUBLIC include)
5656
target_include_directories(cfbox PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include)
5757
target_link_libraries(cfbox PRIVATE cfbox_compiler_flags)
5858

59+
# ── Install target ─────────────────────────────────────────────
60+
install(TARGETS cfbox DESTINATION bin)
61+
5962
# ── GTest via CPM (FetchContent) ──────────────────────────────
6063
if(NOT CMAKE_CROSSCOMPILING)
6164
CPMAddPackage(

cmake/compile/CompilerFlag.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ target_compile_options(cfbox_compiler_flags INTERFACE
2727
-Wnull-dereference
2828
-Wdouble-promotion
2929
-Wformat=2
30+
-Wformat-signedness
31+
-Wstrict-aliasing
32+
-fno-exceptions
33+
-fno-rtti
3034
)
3135

3236
# ── Debug-specific flags ──────────────────────────────────────

src/applets/ar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ auto ar_main(int argc, char* argv[]) -> int {
5454
std::memset(hdr, ' ', 60);
5555
std::memcpy(hdr, fname.c_str(), std::min(fname.size(), static_cast<std::size_t>(16)));
5656
std::snprintf(hdr + 16, 12, "%-10lu", static_cast<unsigned long>(::time(nullptr)));
57-
std::snprintf(hdr + 28, 12, "%-6u", 0); // uid
58-
std::snprintf(hdr + 34, 12, "%-6u", 0); // gid
59-
std::snprintf(hdr + 40, 12, "%-8o", 0100644);
57+
std::snprintf(hdr + 28, 12, "%-6u", 0u); // uid
58+
std::snprintf(hdr + 34, 12, "%-6u", 0u); // gid
59+
std::snprintf(hdr + 40, 12, "%-8o", 0100644u);
6060
std::snprintf(hdr + 48, 12, "%-10zu", data->size());
6161
hdr[58] = '`'; hdr[59] = '\n';
6262
output.append(hdr, 60);

src/applets/hostid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ auto hostid_main(int argc, char* argv[]) -> int {
2222
if (parsed.has_long("version")) { cfbox::help::print_version(HELP); return 0; }
2323

2424
long id = gethostid();
25-
std::printf("%08lx\n", id);
25+
std::printf("%08ld\n", id);
2626
return 0;
2727
}

src/applets/install.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,20 @@ auto install_main(int argc, char* argv[]) -> int {
3636
auto target_dir = parsed.get_any('t', "target-directory");
3737
const auto& pos = parsed.positional();
3838

39-
auto parse_mode = [](const std::string& s) -> std::filesystem::perms {
40-
unsigned long m = std::stoul(s, nullptr, 8);
41-
return static_cast<std::filesystem::perms>(m);
42-
};
43-
4439
std::filesystem::perms mode = std::filesystem::perms::owner_read |
4540
std::filesystem::perms::owner_write |
4641
std::filesystem::perms::group_read |
4742
std::filesystem::perms::others_read;
4843
if (mode_str) {
49-
try { mode = parse_mode(std::string{*mode_str}); }
50-
catch (...) {
44+
char* end = nullptr;
45+
errno = 0;
46+
unsigned long m = std::strtoul(mode_str->data(), &end, 8);
47+
if (errno != 0 || end == mode_str->data() || *end != '\0') {
5148
std::fprintf(stderr, "cfbox install: invalid mode '%.*s'\n",
5249
static_cast<int>(mode_str->size()), mode_str->data());
5350
return 1;
5451
}
52+
mode = static_cast<std::filesystem::perms>(m);
5553
}
5654

5755
if (mkdir_mode) {

src/applets/stat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ auto stat_main(int argc, char* argv[]) -> int {
155155
file_type_string(st.st_mode));
156156
auto* pw = getpwuid(st.st_uid);
157157
auto* gr = getgrgid(st.st_gid);
158-
std::printf("Access: (%04o/%s) Uid: (%5d/%-8s) Gid: (%5d/%-8s)\n",
159-
st.st_mode & 07777,
158+
std::printf("Access: (%04o/%s) Uid: (%5u/%-8s) Gid: (%5u/%-8s)\n",
159+
st.st_mode & 07777u,
160160
format_perms(st.st_mode).c_str(),
161161
st.st_uid, pw ? pw->pw_name : "",
162162
st.st_gid, gr ? gr->gr_name : "");

src/applets/sum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ auto sum_main(int argc, char* argv[]) -> int {
4040

4141
if (sysv) {
4242
auto result = cfbox::checksum::sysv_sum(*data_result);
43-
std::printf("%d %d", result.checksum, result.blocks);
43+
std::printf("%u %u", result.checksum, result.blocks);
4444
} else {
4545
auto result = cfbox::checksum::bsd_sum(*data_result);
46-
std::printf("%05d %5d", result.checksum, result.blocks);
46+
std::printf("%05u %5u", result.checksum, result.blocks);
4747
}
4848
if (p != "-") std::printf(" %.*s", static_cast<int>(p.size()), p.data());
4949
std::putchar('\n');

0 commit comments

Comments
 (0)