mirror of
https://github.com/NixOS/nix
synced 2025-06-30 11:43:15 +02:00
Merge branch 'master' into add-trace
This commit is contained in:
commit
ddb81ca126
19 changed files with 125 additions and 55 deletions
|
@ -262,7 +262,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
|
|||
names[name] = 0;
|
||||
}
|
||||
} else if (s == "node") {
|
||||
if (s.empty()) throw badArchive("entry name missing");
|
||||
if (name.empty()) throw badArchive("entry name missing");
|
||||
parse(sink, source, path + "/" + name);
|
||||
} else
|
||||
throw badArchive("unknown field " + s);
|
||||
|
|
|
@ -82,7 +82,11 @@ struct ErrPos {
|
|||
origin = pos.origin;
|
||||
line = pos.line;
|
||||
column = pos.column;
|
||||
file = pos.file;
|
||||
// is file symbol null?
|
||||
if (pos.file.set())
|
||||
file = pos.file;
|
||||
else
|
||||
file = "";
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace nix {
|
|||
MakeError(BadHash, Error);
|
||||
|
||||
|
||||
enum HashType : char { htMD5, htSHA1, htSHA256, htSHA512 };
|
||||
enum HashType : char { htMD5 = 42, htSHA1, htSHA256, htSHA512 };
|
||||
|
||||
|
||||
const int md5HashSize = 16;
|
||||
|
|
|
@ -334,4 +334,22 @@ namespace nix {
|
|||
"what about this " ANSI_YELLOW "%3%" ANSI_NORMAL " " ANSI_YELLOW "one" ANSI_NORMAL);
|
||||
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ErrPos
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(errpos, invalidPos) {
|
||||
|
||||
// contains an invalid symbol, which we should not dereference!
|
||||
Pos invalid;
|
||||
|
||||
// constructing without access violation.
|
||||
ErrPos ep(invalid);
|
||||
|
||||
// assignment without access violation.
|
||||
ep = invalid;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue