Skip to content

Commit d354e8a

Browse files
authored
style(clang-tidy): fix modernize-avoid-c-arrays (#1814)
Signed-off-by: Balakrishna Avulapati <[email protected]>
1 parent bfda3a7 commit d354e8a

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/core/gzip/gzip.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern "C" {
44
#include <zlib.h>
55
}
66

7+
#include <array> // std::array
78
#include <cstring> // std::memset
89
#include <sstream> // std::ostringstream
910

@@ -21,14 +22,14 @@ auto gzip(std::string_view input) -> std::optional<std::string> {
2122
stream.next_in = reinterpret_cast<Bytef *>(const_cast<char *>(input.data()));
2223
stream.avail_in = static_cast<uInt>(input.size());
2324

24-
char buffer[4096];
25+
std::array<char, 4096> buffer;
2526
std::ostringstream compressed;
2627

2728
do {
28-
stream.next_out = reinterpret_cast<Bytef *>(buffer);
29+
stream.next_out = reinterpret_cast<Bytef *>(buffer.data());
2930
stream.avail_out = sizeof(buffer);
3031
code = deflate(&stream, Z_FINISH);
31-
compressed.write(buffer, sizeof(buffer) - stream.avail_out);
32+
compressed.write(buffer.data(), sizeof(buffer) - stream.avail_out);
3233
} while (code == Z_OK);
3334

3435
if (code != Z_STREAM_END) {

src/core/md5/md5.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <sourcemeta/core/md5.h>
22

3+
#include <array> // std::array
34
#include <iomanip> // std::setfill, std::setw
45
#include <ios> // std::hex
56

@@ -29,9 +30,10 @@ auto md5(std::string_view input, std::ostream &output) -> void {
2930
br_md5_context context;
3031
br_md5_init(&context);
3132
br_md5_update(&context, input.data(), input.size());
32-
unsigned char hash[br_md5_SIZE];
33-
br_md5_out(&context, hash);
34-
std::string_view buffer{reinterpret_cast<const char *>(hash), br_md5_SIZE};
33+
std::array<unsigned char, br_md5_SIZE> hash;
34+
br_md5_out(&context, hash.data());
35+
std::string_view buffer{reinterpret_cast<const char *>(hash.data()),
36+
br_md5_SIZE};
3537
output << std::hex << std::setfill('0');
3638
for (const auto character : buffer) {
3739
output << std::setw(2)

src/core/uri/escaping.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sourcemeta/core/uri_escape.h>
44

55
#include <algorithm> // std::copy
6+
#include <array> // std::array
67
#include <cassert> // assert
78
#include <cctype> // std::isalnum
89
#include <istream> // std::istream
@@ -14,7 +15,8 @@ namespace sourcemeta::core {
1415

1516
auto uri_escape(const char character, std::ostream &output,
1617
const URIEscapeMode mode) -> void {
17-
constexpr char HEX[] = "0123456789ABCDEF";
18+
const std::array<char, 16> HEX = {{'0', '1', '2', '3', '4', '5', '6', '7',
19+
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}};
1820

1921
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
2022
// See https://www.rfc-editor.org/rfc/rfc3986#appendix-A

0 commit comments

Comments
 (0)