Skip to contentSkip to conversation

util/stats64: Fix min/max comparisons

PATCH Applied Max Reitz 2 participants 2 messages Nov 14, 2017

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 util/stats64: Fix min/max comparisons

stat64_min_slow() and stat64_max_slow() compare the wrong way. This makes iotest 136 fail with clang and -m32.

---
 util/stats64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
util/stats64.c +2 -2
index 9968fcceac..389c365a9e 100644
@@ -91,7 +91,7 @@ bool stat64_min_slow(Stat64 *s, uint64_t value)
     low = atomic_read(&s->low);
 
     orig = ((uint64_t)high << 32) | low;
-    if (orig < value) {
+    if (value < orig) {
         /* We have to set low before high, just like stat64_min reads
          * high before low.  The value may become higher temporarily, but
          * stat64_get does not notice (it takes the lock) and the only ill
@@ -120,7 +120,7 @@ bool stat64_max_slow(Stat64 *s, uint64_t value)
     low = atomic_read(&s->low);
 
     orig = ((uint64_t)high << 32) | low;
-    if (orig > value) {
+    if (value > orig) {
         /* We have to set low before high, just like stat64_max reads
          * high before low.  The value may become lower temporarily, but
          * stat64_get does not notice (it takes the lock) and the only ill
Signature · 1 line
2.13.6
#1 lore raw

----- Max Reitz <[email protected]> ha scritto:

Quoted 2 lines

stat64_min_slow() and stat64_max_slow() compare the wrong way. This makes iotest 136 fail with clang and -m32.

Queued, thanks.

Paolo

Quoted 30 lines
---
 util/stats64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
util/stats64.c +2 -2
index 9968fcceac..389c365a9e 100644
@@ -91,7 +91,7 @@ bool stat64_min_slow(Stat64 *s, uint64_t value)
     low = atomic_read(&s->low);
 
     orig = ((uint64_t)high << 32) | low;
-    if (orig < value) {
+    if (value < orig) {
         /* We have to set low before high, just like stat64_min reads
          * high before low.  The value may become higher temporarily, but
          * stat64_get does not notice (it takes the lock) and the only ill
@@ -120,7 +120,7 @@ bool stat64_max_slow(Stat64 *s, uint64_t value)
     low = atomic_read(&s->low);
 
     orig = ((uint64_t)high << 32) | low;
-    if (orig > value) {
+    if (value > orig) {
         /* We have to set low before high, just like stat64_max reads
          * high before low.  The value may become lower temporarily, but
          * stat64_get does not notice (it takes the lock) and the only ill
Signature · 1 line
2.13.6