Skip to content

Code review fixes: safety, performance, and correctness#38

Merged
rezdm merged 11 commits into
mainfrom
code-review-02
Feb 8, 2026
Merged

Code review fixes: safety, performance, and correctness#38
rezdm merged 11 commits into
mainfrom
code-review-02

Conversation

@rezdm

@rezdm rezdm commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace duplicate format_compact lambda with shared format_bytes() utility in ImGui system panel, and replace ostringstream with std::format for better performance
  • Validate socket path length against sockaddr_un::sun_path limit before using XDG_RUNTIME_DIR, with /tmp fallback
  • Narrow catch(...) to catch(const std::exception&) across 8 platform files to avoid silently swallowing std::bad_alloc
  • Use unordered_map for PID-keyed maps in DataStore and UI (O(1) vs O(log n) lookups on the hot path)
  • Use binary search (std::upper_bound) for thread library detection in address map
  • Cache kstat handle in Solaris system data provider with kstat_chain_update() instead of open/close per call
  • Add PID-reuse verification to FreeBSD and Solaris process tree kill, matching the existing Linux safety check
  • Document destruction ordering constraints for DataStore and providers in main.cpp / main_tui.cpp

Findings from the code review in code-review-4.6.md. One finding (#2 — remove ProcessNode::is_expanded) was investigated and found to be inaccurate (the field is used by ImGui), so it was skipped.

Test plan

  • Linux build passes (pex and pexc)
  • Verify FreeBSD build (CI)
  • Verify Solaris changes are consistent (manual review — no CI for Solaris)
  • Run pex and pexc on Linux, confirm system panel, process list, and kill functionality work

🤖 Generated with Claude Code

rezdm and others added 11 commits February 8, 2026 00:03
…ormat

- Remove local format_compact lambda from imgui_system_panel_view.cpp and
  use the shared pex::format_bytes() utility instead
- Replace std::ostringstream in format_bytes() with std::format for better
  performance in hot rendering paths

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The sun_path field in sockaddr_un has a platform-specific size limit
(~104-108 bytes). If XDG_RUNTIME_DIR produces a path exceeding this
limit, fall back to the /tmp-based path which always fits.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevents silently swallowing non-standard exceptions like std::bad_alloc
while still handling expected filesystem_error, invalid_argument, and
out_of_range exceptions from /proc iteration and string parsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace std::map with std::unordered_map for process_map,
previous_cpu_times_, and tree-building temporaries. These maps
are keyed by int PIDs and only need point lookups, making O(1)
hash lookups faster than O(log n) tree lookups on the hot path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace linear scan with std::upper_bound for O(log n) lookups
when mapping thread instruction pointers to library names. The
address_map from /proc/pid/maps is already sorted by start address.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace per-call kstat_open()/kstat_close() with a cached handle
that persists across calls. Uses kstat_chain_update() to keep the
chain current and reopens on failure. Eliminates ~5 kstat_open()
calls per data collection cycle.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Before sending signals during tree kill, re-verify that each PID still
refers to the original process by comparing start times. This prevents
accidentally killing an unrelated process if the PID was recycled
between collection and signal delivery, matching the existing Linux
implementation's safety check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comments in main.cpp and main_tui.cpp explaining why declaration
order matters (C++ destroys locals in reverse order, so providers must
be declared before DataStore). Also document the lifetime contract on
DataStore's constructor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Solaris pkg install returns exit code 4 when a package is already
installed ("no updates necessary"). Add || true to each pkg install
in the prepare step to prevent the VM's shell from aborting on this
non-error condition.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CMake's FetchContent needs git to clone GLFW. The Solaris VM image
previously included git but the current image does not.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Solaris's default make is dmake, which doesn't support GNU make's -j
flag syntax. Use CMAKE_MAKE_PROGRAM which resolves to gmake on Solaris
(since CMake uses GNU make as its generator).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rezdm rezdm merged commit 51ee225 into main Feb 8, 2026
6 checks passed
@rezdm rezdm deleted the code-review-02 branch February 8, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant