aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-06-25 15:50:30 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-06-25 15:50:30 +0200
commitde2641ae99965ecf88e6f72e3969c0c7b7e7020a (patch)
treedc5114198685b489771108e02c89597e83b51745 /src/libutil/hash.cc
parent3c50e84387e51858f10c540e721a938592f30949 (diff)
Fix empty std::optional dereference in writeDerivation()
https://hydra.nixos.org/build/123017579
Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r--src/libutil/hash.cc27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index c8fcdfed0..01fae3044 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -19,7 +19,7 @@ namespace nix {
void Hash::init()
{
- if (!type) abort();
+ assert(type);
switch (*type) {
case htMD5: hashSize = md5HashSize; break;
case htSHA1: hashSize = sha1HashSize; break;
@@ -101,15 +101,15 @@ static string printHash32(const Hash & hash)
string printHash16or32(const Hash & hash)
{
+ assert(hash.type);
return hash.to_string(hash.type == htMD5 ? Base16 : Base32, false);
}
-HashType assertInitHashType(const Hash & h) {
- if (h.type)
- return *h.type;
- else
- abort();
+HashType assertInitHashType(const Hash & h)
+{
+ assert(h.type);
+ return *h.type;
}
std::string Hash::to_string(Base base, bool includeType) const
@@ -363,14 +363,15 @@ HashType parseHashType(const string & s)
string printHashType(HashType ht)
{
switch (ht) {
- case htMD5: return "md5"; break;
- case htSHA1: return "sha1"; break;
- case htSHA256: return "sha256"; break;
- case htSHA512: return "sha512"; break;
+ case htMD5: return "md5";
+ case htSHA1: return "sha1";
+ case htSHA256: return "sha256";
+ case htSHA512: return "sha512";
+ default:
+ // illegal hash type enum value internally, as opposed to external input
+ // which should be validated with nice error message.
+ abort();
}
- // illegal hash type enum value internally, as opposed to external input
- // which should be validated with nice error message.
- abort();
}
}