grahamsedman opened a new pull request, #13194:
URL: https://github.com/apache/trafficserver/pull/13194
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
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:**
- [x] Compilation errors resolved (`-Wformat`)
- [x] 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
--
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]