Merge pull request #3767 from bburdette/pos-null-check

Pos null check
This commit is contained in:
Eelco Dolstra 2020-06-30 19:52:22 +02:00 committed by GitHub
commit ee1582494e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -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;
}

View file

@ -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;
}
}