From 4b65c3943c3fffcee3ec2b82012832a23e1be6c2 Mon Sep 17 00:00:00 2001 From: eladash Date: Wed, 26 Dec 2018 16:28:26 +0200 Subject: [PATCH] Fix sys_semaphore_post count check --- rpcs3/Emu/Cell/lv2/sys_semaphore.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp index a59d9680d5..18c07ca7b2 100644 --- a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp @@ -201,16 +201,11 @@ error_code sys_semaphore_post(ppu_thread& ppu, u32 sem_id, s32 count) { sys_semaphore.trace("sys_semaphore_post(sem_id=0x%x, count=%d)", sem_id, count); - if (count < 0) - { - return CELL_EINVAL; - } - const auto sem = idm::get(sem_id, [&](lv2_sema& sema) { const s32 val = sema.val; - if (val >= 0 && count <= sema.max - val) + if (val >= 0 && count > 0 && count <= sema.max - val) { if (sema.val.compare_and_swap_test(val, val + count)) { @@ -226,6 +221,11 @@ error_code sys_semaphore_post(ppu_thread& ppu, u32 sem_id, s32 count) return CELL_ESRCH; } + if (count <= 0) + { + return CELL_EINVAL; + } + if (sem.ret) { return CELL_OK;