Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
kpschoedel committed Jul 12, 2021
1 parent 25d8991 commit 2086060
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#pragma once

#include <core/CHIPConfig.h>
#include <support/TypeTraits.h>

#include <inttypes.h>
#include <stdint.h>
Expand Down Expand Up @@ -89,10 +90,7 @@ class ChipError
static constexpr bool CanEncapsulate(BaseType value) { return FitsInField(kValueLength, value); }

/// Construct a `CHIP_ERROR` encapsulating @a value inside the @a range.
static BaseType Encapsulate(Range range, BaseType value)
{
return MakeInteger(range, (value & MakeMask(kValueStart, kValueLength)));
}
static BaseType Encapsulate(Range range, BaseType value) { return MakeInteger(range, (value & MakeMask(0, kValueLength))); }

/// Test whether @a error is an SDK error belonging to @a part.
static constexpr bool IsPart(SdkPart part, BaseType error)
Expand Down Expand Up @@ -133,13 +131,11 @@ class ChipError

static constexpr BaseType MakeInteger(Range range, BaseType value)
{
return MakeField(kRangeStart, static_cast<std::underlying_type<Range>::type>(range)) | MakeField(kValueStart, value);
return MakeField(kRangeStart, to_underlying(range)) | MakeField(kValueStart, value);
}
static constexpr BaseType MakeInteger(SdkPart part, BaseType code)
{
return MakeInteger(Range::kSDK,
MakeField(kSdkPartStart, static_cast<std::underlying_type<SdkPart>::type>(part)) |
MakeField(kSdkCodeStart, code));
return MakeInteger(Range::kSDK, MakeField(kSdkPartStart, to_underlying(part)) | MakeField(kSdkCodeStart, code));
}

public:
Expand All @@ -154,7 +150,7 @@ class ChipError
template <SdkPart part, BaseType code>
struct MakeSdkErrorConstant
{
static_assert(FitsInField(kSdkPartLength, static_cast<std::underlying_type<SdkPart>::type>(part)), "part is too large");
static_assert(FitsInField(kSdkPartLength, to_underlying(part)), "part is too large");
static_assert(FitsInField(kSdkCodeLength, code), "code is too large");
static_assert(MakeInteger(part, code) != 0, "value is zero");
static constexpr BaseType value = MakeInteger(part, code);
Expand Down
2 changes: 1 addition & 1 deletion src/system/SystemError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ DLL_EXPORT const char * DescribeErrorLwIP(CHIP_ERROR aError)
return nullptr;
}

const err_t lError = static_cast<err_t>(-ChipError::GetValue(aError));
const err_t lError = static_cast<err_t>(-static_cast<err_t>(ChipError::GetValue(aError)));

// If we are not compiling with LWIP_DEBUG asserted, the unmapped
// local value may go unused.
Expand Down

0 comments on commit 2086060

Please sign in to comment.