diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-03 14:12:38 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-03 14:12:38 +0000 |
commit | 3134db1a8399a4d224eb615becddeee12419883f (patch) | |
tree | a1ead3593f243f24cecd9581348d88f9eb0211f4 /src/libutil | |
parent | 13796be78dfa9d3a189ea6b482659c56b1301634 (diff) | |
parent | dbffd309fed95d306135617fdc18ce4cf6109025 (diff) |
Merge branch 'hash-always-has-type' of github.com:obsidiansystems/nix into better-ca-parse-errors
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/archive.cc | 2 | ||||
-rw-r--r-- | src/libutil/error.hh | 6 | ||||
-rw-r--r-- | src/libutil/hash.cc | 2 | ||||
-rw-r--r-- | src/libutil/tests/logging.cc | 18 |
4 files changed, 25 insertions, 3 deletions
diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc index 6a8484705..51c88537e 100644 --- a/src/libutil/archive.cc +++ b/src/libutil/archive.cc @@ -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); diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 1e6102ce1..6982e30aa 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -67,7 +67,11 @@ struct ErrPos { { line = pos.line; column = pos.column; - file = pos.file; + // is file symbol null? + if (pos.file.set()) + file = pos.file; + else + file = ""; return *this; } diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 35054462c..4b82f191e 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -406,7 +406,7 @@ string printHashType(HashType ht) default: // illegal hash type enum value internally, as opposed to external input // which should be validated with nice error message. - abort(); + assert(false); } } diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc index 6a6fb4ac3..6a58b9425 100644 --- a/src/libutil/tests/logging.cc +++ b/src/libutil/tests/logging.cc @@ -289,4 +289,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; + + } + } |