From da1f872c50c0341c80c4897ccd2a8abcd9ea57e0 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 2 May 2022 20:08:22 +0100 Subject: [PATCH] [Minor] Handle unexpected cases --- src/libutil/cxx/locked_file.cxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libutil/cxx/locked_file.cxx b/src/libutil/cxx/locked_file.cxx index f392d9b4a5..13406c6cfc 100644 --- a/src/libutil/cxx/locked_file.cxx +++ b/src/libutil/cxx/locked_file.cxx @@ -30,6 +30,11 @@ auto raii_locked_file::open(const char *fname, int flags) -> tl::expected tl::ex #ifdef O_CLOEXEC oflags |= O_CLOEXEC | O_CREAT | O_EXCL; #endif + + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags, perms); if (fd == -1) { @@ -93,6 +103,10 @@ auto raii_locked_file::create_temp(const char *fname, int flags, int perms) -> t #ifdef O_CLOEXEC oflags |= O_CLOEXEC | O_CREAT | O_EXCL; #endif + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags, perms); if (fd == -1) { -- 2.47.3