zsh-workers
 help / color / mirror / code / Atom feed
* Compiler warning after workers/39825
@ 2016-11-07 23:50 Bart Schaefer
  2016-11-08  7:08 ` Sebastian Gniazdowski
  2016-11-08  8:36 ` Sebastian Gniazdowski
  0 siblings, 2 replies; 8+ messages in thread
From: Bart Schaefer @ 2016-11-07 23:50 UTC (permalink / raw)
  To: zsh-workers

../../zsh-5.0/Src/utils.c: In function `mb_metastrlenend':
../../zsh-5.0/Src/utils.c:5344: warning: comparison is always true due to limited range of data type

commit 9c68ef08


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Compiler warning after workers/39825
  2016-11-07 23:50 Compiler warning after workers/39825 Bart Schaefer
@ 2016-11-08  7:08 ` Sebastian Gniazdowski
  2016-11-08  7:24   ` Sebastian Gniazdowski
  2016-11-08  8:36 ` Sebastian Gniazdowski
  1 sibling, 1 reply; 8+ messages in thread
From: Sebastian Gniazdowski @ 2016-11-08  7:08 UTC (permalink / raw)
  To: zsh-workers

On Mon, Nov 7, 2016, at 03:50 PM, Bart Schaefer wrote:
> ../../zsh-5.0/Src/utils.c: In function `mb_metastrlenend':
> ../../zsh-5.0/Src/utils.c:5344: warning: comparison is always true due to
> limited range of data type
> 
> commit 9c68ef08

Probably an enlightenment is scheduled on this, but first
rejecting-facts reaction is that you might have modified the line maybe?
Why would char be always in 0 .. 0x7f is a mystery.  Clang doesn't yield
the warning.

BTW. this can be optimized more: `!num_in_char` instead of `complete`,
and no `num_in_char = 0` assignment.

-- 
  Sebastian Gniazdowski
  psprint@fastmail.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Compiler warning after workers/39825
  2016-11-08  7:08 ` Sebastian Gniazdowski
@ 2016-11-08  7:24   ` Sebastian Gniazdowski
  2016-11-08 10:01     ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Gniazdowski @ 2016-11-08  7:24 UTC (permalink / raw)
  To: zsh-workers

On Mon, Nov 7, 2016, at 11:08 PM, Sebastian Gniazdowski wrote:
> On Mon, Nov 7, 2016, at 03:50 PM, Bart Schaefer wrote:
> > ../../zsh-5.0/Src/utils.c: In function `mb_metastrlenend':
> > ../../zsh-5.0/Src/utils.c:5344: warning: comparison is always true due to
> > limited range of data type
> > 
> > commit 9c68ef08
> 
> Probably an enlightenment is scheduled on this, but first

Ah, the (mild) enlightenment is: char can be signed / unsigned. Wonder
if this can have any actual implications as 7f is AFAIK still in
unsigned range. For sure there are some techniques of solving such
portability problems hm

-- 
  Sebastian Gniazdowski
  psprint@fastmail.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Compiler warning after workers/39825
  2016-11-07 23:50 Compiler warning after workers/39825 Bart Schaefer
  2016-11-08  7:08 ` Sebastian Gniazdowski
@ 2016-11-08  8:36 ` Sebastian Gniazdowski
  1 sibling, 0 replies; 8+ messages in thread
From: Sebastian Gniazdowski @ 2016-11-08  8:36 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

On Mon, Nov 7, 2016, at 03:50 PM, Bart Schaefer wrote:
> ../../zsh-5.0/Src/utils.c: In function `mb_metastrlenend':
> ../../zsh-5.0/Src/utils.c:5344: warning: comparison is always true due to
> limited range of data type
> 
> commit 9c68ef08

Attached is patch that should work for both signed and unsigned
integers. Does it emit any warning?

On current system warmup the test results are 2141 ms vs 2337 ms,
slightly less than 10%, but still ~200 ms difference.

-- 
  Sebastian Gniazdowski
  psprint@fastmail.com

[-- Attachment #2: ascii_fix.diff --]
[-- Type: text/plain, Size: 629 bytes --]

diff --git a/Src/utils.c b/Src/utils.c
index 733f570..32e7dc6 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5341,7 +5341,12 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
 	    inchar = *ptr;
 	ptr++;
 
-	if (complete && (inchar >= 0 && inchar <= 0x7f)) {
+        /*
+         * 0x7f is all ones except for top bit in binary,
+         * this will check if inchar is in range 0 .. 127
+         * inclusive, regardless of char signedness
+         */
+	if (complete && (inchar & 0x7f) == inchar) {
 	    /*
 	     * We rely on 7-bit US-ASCII as a subset, so skip
 	     * multibyte handling if we have such a character.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Compiler warning after workers/39825
  2016-11-08  7:24   ` Sebastian Gniazdowski
