Project ideas from Hacker News discussions.

C++ float-to-int conversion can be undefined behavior

📝 Discussion Summary (Click to expand)

1. UB is treated as “benign” only because of internal Microsoft knowledge

“It’s okay and if anyone is worried about it the use of UB is benign on the platforms we target…” — Herb Sutter

2. Procedural vs. technical special‑treatment of the GSL

“There is absolutely no special treatment afforded to the GSL by any of the target platforms…” — Maxatar

3. Calls for safer coding practices and language changes to eliminate UB

“The correct fix is to bounds‑check before casting.” — dmitrygr


🚀 Project Ideas

SafeCast

Summary

  • Provides a lightweight, constexpr‑friendly header‑only library that replaces unsafe static_cast<int>(double) with a checked conversion that either returns std::optional<int> or throws on overflow.
  • Solves the pain point of undefined behavior in numeric conversions by making the failure mode explicit and compile‑time detectable.

Details

Key Value
Target Audience C++ developers (embedded, game, finance) needing deterministic numeric casting
Core Feature constexpr safe cast with compile‑time static_assert support and runtime exception handling
Tech Stack C++20, no external dependencies, leverages std::bit_cast and std::from_chars
Difficulty Low
Monetization Hobby

Notes

  • HN commenters lamented UB in simple casts; this library gives them a safe, explicit alternative.
  • Clear utility for any project that must avoid crashes from out‑of‑range conversions, making it immediately valuable in discussions.

UBGuard

Summary

  • A Clang/GCC plugin that automatically scans code for patterns that invoke undefined behavior (e.g., static_cast<int>(double) with possible overflow) and annotates them with diagnostic warnings plus suggested safe replacements.
  • Addresses the frustration expressed about hidden UB and the desire for tooling that catches these issues early.

Details

Key Value
Target Audience Development teams maintaining large C++ codebases, especially security‑focused or safety‑critical projects
Core Feature Real‑time UB detection via LibTooling with auto‑fix suggestions (e.g., use std::clamp or std::bit_cast)
Tech Stack Clang LibTooling, LLVM, Python scripting, optional GCC plugin via GIMPLE
Difficulty Medium
Monetization Revenue-ready: Subscription $20/mo per developer

Notes

  • Commenters highlighted the need for tools that surface UB before it causes bugs; UBGuard provides that out‑of‑the‑box.
  • Integrates seamlessly into CI pipelines, turning a frequent discussion topic into a practical workflow improvement.

ConvertCI

Summary

  • A GitHub Action that checks pull‑request diffs for unsafe numeric casts and suggests concrete safe‑cast replacements, turning the conversation about UB into an automated review step.
  • Gives open‑source maintainers a concrete way to enforce safe coding standards without manual code review overhead.

Details

Key Value
Target Audience Open‑source maintainers, CI administrators, and contributors to C/C++ projects
Core Feature Scan PR diffs for patterns like static_cast<int>(double) and auto‑generate comment with safe alternative using std::from_chars
Tech Stack Node.js, Docker, GitHub Actions, regex‑based pattern matching
Difficulty Low
Monetization Revenue-ready: Pay‑per‑use $0.01 per scan

Notes

  • Directly references the Hacker News thread where users debated UB safety, turning that debate into a tangible CI tool.
  • Provides immediate practical utility, allowing teams to avoid the “odd” behavior described by commenters.

Read Later