git: 28093296d9e4 - stable/15 - libthr: Do not rely on UB in counter
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 01 Nov 2026 22:08:38 UTC
The branch stable/15 has been updated by aokblast:
URL: https://cgit.FreeBSD.org/src/commit/?id=28093296d9e4a5744abb9ee78a36ce68638be491
commit 28093296d9e4a5744abb9ee78a36ce68638be491
Author: ShengYi Hung <aokblast@FreeBSD.org>
AuthorDate: 2026-10-07 01:41:55 +0000
Commit: ShengYi Hung <aokblast@FreeBSD.org>
CommitDate: 2026-11-01 22:07:51 +0000
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
(cherry picked from commit 1d21e67e720a08992e81d626cff9d76524a81f22)
---
lib/libthr/thread/thr_mutex.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c
index 82da8ab1ccba..1787db825bf3 100644
--- a/lib/libthr/thread/thr_mutex.c
+++ b/lib/libthr/thread/thr_mutex.c
@@ -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