summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-06-22 19:39:04 -0700
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-07-09 18:20:42 +0000
commit2726c17ebb854a1f134b82b63b03f307b5e0b3d8 (patch)
tree079d51a79c8ebb13f65f682773adfd8e97951e27
parent68cb1701d36a86d13979c4d9a33048e569f2ec0b (diff)
downloadsdbusplus-2726c17ebb854a1f134b82b63b03f307b5e0b3d8.tar.gz
sdbusplus-2726c17ebb854a1f134b82b63b03f307b5e0b3d8.zip
SdBusError: Fix initialization checks
sd_bus_error_set_errno() is semantically useful in C for returning the errno and constructing the error in a single call. However, since successful population of the error can not be distinguished due to the collapsed return value, we need another way to ensure the error was built correctly. Don't check for the return of sd_bus_error_set_errno() and instead use sd_bus_error_is_set(). Tested: Builds still work and tests still pass. Change-Id: Ib7546d7bb19eb2ebbaf6e2cab79a8ecd8960f280 Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r--sdbusplus/exception.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/sdbusplus/exception.cpp b/sdbusplus/exception.cpp
index e8f1104..2bb3576 100644
--- a/sdbusplus/exception.cpp
+++ b/sdbusplus/exception.cpp
@@ -1,5 +1,8 @@
#include <sdbusplus/exception.hpp>
#include <sdbusplus/sdbus.hpp>
+#include <stdexcept>
+#include <system_error>
+#include <utility>
extern sdbusplus::SdBusImpl sdbus_impl;
@@ -12,10 +15,14 @@ SdBusError::SdBusError(int error, const char* prefix, SdBusInterface* intf) :
std::system_error(error, std::generic_category()), error(SD_BUS_ERROR_NULL),
intf(intf)
{
- if (error == ENOMEM ||
- intf->sd_bus_error_set_errno(&this->error, error) == -ENOMEM)
+ // We can't check the output of intf->sd_bus_error_set_errno() because
+ // it returns the input errorcode. We don't want to try and guess
+ // possible error statuses. Instead, check to see if the error was
+ // constructed to determine success.
+ intf->sd_bus_error_set_errno(&this->error, error);
+ if (!intf->sd_bus_error_is_set(&this->error))
{
- throw std::bad_alloc();
+ throw std::runtime_error("Failed to create SdBusError");
}
populateMessage(prefix);
OpenPOWER on IntegriCloud