Copilot commented on code in PR #13805:
URL: https://github.com/apache/trafficserver/pull/13805#discussion_r4314192510


##########
plugins/experimental/abuse_shield/unit_tests/test_config.cc:
##########
@@ -49,9 +53,14 @@ class TempConfig
 public:
   TempConfig()
   {
-    auto suffix = std::chrono::steady_clock::now().time_since_epoch().count();
-    dir_        = std::filesystem::temp_directory_path() / 
("abuse_shield_config_test_" + std::to_string(suffix));
-    std::filesystem::create_directories(dir_);
+    auto  dir_template = (std::filesystem::temp_directory_path() / 
"abuse_shield_config_test_XXXXXX").string();
+    auto *created_dir  = mkdtemp(dir_template.data());

Review Comment:
   `mkdtemp()` requires a writable, null-terminated buffer. Using 
`std::string::data()` as writable storage is only guaranteed in C++17+; if this 
code is ever compiled under an older standard, it can fail to compile or behave 
incorrectly. Consider using `&dir_template[0]` (for a non-empty string) or 
otherwise ensure/guard that the build standard guarantees writable `data()`.



##########
plugins/experimental/abuse_shield/unit_tests/test_config.cc:
##########
@@ -49,9 +53,14 @@ class TempConfig
 public:
   TempConfig()
   {
-    auto suffix = std::chrono::steady_clock::now().time_since_epoch().count();
-    dir_        = std::filesystem::temp_directory_path() / 
("abuse_shield_config_test_" + std::to_string(suffix));
-    std::filesystem::create_directories(dir_);
+    auto  dir_template = (std::filesystem::temp_directory_path() / 
"abuse_shield_config_test_XXXXXX").string();
+    auto *created_dir  = mkdtemp(dir_template.data());
+
+    if (created_dir == nullptr) {
+      INFO(std::strerror(errno));
+      REQUIRE(created_dir != nullptr);
+    }

Review Comment:
   `errno` can be overwritten by subsequent library calls, and the current 
pattern checks the same condition twice. Prefer capturing `errno` immediately 
after the `mkdtemp` call and using a single assertion with an explicit message 
(e.g., `REQUIRE_MESSAGE(created_dir != nullptr, std::strerror(saved_errno))`) 
so the failure reason is reliably reported.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to