Skip to content

Fix safety, correctness, and modern C++ best practices across codebase#50

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/review-codebase-architecture-safety
Draft

Fix safety, correctness, and modern C++ best practices across codebase#50
Copilot wants to merge 2 commits intomasterfrom
copilot/review-codebase-architecture-safety

Conversation

Copy link

Copilot AI commented Mar 14, 2026

Code review identified memory leaks, undefined behavior, race conditions, a data-corruption bug, and several C++ antipatterns. This PR addresses the highest-impact issues.

Memory safety & RAII

  • Manager: Replaced vector<Student*> with vector<unique_ptr<Student>>. Eliminates manual delete loop in destructor and the memory leak in remove() (pointer was erased from the vector without being freed).
  • PID: Replaced raw PIDImpl* with unique_ptr<PIDImpl>, constructor uses make_unique, destructor becomes = default.

Bug fixes

  • Manager::remove(): Missing return after successful erasure caused "Student not found!" to always print, even on success.
  • Student::setCode(): name_.append(3, ' ') permanently corrupted the name_ member. The intent was to pad the local nameCode copy:
    // Before (bug): mutates the member
    name_.append(3, ' ');
    nameCode.resize(3);
    
    // After: pads only the local copy
    nameCode.append(3, ' ');
    nameCode.resize(3);

Thread safety

  • TCPServer: volatile bool running_std::atomic<bool>. volatile provides no cross-thread visibility or ordering guarantees.
  • Singleton: Non-thread-safe null-check pattern with a leaking raw pointer replaced with the Meyers singleton (static Singleton instance as a function-local static), which is guaranteed atomic since C++11.

Undefined behavior

  • ChainOfCommand: IHandler was deleted through a base pointer with no virtual destructor. Added virtual ~IHandler() = default.

Style & portability

  • pid.h/pid.cpp: Removed using namespace std; replaced reserved-identifier guards (_PID_H_, _PID_SOURCE_) with #pragma once.
  • Account.cpp, Student.cpp: time(NULL)time(nullptr).
  • SharingData.cpp: Added missing override on all four virtual overrides.
  • TwoSum.cpp, main.cpp: Fixed int/size_t signed-unsigned comparison warnings.
  • Facade.cpp: Replaced GCC-only Elvis operator (s1 ?: new X) with standard ternary (s1 ? s1 : new X).

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: urbytes21 <118428350+urbytes21@users.noreply.github.com>
Copilot AI changed the title [WIP] Review repository architecture and safety practices Fix safety, correctness, and modern C++ best practices across codebase Mar 14, 2026
Copilot AI requested a review from urbytes21 March 14, 2026 03:27
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.

2 participants