Skip to content

Refactor includes and fix clang errors/warnings in (MatcherUtils.h, MatcherUtils.cc) generating compilation error during build#13194

Open
grahamsedman wants to merge 2 commits into
apache:masterfrom
grahamsedman:fix/src-tscore-matcher-utils-errors
Open

Refactor includes and fix clang errors/warnings in (MatcherUtils.h, MatcherUtils.cc) generating compilation error during build#13194
grahamsedman wants to merge 2 commits into
apache:masterfrom
grahamsedman:fix/src-tscore-matcher-utils-errors

Conversation

@grahamsedman
Copy link
Copy Markdown

This PR addresses specific compilation errors and warnings raised by Clang and Clang-tidy regarding format specifiers and C-style casts in MatcherUtils.cc.

Changes:

  1. Fix Format Specifier Errors (Line 116):

    • Problem: Clang reported that the format specifier %ld expects long, but the provided arguments read_size and file_size are of type ssize_t (which maps to int in the compilation environment triggering the error).
    • Solution: Updated the format string to use %zd, which is the correct specifier for ssize_t.
  2. Fix C-Style Cast Warning (Line 145):

    • Problem: clang-tidy (google-readability-casting) flagged the C-style cast (char **)nullptr inside the strtol call.
    • Solution: Replaced the C-style cast with an explicit static_cast<char **>(nullptr).

Related Files:

  • src/tscore/MatcherUtils.cc

Diff:

diff --git a/src/tscore/MatcherUtils.cc b/src/tscore/MatcherUtils.cc
index ..hash.. ..hash.. 100644
--- a/src/tscore/MatcherUtils.cc
+++ b/src/tscore/MatcherUtils.cc
@@ -113,7 +113,7 @@ matcher_line(char *buf, int *line_no, const char *file_path, const char *module
   if (read_size != file_size) {
     // Error, didn't read whole file
-    Error("%s Only able to read %ld bytes out %ld for %s file", module_name, read_size, file_size, file_path);
+    Error("%s Only able to read %zd bytes out %zd for %s file", module_name, read_size, file_size, file_path);
   }
   return result;
 }
@@ -142,7 +142,7 @@ hexToByte(const char *str, char *write)
   // Make sure we only take the bottom 8 bits of the result
   // of the conversion.
   long val = strtol(subStr, (char **)nullptr, 16);
-  *write    = static_cast<char>(strtol(subStr, (char **)nullptr, 16));
+  *write    = static_cast<char>(strtol(subStr, static_cast<char **>(nullptr), 16));
   return 2;
 }

Checks:

  • Compilation errors resolved (-Wformat)
  • Clang-tidy warnings resolved (google-readability-casting)

Compilation Errors

/home/grahamsedman/Projects/trafficserver/src/tscore/MatcherUtils.cc:116:78: error: format specifies type 'long' but the argument has type 'ssize_t' (aka 'int') [-Werror,-Wformat]
116 | Error("%s Only able to read %ld bytes out %ld for %s file", module_name, read_size, file_size, file_path);
| ~~~ ^~~~~~~~~
| %zd

@grahamsedman grahamsedman changed the title Refactor includes and fix clang errors/warnings in (MatcherUtils.h, MatcherUtils.cc) generating compilation errors during build Refactor includes and fix clang errors/warnings in (MatcherUtils.h, MatcherUtils.cc) generating compilation error during build May 22, 2026
Revised includes headers to remove the unused tscore/Result.h header and
add the tscore/ink_platform.h header.
Remove direct inclusions of ink_platform.h and ink_inet.h as they are
pulled in transitively via MatcherUtils.h. Reorder the remaining
include statements for better organisation.

Update format specifiers in readIntoBuffer to use %zd for ssize_t
variables to ensure correct formatting across different platforms.

Replace C-style cast with static_cast in unescapifyStr when passing
nullptr to strtol to adhere to C++ coding standards.
@grahamsedman grahamsedman force-pushed the fix/src-tscore-matcher-utils-errors branch from eeaf214 to b717414 Compare May 23, 2026 12:30
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.

1 participant