-
Notifications
You must be signed in to change notification settings - Fork 0
Pr2 propelcode ev #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
|
|
||
| load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
|
|
||
| alias( | ||
| name = "solid_violations", | ||
| actual = "//score/evaluation/solid:solid_violations", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "memory_issues", | ||
| actual = "//score/evaluation/memory:memory_issues", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "non_idiomatic_cpp", | ||
| actual = "//score/evaluation/idiomatic:non_idiomatic_cpp", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "modern_cpp_syntax", | ||
| actual = "//score/evaluation/modern_cpp:modern_cpp_syntax", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "design_patterns", | ||
| actual = "//score/evaluation/patterns:design_patterns", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "code_optimization", | ||
| actual = "//score/evaluation/optimization:code_optimization", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "safe_cpp", | ||
| actual = "//score/evaluation/safety:safe_cpp", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "security_issues", | ||
| actual = "//score/evaluation/security:security_issues", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "design_faults", | ||
| actual = "//score/evaluation/design:design_faults", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "concurrency_issues", | ||
| actual = "//score/evaluation/concurrency:concurrency_issues", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "exception_error_handling", | ||
| actual = "//score/evaluation/exception_handling:exception_error_handling", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "unit_test_quality", | ||
| actual = "//score/evaluation/unit_test_quality:unit_test_quality", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "template_metaprogramming_issues", | ||
| actual = "//score/evaluation/template_metaprogramming:template_metaprogramming_issues", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "unit_test_quality_test", | ||
| actual = "//score/evaluation/unit_test_quality:unit_test_quality_test", | ||
| ) | ||
|
|
||
| cc_binary( | ||
| name = "evaluation_all", | ||
| srcs = ["evaluation_main.cpp"], | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//score/evaluation/concurrency:concurrency_issues", | ||
| "//score/evaluation/design:design_faults", | ||
| "//score/evaluation/exception_handling:exception_error_handling", | ||
| "//score/evaluation/idiomatic:non_idiomatic_cpp", | ||
| "//score/evaluation/memory:memory_issues", | ||
| "//score/evaluation/modern_cpp:modern_cpp_syntax", | ||
| "//score/evaluation/optimization:code_optimization", | ||
| "//score/evaluation/patterns:design_patterns", | ||
| "//score/evaluation/security:security_issues", | ||
| "//score/evaluation/safety:safe_cpp", | ||
| "//score/evaluation/solid:solid_violations", | ||
| "//score/evaluation/template_metaprogramming:template_metaprogramming_issues", | ||
| "//score/evaluation/unit_test_quality:unit_test_quality", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| cc_library( | ||
| name = "concurrency_issues", | ||
| hdrs = ["concurrency_issues.h"], | ||
| visibility = ["//visibility:public"], | ||
| ) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,148 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifndef SCORE_EVALUATION_CONCURRENCY_ISSUES_H | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define SCORE_EVALUATION_CONCURRENCY_ISSUES_H | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <atomic> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <condition_variable> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <mutex> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <thread> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace score | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace evaluation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class UnsafeCounter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void Increment() { ++count_; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int Get() const { return count_; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int count_{0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ManualLockUser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void Write(const std::string& data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mtx_.lock(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Reliability]
Suggested change
Context for Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ProcessData(data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mtx_.unlock(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void ProcessData(const std::string& /*data*/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::mutex mtx_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class BrokenLazyInit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void EnsureInitialised() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!initialised_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Logic]
Suggested change
Context for Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::lock_guard<std::mutex> lk(mtx_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!initialised_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resource_ = 42; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialised_ = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int GetResource() const { return resource_; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool initialised_{false}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int resource_{0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::mutex mtx_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class DeadlockProne | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void TransferAB(int amount) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::lock_guard<std::mutex> la(mtx_a_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Logic]
Suggested change
Context for Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::lock_guard<std::mutex> lb(mtx_b_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| balance_a_ -= amount; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| balance_b_ += amount; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void TransferBA(int amount) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::lock_guard<std::mutex> lb(mtx_b_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::lock_guard<std::mutex> la(mtx_a_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| balance_b_ -= amount; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| balance_a_ += amount; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::mutex mtx_a_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::mutex mtx_b_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int balance_a_{1000}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int balance_b_{1000}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class SpuriousWakeupBug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void Wait() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::mutex> lk(mtx_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!ready_) cv_.wait(lk); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+98
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Reliability] std::unique_lock<std::mutex> lk(mtx_);
cv_.wait(lk, [this]() { return ready_; });Context for Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void Signal() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::lock_guard<std::mutex> lk(mtx_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ready_ = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cv_.notify_one(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::mutex mtx_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::condition_variable cv_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool ready_{false}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inline void StartDetachedThread() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string local_config = "config_data"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::thread t([&local_config]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Reliability]
Suggested change
Context for Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (void)local_config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.detach(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class TocTouAtomic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void ConsumeIfAvailable() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (count_.load() > 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Logic]
Suggested change
Context for Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --count_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void Produce() { ++count_; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::atomic<int> count_{0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif // SCORE_EVALUATION_CONCURRENCY_ISSUES_H | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| cc_library( | ||
| name = "design_faults", | ||
| hdrs = ["design_faults.h"], | ||
| visibility = ["//visibility:public"], | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Logic]
UnsafeCounter::Increment()performs a read-modify-write operation (++count_) on a shared mutable integer (count_) without any synchronization mechanism (like a mutex orstd::atomic). In a multi-threaded environment, this will lead to a data race, causing incorrect counts and undefined behavior.Context for Agents