Skip to content

Commit 5b7b69d

Browse files
authored
Merge pull request cms-sw#40778 from Dr15Jones/arrayDigest
Changed internals of Digest to use std::array
2 parents 3aa77af + af965c9 commit 5b7b69d

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

DataFormats/Provenance/src/Hash.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace edm {
7676
value_type temp1(hash);
7777
fixup_(temp1);
7878
cms::MD5Result temp;
79-
copy_all(temp1, temp.bytes);
79+
copy_all(temp1, temp.bytes.begin());
8080
result += temp.toString();
8181
}
8282

@@ -85,15 +85,15 @@ namespace edm {
8585
value_type temp1(hash);
8686
fixup_(temp1);
8787
cms::MD5Result temp;
88-
copy_all(temp1, temp.bytes);
88+
copy_all(temp1, temp.bytes.begin());
8989
digest.append(temp.toString());
9090
}
9191

9292
std::ostream& print_(std::ostream& os, value_type const& hash) {
9393
value_type temp1(hash);
9494
fixup_(temp1);
9595
cms::MD5Result temp;
96-
copy_all(temp1, temp.bytes);
96+
copy_all(temp1, temp.bytes.begin());
9797
os << temp.toString();
9898
return os;
9999
}

FWCore/Utilities/interface/Digest.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <iosfwd>
77
#include <string>
8+
#include <array>
89

910
namespace cms {
1011

@@ -15,7 +16,7 @@ namespace cms {
1516
MD5Result();
1617

1718
// This is the MD5 digest.
18-
unsigned char bytes[16];
19+
std::array<unsigned char, 16> bytes;
1920

2021
// Convert the digest to a printable string (the 'hexdigest')
2122
std::string toString() const;

FWCore/Utilities/src/Digest.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,25 @@ namespace cms {
9393
"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
9494

9595
std::string MD5Result::toString() const {
96-
char buf[16 * 2];
97-
char* pBuf = buf;
98-
for (unsigned int i = 0; i < sizeof(bytes); ++i) {
99-
const char* p = s_hexValues + 2 * bytes[i];
96+
std::array<char, 16 * 2> buf;
97+
char* pBuf = buf.begin();
98+
for (auto b : bytes) {
99+
const char* p = s_hexValues + 2 * b;
100100
*pBuf = *p;
101101
++pBuf;
102102
++p;
103103
*pBuf = *p;
104104
++pBuf;
105105
}
106-
return std::string(buf, sizeof(buf));
106+
return std::string(buf.begin(), buf.end());
107107
}
108108

109109
std::string MD5Result::compactForm() const {
110110
// This is somewhat dangerous, because the conversion of 'unsigned
111111
// char' to 'char' may be undefined if 'char' is a signed type
112112
// (4.7p3 in the Standard).
113-
const char* p = reinterpret_cast<const char*>(&bytes[0]);
114-
return std::string(p, p + sizeof(bytes));
113+
const char* p = reinterpret_cast<const char*>(bytes.data());
114+
return std::string(p, p + bytes.size());
115115
}
116116

117117
void MD5Result::fromHexifiedString(std::string const& hexy) {
@@ -139,11 +139,11 @@ namespace cms {
139139
bool MD5Result::isValid() const { return (*this != invalidResult()); }
140140

141141
bool operator==(MD5Result const& a, MD5Result const& b) {
142-
return std::equal(a.bytes, a.bytes + sizeof(a.bytes), b.bytes);
142+
return std::equal(a.bytes.begin(), a.bytes.end(), b.bytes.begin());
143143
}
144144

145145
bool operator<(MD5Result const& a, MD5Result const& b) {
146-
return std::lexicographical_compare(a.bytes, a.bytes + sizeof(a.bytes), b.bytes, b.bytes + sizeof(b.bytes));
146+
return std::lexicographical_compare(a.bytes.begin(), a.bytes.end(), b.bytes.begin(), b.bytes.end());
147147
}
148148

149149
//--------------------------------------------------------------------
@@ -170,7 +170,7 @@ namespace cms {
170170

171171
MD5Result Digest::digest() {
172172
MD5Result aDigest;
173-
md5_finish(&state_, aDigest.bytes);
173+
md5_finish(&state_, aDigest.bytes.data());
174174
return aDigest;
175175
}
176176
} // namespace cms

0 commit comments

Comments
 (0)