mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Daniel Santos <daniel@gsat.us>
To: Khem Raj <raj.khem@gmail.com>,
	musl@lists.openwall.com, Daniel Santos <daniel.santos@pobox.com>
Subject: Re: [musl] [PATCH] Fix signed compare warning
Date: Thu, 25 Jun 2020 23:31:32 -0500	[thread overview]
Message-ID: <bd78cf74-6ed4-3fb0-b7e3-fe084e388ff2@gsat.us> (raw)
In-Reply-To: <39be4d66-963c-4e06-e685-37a8396d10c3@gmail.com>

On 6/25/20 10:58 AM, Khem Raj wrote:
>
> On 6/24/20 4:20 PM, Daniel Santos wrote:
>> Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
>> ---
>>  src/thread/__timedwait.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/thread/__timedwait.c b/src/thread/__timedwait.c
>> index 666093be..9829b93e 100644
>> --- a/src/thread/__timedwait.c
>> +++ b/src/thread/__timedwait.c
>> @@ -38,7 +38,7 @@ int __timedwait_cp(volatile int *addr, int val,
>>  	if (priv) priv = FUTEX_PRIVATE;
>>  
>>  	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
compare.  My early years in 6502 assembly sort-of shapes my thinking, as
I try to write higher level code as similarly to the assembly I presume
the compiler will emit.  But if the project has a strong preference to
avoid casts, I can change it.

Thanks!
Daniel

  parent reply	other threads:[~2020-06-26  6:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24 23:20 Daniel Santos
2020-06-25 15:58 ` Khem Raj
2020-06-25 17:33   ` Rich Felker
2020-06-26  4:31   ` Daniel Santos [this message]
2020-06-26  6:26     ` Jeffrey Walton
2020-07-04 21:13       ` Daniel Santos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bd78cf74-6ed4-3fb0-b7e3-fe084e388ff2@gsat.us \
    --to=daniel@gsat.us \
    --cc=daniel.santos@pobox.com \
    --cc=musl@lists.openwall.com \
    --cc=raj.khem@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).