Repository navigation
test: comment UI review, v2 (v2.24.3) baseline - #92
shenxianpeng wants to merge 2 commits into
Conversation
Cpp-Linter Report
|
There was a problem hiding this comment.
Cpp-linter Review
Used clang-tidy v21.1.8
Only 14 out of 16 clang-tidy concerns fit within this pull request's diff.
Click here for the full clang-tidy patch
diff --git a/src/inventory.cpp b/src/inventory.cpp
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -2 +1,0 @@
-#include <cstring>
@@ -3,0 +3,3 @@
+#include <cstring>
+#include <string>
+#include <vector>
@@ -5,2 +7,3 @@
-void Inventory::add(Item item) {
- items_.push_back(item);
+void Inventory::add(const Item& item)
+{
+ items_.push_back(item);
@@ -9 +12 @@ void Inventory::add(Item item) {
-double Inventory::total_value() const
+auto Inventory::total_value() const -> double
@@ -12,2 +15,3 @@ double Inventory::total_value() const
- for (size_t index = 0; index < items_.size(); index++)
- total += items_[index].quantity*items_[index].price;
+ for (const auto& item : items_) {
+ total += item.quantity * item.price;
+ }
@@ -17,2 +21,3 @@ double Inventory::total_value() const
-std::string Inventory::report(std::vector<std::string> names) const {
- std::string out = "";
+std::string Inventory::report(const std::vector<std::string>& names)
+{
+ std::string out;
@@ -20 +25,3 @@ std::string Inventory::report(std::vector<std::string> names) const {
- if (name.empty()) continue;
+ if (name.empty()) {
+ continue;
+ }
@@ -26 +33 @@ std::string Inventory::report(std::vector<std::string> names) const {
-char* copy_label(const char* label)
+static auto copy_label(const char* label) -> char*
diff --git a/src/inventory.hpp b/src/inventory.hpp
--- a/src/inventory.hpp
+++ b/src/inventory.hpp
@@ -13 +13 @@ public:
- void add(Item item);
+ void add(const Item& item);
@@ -15 +15 @@ public:
- std::string report(std::vector<std::string> names) const;
+ static std::string report(conststd::vector<std::string>& names) ;
Used clang-format v21.1.8
Click here for the full clang-format patch
diff --git a/src/inventory.cpp b/src/inventory.cpp
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -2 +1,0 @@
-#include <cstring>
@@ -3,0 +3 @@
+#include <cstring>
@@ -5,2 +5,3 @@
-void Inventory::add(Item item) {
- items_.push_back(item);
+void Inventory::add(Item item)
+{
+ items_.push_back(item);
@@ -13 +14 @@ double Inventory::total_value() const
- total += items_[index].quantity*items_[index].price;
+ total += items_[index].quantity * items_[index].price;
@@ -17 +18,2 @@ double Inventory::total_value() const
-std::string Inventory::report(std::vector<std::string> names) const {
+std::string Inventory::report(std::vector<std::string> names) const
+{
@@ -19,2 +21,3 @@ std::string Inventory::report(std::vector<std::string> names) const {
- for(const auto& name : names) {
- if (name.empty()) continue;
+ for (const auto& name : names) {
+ if (name.empty())
+ continue;
✨ Powered by cpp-linter • 💬 Feedback
| @@ -0,0 +1,31 @@ | |||
| #include "inventory.hpp" | |||
| #include <cstring> | |||
There was a problem hiding this comment.
clang-format suggestion
Please remove the line(s)
- 2
clang-tidy suggestion
Please remove the line(s)
- 2
| @@ -0,0 +1,31 @@ | |||
| #include "inventory.hpp" | |||
| #include <cstring> | |||
| #include <cstdlib> | |||
There was a problem hiding this comment.
clang-format suggestion
| #include <cstdlib> | |
| #include <cstring> |
clang-tidy suggestion
| #include <cstdlib> | |
| #include <cstring> | |
| #include <string> | |
| #include <vector> |
| void Inventory::add(Item item) { | ||
| items_.push_back(item); |
There was a problem hiding this comment.
clang-format suggestion
| void Inventory::add(Item item) { | |
| items_.push_back(item); | |
| void Inventory::add(Item item) | |
| { | |
| items_.push_back(item); |
clang-tidy diagnostics
- the parameter 'item' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
| void Inventory::add(Item item) { | |
| items_.push_back(item); | |
| void Inventory::add(const Item& item) | |
| { | |
| items_.push_back(item); |
| { | ||
| double total = 0; | ||
| for (size_t index = 0; index < items_.size(); index++) | ||
| total += items_[index].quantity*items_[index].price; |
There was a problem hiding this comment.
clang-format suggestion
| total += items_[index].quantity*items_[index].price; | |
| total += items_[index].quantity * items_[index].price; |
| return total; | ||
| } | ||
|
|
||
| std::string Inventory::report(std::vector<std::string> names) const { |
There was a problem hiding this comment.
clang-format suggestion
| std::string Inventory::report(std::vector<std::string> names) const { | |
| std::string Inventory::report(std::vector<std::string> names) const | |
| { |
clang-tidy diagnostic
src/inventory.cpp:17:24: warning: [modernize-use-trailing-return-type]
use a trailing return type for this function
17 | std::string Inventory::report(std::vector<std::string> names) const {
| ^
note: this fix will not be applied because it overlaps with another fix|
|
||
| char* copy_label(const char* label) | ||
| { | ||
| char* buffer = (char*)malloc(strlen(label)); |
There was a problem hiding this comment.
clang-tidy diagnostic
src/inventory.cpp:28:5: warning: [cppcoreguidelines-owning-memory]
initializing non-owner 'char *' with a newly created 'gsl::owner<>'
28 | char* buffer = (char*)malloc(strlen(label));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~clang-tidy diagnostic
src/inventory.cpp:28:20: warning: [cppcoreguidelines-pro-type-cstyle-cast]
do not use C-style cast to convert between unrelated types
28 | char* buffer = (char*)malloc(strlen(label));
| ^clang-tidy diagnostic
src/inventory.cpp:28:27: warning: [cppcoreguidelines-no-malloc]
do not manage memory manually; consider a container or a smart pointer
28 | char* buffer = (char*)malloc(strlen(label));
| ^~~~~~~~~~~~~~~~~~~~~| char* copy_label(const char* label) | ||
| { | ||
| char* buffer = (char*)malloc(strlen(label)); | ||
| strcpy(buffer, label); |
There was a problem hiding this comment.
clang-tidy diagnostic
src/inventory.cpp:29:5: warning: [clang-analyzer-security.insecureAPI.strcpy]
Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
29 | strcpy(buffer, label);
| ^~~~~~
/home/runner/work/test-cpp-linter-action/test-cpp-linter-action/src/inventory.cpp:29:5: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
29 | strcpy(buffer, label);
| ^~~~~~|
|
||
| class Inventory { | ||
| public: | ||
| void add(Item item); |
There was a problem hiding this comment.
clang-tidy suggestion
| void add(Item item); | |
| void add(const Item& item); |
| public: | ||
| void add(Item item); | ||
| double total_value() const; | ||
| std::string report(std::vector<std::string> names) const; |
There was a problem hiding this comment.
clang-tidy diagnostics
- use a trailing return type for this function [modernize-use-trailing-return-type]
| std::string report(std::vector<std::string> names) const; | |
| static std::string report(conststd::vector<std::string>& names) ; |
| @@ -0,0 +1,19 @@ | |||
| #pragma once | |||
There was a problem hiding this comment.
clang-tidy diagnostic
src/inventory.hpp:1:1: warning: [portability-avoid-pragma-once]
avoid 'pragma once' directive; use include guards instead
1 | #pragma once
| ^
Renders the PR comment, review and step summary of cpp-linter-action v2 (v2.24.3) baseline on the same fixture (src/inventory.cpp) for a UI review. Do not merge.
Generated by Claude Code