URL:
  <https://savannah.gnu.org/bugs/?68264>

                 Summary: find -used misbehaves on OpenBSD 7.8 when atime ==
ctime; tests/find/used.sh fails
                   Group: findutils
               Submitter: chitaotao
               Submitted: Wed 22 Apr 2026 06:27:10 AM UTC
                Category: find
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Test suite failure
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name:
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Unlocked
                 Release: None
           Fixed Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Wed 22 Apr 2026 06:27:10 AM UTC By: Xuntao Chi <chitaotao>
Hello,

I ran make check in a build of current findutils on OpenBSD and
tests/find/used.sh fails consistently.


Environment:
* uname -a: OpenBSD CHI-OpenBSD.localdomain 7.8 GENERIC.MP#6 amd64
* findutils tree built from commit 34929da
* built find --version reports find (GNU findutils) UNKNOWN


Observed test failure:
tests/find/used.log shows that a freshly created file t00 with equal atime and
ctime is classified into the wrong -used buckets

Expected according to the test:
* find ... -used -5 should print t00
* find ... -used +5 should print nothing for t00

Actual on OpenBSD:
* t00 is missing from the negative cases (-45, -35, -25, -15, -5)
* t00 incorrectly appears in the positive cases (+5, +15, +25, +35, +45)
So a file with atime == ctime is handled as if it had a large "used" age.


Why I think this happens:
-used appears to construct synthetic reference times relative to an origin of
{0,0}. For some arguments this produces negative time_t values. Later,
pred_used / pred_timewindow compare timestamps via difftime().

On OpenBSD, the libc implementation of difftime() appears to give the wrong
answer for representable negative time_t values. A minimal C reproducer on the
same machine


#include <stdio.h>
#include <time.h>
#include <inttypes.h>

int main(void) {
    time_t a = 0;
    time_t b = (time_t)-86400;
    printf("sizeof(time_t)=%zu\n", sizeof(time_t));
    printf("a=%jd b=%jd\n", (intmax_t)a, (intmax_t)b);
    printf("difftime(a,b)=%.0f\n", difftime(a,b));
    return 0;
}


gives:


sizeof(time_t)=8
a=0 b=-86400
difftime(a,b)=-18446744073709465600


where I would expect 86400.

So the immediate trigger appears to be an OpenBSD libc bug. However, from the
findutils side this also looks like a portability problem in -used: it assumes
that negative synthetic time_t values are safe to hand to difftime(). And that
assumption seems to break on OpenBSD and causes the shipped test
tests/find/used.sh to fail.

Thanks.






    _______________________________________________________
File Attachments:

Name: test-suite.log                 Size: 3.3KiB
    <https://file.savannah.gnu.org/file/test-suite.log?file_id=58493>



    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-f290f6b25beb8cb99bbe243a6cd2c5fef79ffcde.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68264>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to