Hi,

2013/05/20 Mon 23:39:13 UTC+9 mattn wrote:
> On Monday, May 20, 2013 11:38:35 PM UTC+9, mattn wrote:
> > https://gist.github.com/mattn/5612637
> 
> Ah, sorry. I had pushed "Post" button.
> But subtitle says all.

I also found some problems in regexp_nfa:

 1. Character classes such as [[:cntrl:]] or [[:alpha:]] may match
    multibyte character unexpectedly.
 2. Debug log (postfix notation) may contain garbage outputs.

Attached patch fixes them.

Thanks,
Ken Takata

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -1824,13 +1824,13 @@
 	else if (retval == OK)
 	    fprintf(f, ">>> NFA engine succeeded !\n");
 	fprintf(f, "Regexp: \"%s\"\nPostfix notation (char): \"", expr);
-	for (p=post_start; *p; p++)
+	for (p = post_start; *p && p < post_end; p++)
 	{
 	    nfa_set_code(*p);
 	    fprintf(f, "%s, ", code);
 	}
 	fprintf(f, "\"\nPostfix notation (int): ");
-	for (p=post_start; *p; p++)
+	for (p = post_start; *p && p < post_end; p++)
 		fprintf(f, "%d ", *p);
 	fprintf(f, "\n\n");
 	fclose(f);
@@ -2665,11 +2665,11 @@
     switch (class)
     {
 	case NFA_CLASS_ALNUM:
-	    if (isalnum(c))
+	    if ((1 <= c && c <= 255) && isalnum(c))
 		return OK;
 	    break;
 	case NFA_CLASS_ALPHA:
-	    if (isalpha(c))
+	    if ((1 <= c && c <= 255) && isalpha(c))
 		return OK;
 	    break;
 	case NFA_CLASS_BLANK:
@@ -2677,7 +2677,7 @@
 		return OK;
 	    break;
 	case NFA_CLASS_CNTRL:
-	    if (iscntrl(c))
+	    if ((1 <= c && c <= 255) && iscntrl(c))
 		return OK;
 	    break;
 	case NFA_CLASS_DIGIT:
@@ -2685,7 +2685,7 @@
 		return OK;
 	    break;
 	case NFA_CLASS_GRAPH:
-	    if (isgraph(c))
+	    if ((1 <= c && c <= 255) && isgraph(c))
 		return OK;
 	    break;
 	case NFA_CLASS_LOWER:
@@ -2697,7 +2697,7 @@
 		return OK;
 	    break;
 	case NFA_CLASS_PUNCT:
-	    if (ispunct(c))
+	    if ((1 <= c && c <= 255) && ispunct(c))
 		return OK;
 	    break;
 	case NFA_CLASS_SPACE:

Raspunde prin e-mail lui