@ 2016-11-08 10:01     ` Peter Stephenson
  2016-11-08 10:07       ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2016-11-08 10:01 UTC (permalink / raw)
  To: zsh-workers

On Mon, 07 Nov 2016 23:24:23 -0800
Sebastian Gniazdowski <psprint@fastmail.com> wrote:
> Ah, the (mild) enlightenment is: char can be signed / unsigned. Wonder
> if this can have any actual implications as 7f is AFAIK still in
> unsigned range. For sure there are some techniques of solving such
> portability problems hm

Yes, that's it.  We have a macro to perform a safe cast to unsigned.
That's the right answer, since if the char is signed and is negative,
it's *not* in a range we want to deal with.  So the compiler was right...

Casting 0x74 is unnecessary, since the constant will conform with
unsigned char anyway, but I've made the point...

pws

diff --git a/Src/utils.c b/Src/utils.c
index 733f570..d73110a 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5341,7 +5341,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
 	    inchar = *ptr;
 	ptr++;
 
-	if (complete && (inchar >= 0 && inchar <= 0x7f)) {
+	if (complete && (inchar >= 0 && STOUC(inchar) <= STOUC(0x7f))) {
 	    /*
 	     * We rely on 7-bit US-ASCII as a subset, so skip
 	     * multibyte handling if we have such a character.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Compiler warning after workers/39825
  2016-11-08 10:01     ` Peter Stephenson
@ 2016-11-08 10:07       ` Peter Stephenson
  2016-11-08 15:38         ` Daniel Shahaf
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2016-11-08 10:07 UTC (permalink / raw)
  To: zsh-workers

On Tue, 8 Nov 2016 10:01:49 +0000
Peter Stephenson <p.stephenson@samsung.com> wrote:
> diff --git a/Src/utils.c b/Src/utils.c
> index 733f570..d73110a 100644
> --- a/Src/utils.c
> +++ b/Src/utils.c
> @@ -5341,7 +5341,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
>  	    inchar = *ptr;
>  	ptr++;
>  
> -	if (complete && (inchar >= 0 && inchar <= 0x7f)) {
> +	if (complete && (inchar >= 0 && STOUC(inchar) <= STOUC(0x7f))) {
                         ^^^^^^^^^^^^

This is now irrelevant, I'll remove that, too.

pws


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Compiler warning after workers/39825
  2016-11-08 10:07       ` Peter Stephenson
@ 2016-11-08 15:38         ` Daniel Shahaf
  2016-11-08 15:44           ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Shahaf @ 2016-11-08 15:38 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

Peter Stephenson wrote on Tue, Nov 08, 2016 at 10:07:35 +0000:
> On Tue, 8 Nov 2016 10:01:49 +0000
> Peter Stephenson <p.stephenson@samsung.com> wrote:
> > diff --git a/Src/utils.c b/Src/utils.c
> > index 733f570..d73110a 100644
> > --- a/Src/utils.c
> > +++ b/Src/utils.c
> > @@ -5341,7 +5341,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
> >  	    inchar = *ptr;
> >  	ptr++;
> >  
> > -	if (complete && (inchar >= 0 && inchar <= 0x7f)) {
> > +	if (complete && (inchar >= 0 && STOUC(inchar) <= STOUC(0x7f))) {
>                          ^^^^^^^^^^^^
> 
> This is now irrelevant, I'll remove that, too.

It's relevant on systems where the «char» type is signed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Compiler warning after workers/39825
  2016-11-08 15:38         ` Daniel Shahaf
@ 2016-11-08 15:44           ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2016-11-08 15:44 UTC (permalink / raw)
  To: zsh-workers

On Tue, 8 Nov 2016 15:38:30 +0000
Daniel Shahaf <d.s@daniel.shahaf.name> wrote:

> Peter Stephenson wrote on Tue, Nov 08, 2016 at 10:07:35 +0000:
> > On Tue, 8 Nov 2016 10:01:49 +0000
> > Peter Stephenson <p.stephenson@samsung.com> wrote:
> > > diff --git a/Src/utils.c b/Src/utils.c
> > > index 733f570..d73110a 100644
> > > --- a/Src/utils.c
> > > +++ b/Src/utils.c
> > > @@ -5341,7 +5341,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
> > >  	    inchar = *ptr;
> > >  	ptr++;
> > >  
> > > -	if (complete && (inchar >= 0 && inchar <= 0x7f)) {
> > > +	if (complete && (inchar >= 0 && STOUC(inchar) <= STOUC(0x7f))) {
> >                          ^^^^^^^^^^^^
> > 
> > This is now irrelevant, I'll remove that, too.
> 
> It's relevant on systems where the «char» type is signed.

No, read what the remaining modified test does.  It's not using a signed
value any more.

pws


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-11-08 15:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-07 23:50 Compiler warning after workers/39825 Bart Schaefer
2016-11-08  7:08 ` Sebastian Gniazdowski
2016-11-08  7:24   ` Sebastian Gniazdowski
2016-11-08 10:01     ` Peter Stephenson
2016-11-08 10:07       ` Peter Stephenson
2016-11-08 15:38         ` Daniel Shahaf
2016-11-08 15:44           ` Peter Stephenson
2016-11-08  8:36 ` Sebastian Gniazdowski

Code repositories for project(s) associated with this public inbox

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

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).