Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 26 Jun 2020 02:26:59 -0400
From: Jeffrey Walton <noloader@...il.com>
To: musl@...ts.openwall.com
Cc: Khem Raj <raj.khem@...il.com>, Daniel Santos <daniel.santos@...ox.com>
Subject: Re: [PATCH] Fix signed compare warning

On Fri, Jun 26, 2020 at 2:20 AM Daniel Santos <daniel@...t.us> wrote:
>
> ...
> >>      if (at) {
> >> -            if (at->tv_nsec >= 1000000000UL) return EINVAL;
> >> +            if ((unsigned long)at->tv_nsec >= 1000000000UL) return EINVAL;
> >>              if (__clock_gettime(clk, &to)) return EINVAL;
> >>              to.tv_sec = at->tv_sec - to.tv_sec;
> >>              if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
> >>
> > may be use < 0 || >= 1000000000L and avoid the cast.
> > there is a similar issue in src/thread/pthread_cond_timedwait.c as well
> Thank you for that.  I'll resubmit changing both instances.
>
> In this case, the POSIX spec requires nt_nsec to be a long (
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
> ).  Either way, a good optimizer should convert this into an unsigned

I believe the C language says the signed value gets promoted to an
unsigned value. I don't believe the optimizer has anything to do with
it.

That's why -1 is greater than 1 in C:

    int x = -1;
    unsigned int y = 1;
    if (x > y)
        printf("WTF???\n");

Jeff

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.