ams-libs: AMS_ASSERT no longer invokes expression

This commit is contained in:
Michael Scire 2021-09-29 21:32:40 -07:00
parent 5dc64bc1f7
commit 9b04ff0f54
38 changed files with 82 additions and 23 deletions

View file

@ -29,6 +29,7 @@ namespace ams::ddsf {
for (const auto &holder : this->entry_list) {
AMS_ASSERT(holder.IsConstructed());
AMS_ASSERT(holder.Get().GetDeviceCode() != device_code);
AMS_UNUSED(holder);
}
/* Allocate memory for a new device code entry holder. */

View file

@ -21,6 +21,7 @@ namespace ams::err::impl {
void MakeErrorCodeString(char *dst, size_t dst_size, ErrorCode error_code) {
const auto len = util::TSNPrintf(dst, dst_size, "%04d-%04d", error_code.category, error_code.number);
AMS_ASSERT(static_cast<size_t>(len) < dst_size);
AMS_UNUSED(len);
}
}

View file

@ -82,6 +82,7 @@ namespace ams::fs::impl {
const char *IdString::ToValueString(int id) {
const int len = util::SNPrintf(this->buffer, sizeof(this->buffer), "%d", id);
AMS_ASSERT(static_cast<size_t>(len) < sizeof(this->buffer));
AMS_UNUSED(len);
return this->buffer;
}

View file

@ -33,8 +33,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s:", bis_mount_name);
const auto size = util::SNPrintf(dst, dst_size, "%s:", bis_mount_name);
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -32,8 +32,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s:", GetContentStorageMountName(id));
const auto size = util::SNPrintf(dst, dst_size, "%s:", GetContentStorageMountName(id));
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -42,8 +42,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(this->partition), this->handle);
const auto size = util::SNPrintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(this->partition), this->handle);
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -426,8 +426,9 @@ namespace ams::fs {
{
bool normalized = false;
const auto is_norm_result = IsNormalized(std::addressof(normalized), out, unc_preserved, has_mount_name);
AMS_ASSERT(R_SUCCEEDED(is_norm_result));
R_ASSERT(is_norm_result);
AMS_ASSERT(normalized);
AMS_UNUSED(is_norm_result, normalized);
}
return ResultSuccess();

View file

@ -29,8 +29,11 @@ namespace ams::fs {
u32 *dst_invalid = this->invalid_chars;
for (const char *cur = ":*?<>|"; *cur != '\x00'; ++cur) {
AMS_ASSERT(dst_invalid < std::end(this->invalid_chars));
const auto result = util::ConvertCharacterUtf8ToUtf32(dst_invalid, cur);
AMS_ASSERT(result == util::CharacterEncodingResult_Success);
AMS_UNUSED(result);
++dst_invalid;
}
AMS_ASSERT(dst_invalid == std::end(this->invalid_chars));
@ -39,8 +42,11 @@ namespace ams::fs {
u32 *dst_sep = this->separators;
for (const char *cur = "/\\"; *cur != '\x00'; ++cur) {
AMS_ASSERT(dst_sep < std::end(this->separators));
const auto result = util::ConvertCharacterUtf8ToUtf32(dst_sep, cur);
AMS_ASSERT(result == util::CharacterEncodingResult_Success);
AMS_UNUSED(result);
++dst_sep;
}
AMS_ASSERT(dst_sep == std::end(this->separators));

View file

@ -35,8 +35,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s:", impl::SdCardFileSystemMountName);
const auto size = util::SNPrintf(dst, dst_size, "%s:", impl::SdCardFileSystemMountName);
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -215,9 +215,12 @@ namespace ams::fssystem {
AMS_ASSERT(entry != nullptr);
/* Ensure the entry is valid. */
const auto entry_buffer = this->external_entry_buffer != nullptr ? this->external_entry_buffer : this->internal_entry_buffer.get();
AMS_ASSERT(static_cast<void *>(entry_buffer) <= static_cast<void *>(entry));
AMS_ASSERT(static_cast<void *>(entry) < static_cast<void *>(entry_buffer + this->entry_buffer_size));
{
const auto entry_buffer = this->external_entry_buffer != nullptr ? this->external_entry_buffer : this->internal_entry_buffer.get();
AMS_ASSERT(static_cast<void *>(entry_buffer) <= static_cast<void *>(entry));
AMS_ASSERT(static_cast<void *>(entry) < static_cast<void *>(entry_buffer + this->entry_buffer_size));
AMS_UNUSED(entry_buffer);
}
/* Copy the entries back by one. */
std::memmove(entry, entry + 1, sizeof(Entry) * (this->entry_count - ((entry + 1) - this->entries)));

View file

@ -786,6 +786,7 @@ namespace ams::fssystem::save {
/* Get the entry to invalidate. */
const CacheEntry *entry_to_invalidate = std::addressof(this->entries[this->invalidate_index]);
AMS_UNUSED(entry_to_invalidate);
/* Ensure that the entry can be invalidated. */
AMS_ASSERT(entry_to_invalidate->is_valid);

View file

@ -192,6 +192,7 @@ namespace ams::fssystem::save {
const auto cache_buffer = reinterpret_cast<u8 *>(this->memory_range.first) + read_offset;
AMS_ASSERT(read_offset >= 0);
AMS_ASSERT(static_cast<size_t>(read_offset) <= readable_offset_max);
AMS_UNUSED(readable_offset_max);
std::memcpy(buffer, cache_buffer, size);
}
@ -209,6 +210,7 @@ namespace ams::fssystem::save {
const auto cache_buffer = reinterpret_cast<u8 *>(this->memory_range.first) + write_offset;
AMS_ASSERT(write_offset >= 0);
AMS_ASSERT(static_cast<size_t>(write_offset) <= writable_offset_max);
AMS_UNUSED(writable_offset_max);
std::memcpy(cache_buffer, buffer, size);
this->is_dirty = true;

View file

@ -44,9 +44,10 @@ namespace ams::fssystem::save {
{
s64 hash_size = 0;
s64 data_size = 0;
AMS_ASSERT(R_SUCCEEDED(hash_storage.GetSize(std::addressof(hash_size))));
AMS_ASSERT(R_SUCCEEDED(data_storage.GetSize(std::addressof(hash_size))));
R_ASSERT(hash_storage.GetSize(std::addressof(hash_size)));
R_ASSERT(data_storage.GetSize(std::addressof(hash_size)));
AMS_ASSERT(((hash_size / HashSize) * this->verification_block_size) >= data_size);
AMS_UNUSED(hash_size, data_size);
}
/* Set salt. */

View file

@ -141,6 +141,7 @@ namespace ams::gpio::driver::impl {
auto &pad = this->GetDevice().SafeCastTo<Pad>();
auto &driver = pad.GetDriver().SafeCastTo<IGpioDriver>();
AMS_ASSERT(driver.GetInterruptControlMutex(pad).IsLockedByCurrentThread());
AMS_UNUSED(pad, driver);
if (auto *event = this->event_holder.GetSystemEvent(); event != nullptr) {
os::SignalSystemEvent(event);

View file

@ -21,7 +21,7 @@ namespace ams::htcfs {
namespace {
constinit util::TypedStorage<Client> g_client_storage;
constinit bool g_initialized;
[[maybe_unused]] constinit bool g_initialized;
}

View file

@ -49,6 +49,7 @@ namespace ams::htcs::impl::rpc {
AMS_ASSERT(0 <= write_handle_count && write_handle_count < SocketCountMax);
AMS_ASSERT(0 <= exception_handle_count && exception_handle_count < SocketCountMax);
AMS_ASSERT(handle_count * static_cast<s64>(sizeof(s32)) == body_size);
AMS_UNUSED(handle_count);
/* Set our results. */
m_err = err;

View file

@ -63,8 +63,11 @@ namespace ams::mem::impl::heap {
bool CachedHeap::CheckCache() {
bool cache = false;
auto err = this->Query(AllocQuery_CheckCache, std::addressof(cache));
AMS_ASSERT(err != 0);
const auto err = this->Query(AllocQuery_CheckCache, std::addressof(cache));
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
return cache;
}

View file

@ -1151,8 +1151,9 @@ namespace ams::mem::impl::heap {
}
if (start_alignup < end_aligndown) {
auto err = this->FreePhysical(reinterpret_cast<void *>(start_alignup), end_aligndown - start_alignup);
const auto err = this->FreePhysical(reinterpret_cast<void *>(start_alignup), end_aligndown - start_alignup);
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
}
} else {
this->MergeIntoFreeList(span);

View file

@ -167,8 +167,9 @@ namespace ams::mem {
}
}
auto err = GetCentral(this->central_heap_storage)->Free(ptr);
const auto err = GetCentral(this->central_heap_storage)->Free(ptr);
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
}
void *StandardAllocator::Reallocate(void *ptr, size_t new_size) {
@ -248,8 +249,9 @@ namespace ams::mem {
void StandardAllocator::CleanUpManagementArea() const {
AMS_ASSERT(this->initialized);
auto err = GetCentral(this->central_heap_storage)->Query(impl::AllocQuery_UnifyFreeList);
const auto err = GetCentral(this->central_heap_storage)->Query(impl::AllocQuery_UnifyFreeList);
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
}
size_t StandardAllocator::GetSizeOf(const void *ptr) const {

View file

@ -23,7 +23,8 @@ namespace ams::os::impl {
svc::MemoryInfo memory_info;
svc::PageInfo page_info;
const auto result = svc::QueryMemory(std::addressof(memory_info), std::addressof(page_info), address);
AMS_ASSERT(R_SUCCEEDED(result));
R_ASSERT(result);
AMS_UNUSED(result);
return memory_info.state == svc::MemoryState_Free && address + size <= memory_info.addr + memory_info.size;
}

View file

@ -109,6 +109,7 @@ namespace ams::os::impl {
const auto count = mq->count;
const auto offset = mq->offset;
AMS_ASSERT(count > 0);
AMS_UNUSED(count);
return mq->buffer[offset];
}

View file

@ -38,8 +38,9 @@ namespace ams::os::impl {
const s64 frac = tick_val % tick_freq;
const TimeSpan ts = TimeSpan::FromSeconds(seconds) + TimeSpan::FromNanoSeconds(frac * NanoSecondsPerSecond / tick_freq);
constexpr TimeSpan ZeroTS = TimeSpan::FromNanoSeconds(0);
constexpr TimeSpan ZeroTS = TimeSpan::FromNanoSeconds(0);
AMS_ASSERT(!((tick_val > 0 && ts < ZeroTS) || (tick_val < 0 && ts > ZeroTS)));
AMS_UNUSED(ZeroTS);
return ts;
}

View file

@ -49,8 +49,11 @@ namespace ams::os::impl {
WaitableHolderBase *WaitAnyImpl(bool infinite, TimeSpan timeout) {
WaitableHolderBase *holder = nullptr;
const Result wait_result = this->WaitAnyImpl(std::addressof(holder), infinite, timeout, false, svc::InvalidHandle);
AMS_ASSERT(R_SUCCEEDED(wait_result));
R_ASSERT(wait_result);
AMS_UNUSED(wait_result);
return holder;
}
public:

View file

@ -123,8 +123,9 @@ namespace ams::os {
const s32 prev_prio = thread->base_priority;
bool success = impl::GetThreadManager().ChangePriority(thread, priority);
const bool success = impl::GetThreadManager().ChangePriority(thread, priority);
AMS_ASSERT(success);
AMS_UNUSED(success);
thread->base_priority = priority;

View file

@ -45,6 +45,7 @@ namespace ams::os {
AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized);
AMS_ASSERT(impl.IsEmpty());
AMS_UNUSED(impl);
/* Mark not initialized. */
manager->state = WaitableManagerType::State_NotInitialized;