[Base] Fix `Semaphore::Create` invalid parameters

This commit is contained in:
Joel Linn 2022-02-21 23:02:38 +01:00 committed by Rick Gibbed
parent bb42829308
commit e75e0eb39c
1 changed files with 4 additions and 0 deletions

View File

@ -975,6 +975,10 @@ class PosixSemaphore : public PosixConditionHandle<Semaphore> {
std::unique_ptr<Semaphore> Semaphore::Create(int initial_count,
int maximum_count) {
if (initial_count < 0 || initial_count > maximum_count ||
maximum_count <= 0) {
return nullptr;
}
return std::make_unique<PosixSemaphore>(initial_count, maximum_count);
}