unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Suspicious code in search.c
@ 2005-10-20 14:52 Kim F. Storm
  2005-10-20 23:38 ` Richard M. Stallman
  2005-10-21  0:46 ` Kenichi Handa
  0 siblings, 2 replies; 7+ messages in thread
From: Kim F. Storm @ 2005-10-20 14:52 UTC (permalink / raw)



See search.c line 1711-1712:

	  if (ASCII_BYTE_P (*ptr) || ! multibyte)
	    ch = *ptr;
-->	  else if (charset_base
-->		   && (pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1]))
	    {
	      unsigned char *charstart = ptr - 1;


Based on the indentation, I would assume the following interpretation
is intended:

	  else if (charset_base
		   && ((pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1])))
		      ^                                            ^

Can somebody who knows this code better than I take a look (and
perhaps reformat the code if the current code is ok).


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: Suspicious code in search.c
  2005-10-20 14:52 Suspicious code in search.c Kim F. Storm
@ 2005-10-20 23:38 ` Richard M. Stallman
  2005-10-21  0:52   ` Kenichi Handa
  2005-10-21  0:46 ` Kenichi Handa
  1 sibling, 1 reply; 7+ messages in thread
From: Richard M. Stallman @ 2005-10-20 23:38 UTC (permalink / raw)
  Cc: emacs-devel, Kim F. Storm

    See search.c line 1711-1712:

	      if (ASCII_BYTE_P (*ptr) || ! multibyte)
		ch = *ptr;
    -->	  else if (charset_base
    -->		   && (pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1]))
		{
		  unsigned char *charstart = ptr - 1;

Handa, you wrote that code in April.  Can you clear it up?

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

* Re: Suspicious code in search.c
  2005-10-20 14:52 Suspicious code in search.c Kim F. Storm
  2005-10-20 23:38 ` Richard M. Stallman
@ 2005-10-21  0:46 ` Kenichi Handa
  2005-10-21  2:01   ` Nick Roberts
  1 sibling, 1 reply; 7+ messages in thread
From: Kenichi Handa @ 2005-10-21  0:46 UTC (permalink / raw)
  Cc: emacs-devel

In article <m37jc8i6l1.fsf@kfs-l.imdomain.dk>, storm@cua.dk (Kim F. Storm) writes:

> See search.c line 1711-1712:

> 	  if (ASCII_BYTE_P (*ptr) || ! multibyte)
> 	    ch = *ptr;
--> 	  else if (charset_base
--> 		   && (pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1]))
> 	    {
> 	      unsigned char *charstart = ptr - 1;


> Based on the indentation, I would assume the following interpretation
> is intended:

> 	  else if (charset_base
> 		   && ((pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1])))
> 		      ^                                            ^

Yes, and a compiler should interpret that part as above.
But, I agree that it's better to add that explicit parentheses.

> Can somebody who knows this code better than I take a look (and
> perhaps reformat the code if the current code is ok).

Done.

---
Kenichi Handa
handa@m17n.org

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

* Re: Suspicious code in search.c
  2005-10-20 23:38 ` Richard M. Stallman
@ 2005-10-21  0:52   ` Kenichi Handa
  2005-10-21 17:51     ` Richard M. Stallman
  0 siblings, 1 reply; 7+ messages in thread
From: Kenichi Handa @ 2005-10-21  0:52 UTC (permalink / raw)
  Cc: emacs-devel, storm

In article <E1ESjzL-0004ZL-8D@fencepost.gnu.org>, "Richard M. Stallman" <rms@gnu.org> writes:

>     See search.c line 1711-1712:
> 	      if (ASCII_BYTE_P (*ptr) || ! multibyte)
> 		ch = *ptr;
--> 	  else if (charset_base
--> 		   && (pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1]))
> 		{
> 		  unsigned char *charstart = ptr - 1;

> Handa, you wrote that code in April.  Can you clear it up?

I've just done it.

---
Kenichi Handa
handa@m17n.org

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

* Re: Suspicious code in search.c
  2005-10-21  0:46 ` Kenichi Handa
@ 2005-10-21  2:01   ` Nick Roberts
  2005-10-21  2:27     ` Kenichi Handa
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Roberts @ 2005-10-21  2:01 UTC (permalink / raw)
  Cc: emacs-devel, Kim F. Storm

Kenichi Handa writes:
 > In article <m37jc8i6l1.fsf@kfs-l.imdomain.dk>, storm@cua.dk (Kim F. Storm) writes:
 > 
 > > See search.c line 1711-1712:
 > 
 > > 	  if (ASCII_BYTE_P (*ptr) || ! multibyte)
 > > 	    ch = *ptr;
 > --> 	  else if (charset_base
 > --> 		   && (pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1]))
 > > 	    {
 > > 	      unsigned char *charstart = ptr - 1;
 > 
 > 
 > > Based on the indentation, I would assume the following interpretation
 > > is intended:
 > 
 > > 	  else if (charset_base
 > > 		   && ((pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1])))
 > > 		      ^                                            ^
 > 
 > Yes, and a compiler should interpret that part as above.
 > But, I agree that it's better to add that explicit parentheses.

The original expression is equivalent to:

 	  else if ((charset_base
 		   && (pat_end - ptr) == 1) || CHAR_HEAD_P (ptr[1]))

I don't know which expression is right, but you've changed the logic.

Nick


main ()
{
  if (0 && 0 || 1) printf ("1\n");
  if ((0 && 0) || 1) printf ("2\n");
  if (0 && (0 || 1)) printf ("3\n");
}

nickrob/38 mytest
1
2

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

* Re: Suspicious code in search.c
  2005-10-21  2:01   ` Nick Roberts
@ 2005-10-21  2:27     ` Kenichi Handa
  0 siblings, 0 replies; 7+ messages in thread
From: Kenichi Handa @ 2005-10-21  2:27 UTC (permalink / raw)
  Cc: storm, emacs-devel

In article <17240.19436.738186.836546@kahikatea.snap.net.nz>, Nick Roberts <nickrob@snap.net.nz> writes:
> The original expression is equivalent to:

>  	  else if ((charset_base
>  		   && (pat_end - ptr) == 1) || CHAR_HEAD_P (ptr[1]))

> I don't know which expression is right, but you've changed the logic.

Oops, you are right.  I misunderstood.  Yes, I changed the
logic and I think the change is correct.  This is the place
to check if *ptr is the last byte of a multibyte character.
It is so if *ptr is the last byte of the whole text or
ptr[1] is the first byte of a character.

---
Kenichi Handa
handa@m17n.org

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

* Re: Suspicious code in search.c
  2005-10-21  0:52   ` Kenichi Handa
@ 2005-10-21 17:51     ` Richard M. Stallman
  0 siblings, 0 replies; 7+ messages in thread
From: Richard M. Stallman @ 2005-10-21 17:51 UTC (permalink / raw)
  Cc: storm, emacs-devel

    > Handa, you wrote that code in April.  Can you clear it up?

    I've just done it.

Thanks.

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

end of thread, other threads:[~2005-10-21 17:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-20 14:52 Suspicious code in search.c Kim F. Storm
2005-10-20 23:38 ` Richard M. Stallman
2005-10-21  0:52   ` Kenichi Handa
2005-10-21 17:51     ` Richard M. Stallman
2005-10-21  0:46 ` Kenichi Handa
2005-10-21  2:01   ` Nick Roberts
2005-10-21  2:27     ` Kenichi Handa

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

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).