libthr: Do not rely on UB in counter

counter + 1 > 0 is a undefined behavior and nobody guarantee that it
will be honestly perform by the compiler that counter + 1 will always be
INT_MIN. We switch to INT_MAX check instead to provide a deterministic
result.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60426
This commit is contained in:
ShengYi Hung committed 2026-10-08 03:59:10 +11:00
1 parent 26203cca52
commit 1d21e67e72
1 file changed
+2 -2
+2 -2
View File
@@ -865,7 +865,7 @@ mutex_self_trylock(struct pthread_mutex *m)
case PTHREAD_MUTEX_RECURSIVE:
/* Increment the lock count: */
if (m->m_count + 1 > 0) {
if (m->m_count < INT_MAX) {
m->m_count++;
ret = 0;
} else
@@ -934,7 +934,7 @@ mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime)
case PTHREAD_MUTEX_RECURSIVE:
/* Increment the lock count: */
if (m->m_count + 1 > 0) {
if (m->m_count < INT_MAX) {
m->m_count++;
ret = 0;
} else