Skip to content

Commit

Permalink
Add std::unreachable() after function calls that always throw.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilx committed Nov 24, 2024
1 parent 3a568c9 commit e791a6a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/appender.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <log4cplus/thread/syncprims-pub-impl.h>
#include <memory>
#include <stdexcept>
#include <utility>


namespace log4cplus
Expand Down Expand Up @@ -120,6 +121,7 @@ Appender::Appender(const log4cplus::helpers::Properties & properties)
LOG4CPLUS_TEXT("Cannot find LayoutFactory: \"")
+ factoryName
+ LOG4CPLUS_TEXT("\""), true);
std::unreachable();
}

helpers::Properties layoutProperties =
Expand All @@ -130,6 +132,7 @@ Appender::Appender(const log4cplus::helpers::Properties & properties)
helpers::getLogLog().error(
LOG4CPLUS_TEXT("Failed to create Layout: ")
+ factoryName, true);
std::unreachable();
}
else {
layout = std::move(newLayout);
Expand All @@ -139,6 +142,7 @@ Appender::Appender(const log4cplus::helpers::Properties & properties)
helpers::getLogLog().error(
LOG4CPLUS_TEXT("Error while creating Layout: ")
+ LOG4CPLUS_C_STR_TO_TSTRING(e.what()), true);
std::unreachable();
}

}
Expand Down Expand Up @@ -167,6 +171,7 @@ Appender::Appender(const log4cplus::helpers::Properties & properties)
helpers::getLogLog().error(
LOG4CPLUS_TEXT("Appender::ctor()- Cannot find FilterFactory: ")
+ factoryName, true);
std::unreachable();
}
spi::FilterPtr tmpFilter = factory->createObject (
filterProps.getPropertySubset(filterName + LOG4CPLUS_TEXT(".")));
Expand All @@ -175,6 +180,7 @@ Appender::Appender(const log4cplus::helpers::Properties & properties)
helpers::getLogLog().error(
LOG4CPLUS_TEXT("Appender::ctor()- Failed to create filter: ")
+ filterName, true);
std::unreachable();
}
addFilter (std::move (tmpFilter));
}
Expand Down
3 changes: 3 additions & 0 deletions src/asyncappender.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <log4cplus/config.hxx>
#ifndef LOG4CPLUS_SINGLE_THREADED

#include <utility>

#include <log4cplus/asyncappender.h>
#include <log4cplus/spi/factory.h>
#include <log4cplus/helpers/loglog.h>
Expand Down Expand Up @@ -119,6 +121,7 @@ AsyncAppender::AsyncAppender (helpers::Properties const & props)
LOG4CPLUS_TEXT ("AsyncAppender::AsyncAppender()")
LOG4CPLUS_TEXT (" - Cannot find AppenderFactory: ")
+ appender_name, true);
std::unreachable ();
}

helpers::Properties appender_props = props.getPropertySubset (
Expand Down
5 changes: 4 additions & 1 deletion src/env.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include <functional>
#include <stdexcept>
#include <memory>

#include <utility>

namespace log4cplus::internal {

Expand Down Expand Up @@ -340,10 +340,13 @@ get_current_dir ()
if (eno == ERANGE)
buf_size *= 2;
else
{
helpers::getLogLog ().error (
LOG4CPLUS_TEXT ("getcwd: ")
+ helpers::convertIntegerToString (eno),
true);
std::unreachable();
}
}
}
while (! ret);
Expand Down
13 changes: 13 additions & 0 deletions src/lockfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <cerrno>
#include <limits>
#include <cstring>
#include <utility>

#include <log4cplus/helpers/lockfile.h>
#include <log4cplus/helpers/stringhelper.h>
Expand Down Expand Up @@ -225,16 +226,22 @@ LockFile::open (int open_flags) const
# else
# error "Neither _tsopen_s() nor _tsopen() is available."
# endif
{
getLogLog ().error (tstring (LOG4CPLUS_TEXT("could not open or create file "))
+ lock_file_name, true);
std::unreachable ();
}

#elif defined (LOG4CPLUS_USE_POSIX_LOCKING)
data->fd = ::open (LOG4CPLUS_TSTRING_TO_STRING (lock_file_name).c_str (),
open_flags, OPEN_MODE);
if (data->fd == -1)
{
getLogLog ().error (
tstring (LOG4CPLUS_TEXT ("could not open or create file "))
+ lock_file_name, true);
std::unreachable ();
}

#if ! defined (O_CLOEXEC)
if (! trySetCloseOnExec (data->fd))
Expand Down Expand Up @@ -301,8 +308,11 @@ LockFile::lock () const
fl.l_len = 0;
ret = fcntl (data->fd, F_SETLKW, &fl);
if (ret == -1 && errno != EINTR)
{
getLogLog ().error (tstring (LOG4CPLUS_TEXT("fcntl(F_SETLKW) failed: "))
+ convertIntegerToString (errno), true);
std::unreachable ();
}
}
while (ret == -1);

Expand Down Expand Up @@ -354,8 +364,11 @@ void LockFile::unlock () const
fl.l_len = 0;
ret = fcntl (data->fd, F_SETLKW, &fl);
if (ret != 0)
{
getLogLog ().error (tstring (LOG4CPLUS_TEXT("fcntl(F_SETLKW) failed: "))
+ convertIntegerToString (errno), true);
std::unreachable ();
}

#elif defined (LOG4CPLUS_USE_LOCKF)
ret = lockf (data->fd, F_ULOCK, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/timehelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <algorithm>
#include <vector>
#include <iomanip>
#include <utility>
#include <cassert>
#include <cerrno>
#if defined (UNICODE)
Expand Down Expand Up @@ -304,6 +305,7 @@ getFormattedTime(const log4cplus::tstring& fmt_orig,
LogLog::getLogLog ()->error (
LOG4CPLUS_TEXT("Error in strftime(): ")
+ convertIntegerToString (eno), true);
std::unreachable();
}
}
}
Expand Down

0 comments on commit e791a6a

Please sign in to comment.