mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-11-07 04:36:52 -10:00
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:
1 parent
26203cca52
commit
1d21e67e72
1 file changed
+2
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user