Skip to content

Conversation

Copy link

Copilot AI commented Dec 2, 2025

Static analysis and code review identified multiple instances of undefined behavior from accessing empty containers, plus a few other bugs.

Empty container access guards

  • molecule.h: is_protein() now checks atoms_->empty() before accessing [0]
  • bonds.cpp: get_bonds() and update_bonds() return early on empty input
  • pqr.cpp, cif.cpp, mol2.cpp: Guard molecules()[0] and atoms()[0] access
  • pdb.cpp: Throw FileException when structure.models is empty

Other fixes

  • ee_method.cpp: Division by zero guard in cover solver: if (charges_count[i] > 0)
  • common.cpp: Early return in get_element_symbol() for empty strings
  • python.cpp: Rename loop var chargeschg to avoid shadowing parameter
  • options.cpp: std::printstd::println for proper newline

Example fix

// Before - UB on empty atoms
bool is_protein() const { return not(*atoms_)[0].chain_id().empty(); }

// After
bool is_protein() const { return not atoms_->empty() and not(*atoms_)[0].chain_id().empty(); }

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Find bugs and improve code quality.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix bugs and improve code quality Fix undefined behavior from empty container access and other bugs Dec 2, 2025
Copilot AI requested a review from krab1k December 2, 2025 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants