diff options
| author | Leonardo Guimaraes <leozinhoszg@gmail.com> | 2026-11-22 12:06:49 -0300 |
|---|---|---|
| committer | Leonardo Guimaraes <leozinhoszg@gmail.com> | 2026-11-22 12:06:49 -0300 |
| commit | d6443b152469c467f6295889de855b2931095161 (patch) | |
| tree | db225e8cbcf1a2cb45e867c2cb4b507191a39140 /runtime/src/main.cpp | |
| parent | 2dca597bd9f143992032010037f2d5c3b970d312 (diff) | |
Startup trace: never replace an existing file; write UTF-8 only
Review on #1756 (Vonsek):
- The trace is opened before the loader reads the image, so `wb` could
truncate an input named by mistake (the image itself). open() now
uses "x" mode and fails with EEXIST on an existing path; gta6rt says
so and exits with 2.
- OutputDebugStringA text is in the ANSI code page. It is converted
to UTF-8 before quoting, so a byte such as 0xE9 no longer breaks the
JSON lines. Host module names now come from GetModuleFileNameW,
converted to UTF-8, for the same reason.
startup_trace_test: an existing file is refused with EEXIST and its
bytes survive, the trace stays off; an ANSI debug string with 0xE9
appears as its UTF-8 form and the whole file is valid UTF-8.
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 5ac73301d..06baae387 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -85,8 +85,9 @@ int wmain(int argc, wchar_t** argv) { | |||
| 85 | if (overlay_dir.empty()) overlay_dir = game_dir / "overlay"; | 85 | if (overlay_dir.empty()) overlay_dir = game_dir / "overlay"; |
| 86 | rt::fs::configure(game_dir, overlay_dir); | 86 | rt::fs::configure(game_dir, overlay_dir); |
| 87 | rt::d3d12_trace::set_enabled(trace_d3d12); | 87 | rt::d3d12_trace::set_enabled(trace_d3d12); |
| 88 | if (!trace_file.empty() && !rt::startup_trace::open(trace_file.c_str())) { | 88 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { |
| 89 | std::fprintf(stderr, "error: cannot open the trace file\n"); | 89 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" |
| 90 | : "error: cannot create the trace file\n"); | ||
| 90 | return 2; | 91 | return 2; |
| 91 | } | 92 | } |
| 92 | 93 | ||