Subject: Re: libssh2 master 81912f6 cast away a warning.

Re: libssh2 master 81912f6 cast away a warning.

From: Simon Josefsson <simon_at_josefsson.org>
Date: Mon, 07 Jun 2010 14:32:22 +0200

Tor Arntsen <tor_at_spacetec.no> writes:

> On Mon, Jun 7, 2010 at 06:35, Peter Stuge <peter_at_stuge.se> wrote:
>> Guenter wrote:
>>> we can cast to int until year 2038
>>
>> I don't mind that cast, but it could be nice to add /* XXX: Y2k38 */
>> nearby.
>
> Hm, one of those unfortunate API problems.. it's a parameter to a
> public function. The correct fix is of course to change
> seconds_to_next to time_t *.

No, time_t should only be used for absolute time values, not time
intervals. The "standard" type in C for time intervals is 'double'
(return value of 'difftime') but since we only use the variable for
whole seconds, an 'unsigned' should be fine.

> No can do here though. In those cases I personally prefer to fix the
> internal types, and copy from/to the API parameter explictly - it
> makes things pretty obvious then. But that's just me.

Yup, me too.

Isn't a better approach something like this:

        *seconds_to_next = (int) difftime (session->keepalive_last_sent, now)
            + session->keepalive_interval;

Or possibly just

        *seconds_to_next = (int) (session->keepalive_last_sent - now)
            + session->keepalive_interval;

?

/Simon
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-06-07