aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-06-30 19:52:22 +0200
committerGitHub <noreply@github.com>2020-06-30 19:52:22 +0200
commitee1582494e458bf83535986b2a5bca32687420c5 (patch)
tree5a53ba43e8818f6673ea7417645dafce6150f5f3 /src
parent2b834d48aae35c5050895fac540ca55387925d0f (diff)
parenta0705e0dd152f2a19d096d02024723a5614c7726 (diff)
Merge pull request #3767 from bburdette/pos-null-check
Pos null check
Diffstat (limited to 'src')
-rw-r--r--src/libutil/error.hh6
-rw-r--r--src/libutil/tests/logging.cc18
2 files changed, 23 insertions, 1 deletions
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/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;
+
+ }
+
}