mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-29 14:32:58 +02:00
strat: minor result/overflow check fixes
This commit is contained in:
parent
ce44fe4ea9
commit
f037d60c75
@ -36,12 +36,10 @@ namespace ams::fs::fsa {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check that the read is valid. */
|
/* Check that the read is valid. */
|
||||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||||
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
|
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
|
||||||
R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange());
|
R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange());
|
||||||
|
R_UNLESS(util::CanAddWithoutOverflow<s64>(offset, size), fs::ResultOutOfRange());
|
||||||
const s64 signed_size = static_cast<s64>(size);
|
|
||||||
R_UNLESS((std::numeric_limits<s64>::max() - offset) >= signed_size, fs::ResultOutOfRange());
|
|
||||||
|
|
||||||
/* Do the read. */
|
/* Do the read. */
|
||||||
R_RETURN(this->DoRead(out, offset, buffer, size, option));
|
R_RETURN(this->DoRead(out, offset, buffer, size, option));
|
||||||
@ -68,12 +66,10 @@ namespace ams::fs::fsa {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check the write is valid. */
|
/* Check the write is valid. */
|
||||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||||
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
|
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
|
||||||
R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange());
|
R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange());
|
||||||
|
R_UNLESS(util::CanAddWithoutOverflow<s64>(offset, size), fs::ResultOutOfRange());
|
||||||
const s64 signed_size = static_cast<s64>(size);
|
|
||||||
R_UNLESS((std::numeric_limits<s64>::max() - offset) >= signed_size, fs::ResultOutOfRange());
|
|
||||||
|
|
||||||
R_RETURN(this->DoWrite(offset, buffer, size, option));
|
R_RETURN(this->DoWrite(offset, buffer, size, option));
|
||||||
}
|
}
|
||||||
|
@ -157,11 +157,7 @@ namespace ams::time::impl::util {
|
|||||||
R_UNLESS(out != nullptr, time::ResultInvalidPointer());
|
R_UNLESS(out != nullptr, time::ResultInvalidPointer());
|
||||||
R_UNLESS(from.source_id == to.source_id, time::ResultNotComparable());
|
R_UNLESS(from.source_id == to.source_id, time::ResultNotComparable());
|
||||||
|
|
||||||
const bool no_overflow = (from.value >= 0 ? (to.value >= std::numeric_limits<s64>::min() + from.value)
|
R_UNLESS(ams::util::TrySubtractWithoutOverflow(out, to.value, from.value), time::ResultOverflowed());
|
||||||
: (to.value <= std::numeric_limits<s64>::max() + from.value));
|
|
||||||
R_UNLESS(no_overflow, time::ResultOverflowed());
|
|
||||||
|
|
||||||
*out = to.value - from.value;
|
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user