refactor(clang-tidy): behaviour-preserving modernize sweep of CoolPropLib.cpp (CoolProp-jtl)#2985
Conversation
#2926) Behaviour-preserving clang-tidy cleanup of the C API translation unit, clearing the 24 whole-file signal findings surfaced while running preflight for #2873: - insecureAPI.strcpy (7): strcpy -> std::memcpy(dst, s.c_str(), s.size()+1). Every site was already guarded by `if (s.size() < buffer_length)`, with strict `<` against the buffer length that bounds the destination, so the copy of size+null always fits. Behaviour identical; just drops the categorically-banned strcpy. - readability-implicit-bool-conversion (6): explicit returns/casts (return true/false -> 1/0 in int APIs; static_cast for bool->long/int). - modernize-raw-string-literal (4): escaped-quote format strings -> R"(...)". - modernize-use-scoped-lock (3): std::lock_guard -> std::scoped_lock. - use-default-member-init (1): AbstractStateLibrary::next_handle in-class init + ctor = default. - performance-unnecessary-value-param (1): add() takes shared_ptr by const ref. - modernize-use-auto (1): map iterator -> auto. - cppcoreguidelines-special-member-functions (1): fpu_reset_guard declares deleted copy/move (it is an RAII scope guard, never copied). pro-bounds-pointer-arithmetic findings are intentionally left untouched — they are in preflight's noise-filter (CI does not enforce them on this inherently pointer-based array C API). Preflight green (build, tests, cppcheck, clang-tidy 0 signal, semgrep); adversarial pre-PR review found no blocking issues. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR improves buffer safety and type consistency in CoolProp's C-API layer ( ChangesCoolProp C-API Buffer Safety and Type Safety
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…yer 2) (#3018) Hand-written high-signal fixes from the layer-2 clang-tidy sweep (CoolProp-1pr), the follow-up to the #2926 triage after the first fix wave landed (#2978/#2980/#2983/#2985). - bugprone-exception-escape (FlashRoutines.cpp): wrap the ~solver_resid() RAII cleanup in try/catch. The dtor calls HEOS->unspecify_phase(); a throw escaping a destructor (implicitly noexcept) calls std::terminate. unspecify_phase() only resets a flag and shouldn't throw, but the guard makes the no-crash guarantee explicit. - bugprone-switch-missing-default-case x5 (HelmholtzEOSMixtureBackend.cpp): add default: break; to the four calc_saturation_ancillary Q-switches (they fall through to the existing "Q invalid" throw) and to the iDmolar phase-guess switch (falls through to the full VLE path). No behavior change; documents the unhandled arms. - bugprone-assignment-in-if-condition x3 (HumidAirProp.cpp): replace the if((key=get_input_key(...))>=0){} else-if chain (empty bodies, side- effecting condition) with sequential first-match assignment. Same priority order (HUMRAT > TDP > RH) and same throw on no match. - bugprone-macro-parentheses x2 (Configuration.cpp): parenthesize the String macro argument in the CONFIGURATION_KEYS_ENUM X-macro. Tests: [HAProps]/[humid_air*]/[ancillary]/[saturation] (4608 assertions, 23 cases) and the preflight [!slow][!benchmark] suite pass. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Resolves beads CoolProp-jtl. Continues the #2926 / CoolProp-2uw clang-tidy modernize series.
What
Clears the 24 whole-file clang-tidy signal findings in
src/CoolPropLib.cppthat were surfaced while running preflight for #2873 (PR #2983). All changes are behaviour-preserving.clang-analyzer-security.insecureAPI.strcpystrcpy→std::memcpy(dst, s.c_str(), s.size()+1)readability-implicit-bool-conversionreturn true/false→1/0; explicitstatic_castfor bool→long/intmodernize-raw-string-literalR"(...)"modernize-use-scoped-lockstd::lock_guard<std::mutex>→std::scoped_lock*-use-default-member-initAbstractStateLibrary::next_handlein-class init + ctor= defaultperformance-unnecessary-value-paramadd()takesshared_ptrby const refmodernize-use-autoautocppcoreguidelines-special-member-functionsfpu_reset_guarddeclares deleted copy/move (RAII scope guard)Why the strcpy → memcpy change is safe (not just silencing)
Every
strcpysite was already guarded by a precedingif (s.size() < buffer_length)with strict<against the buffer-length variable that bounds the destination buffer. Sos.size() + 1 <= buffer_length, andmemcpyofsize + null terminatoralways fits — byte-identical behaviour, minus the categorically-bannedstrcpy. (Confirmed per-site, includingAbstractState_fluid_param_stringcorrectly usingreturn_buffer_lengthrather than the unrelatedmessage_buffer/buffer_length.)Deliberately out of scope
cppcoreguidelines-pro-bounds-pointer-arithmeticfindings are left untouched — they sit in preflight's noise-filter and CI does not enforce them on this inherently pointer-based array C API.Verification
🤖 Generated with Claude Code
Summary by CodeRabbit