Fix safety, correctness, and modern C++ best practices across codebase#50
Draft
Fix safety, correctness, and modern C++ best practices across codebase#50
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: Replacedvector<Student*>withvector<unique_ptr<Student>>. Eliminates manualdeleteloop in destructor and the memory leak inremove()(pointer was erased from the vector without being freed).PID: Replaced rawPIDImpl*withunique_ptr<PIDImpl>, constructor usesmake_unique, destructor becomes= default.Bug fixes
Manager::remove(): Missingreturnafter successful erasure caused "Student not found!" to always print, even on success.Student::setCode():name_.append(3, ' ')permanently corrupted thename_member. The intent was to pad the localnameCodecopy:Thread safety
TCPServer:volatile bool running_→std::atomic<bool>.volatileprovides 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 instanceas a function-local static), which is guaranteed atomic since C++11.Undefined behavior
ChainOfCommand:IHandlerwas deleted through a base pointer with no virtual destructor. Addedvirtual ~IHandler() = default.Style & portability
pid.h/pid.cpp: Removedusing namespace std; replaced reserved-identifier guards (_PID_H_,_PID_SOURCE_) with#pragma once.Account.cpp,Student.cpp:time(NULL)→time(nullptr).SharingData.cpp: Added missingoverrideon all four virtual overrides.TwoSum.cpp,main.cpp: Fixedint/size_tsigned-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.