Re: [PATCH v3] ctime.3: EXAMPLES: Add example program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 22, 2024 at 09:57:39PM GMT, Paul Eggert wrote:
> On 2024-08-22 16:49, Alejandro Colomar wrote:
> >           t = mktime(tp);
> >           if (t == -1 && errno == EOVERFLOW)
> >               return -1;
> 
> This isn't right, for the same reason similar code wasn't right earlier. A
> successful call to mktime can return -1 and set errno to whatever value it
> likes.

Is mktime(3) allowed to return -1 and set EOVERFLOW on a successful
call?

RETURN VALUE
     The mktime() function shall return the specified  time  since  the
     Epoch  encoded  as  a value of type time_t.  If the time since the
     Epoch cannot be represented, the function shall return  the  value
     (time_t)-1 and set errno to indicate the error.

ERRORS
     The mktime() function shall fail if:

     EOVERFLOW
            The result cannot be represented.

     The following sections are informative.


Then I think the API is completely broken.  How should we check for
errors after a mktime(3) call?

If this is so, let me file a glibc bug requesting a fix of the API,
adding a promise that on success, errno will remain unset.

> This is just the first problem I found with the code (and I found it quickly
> because I remembered the earlier problem). I would expect there to be
> others.
> 
> How about if we omit the sample code and make the minimal changes I
> suggested earlier?

Because I'm being very careful writing that code, and still I'm having
trouble doing that, I think we must provide some example of a correct
call, to prevent many other programmers from doing it wrong.

Cheers,
Alex

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux