Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Jan 2019 02:59:20 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r342910 - head/gnu/usr.bin/grep
Message-ID:  <201901100259.x0A2xKSZ072907@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Thu Jan 10 02:59:19 2019
New Revision: 342910
URL: https://svnweb.freebsd.org/changeset/base/342910

Log:
  grep(1) outputs NOT-matched lines with multi-byte characters
  
  PR	113343
  MFC after:	2 months

Modified:
  head/gnu/usr.bin/grep/search.c

Modified: head/gnu/usr.bin/grep/search.c
==============================================================================
--- head/gnu/usr.bin/grep/search.c	Thu Jan 10 02:01:20 2019	(r342909)
+++ head/gnu/usr.bin/grep/search.c	Thu Jan 10 02:59:19 2019	(r342910)
@@ -401,9 +401,12 @@ EGexecute (char const *buf, size_t size, size_t *match
 			}
 
 		      if (mlen == (size_t) -2)
-			/* Offset points inside multibyte character:
-			 * no good. */
-			break;
+			{
+			  /* Offset points inside multibyte character:
+			   * no good. */
+			  memset (&mbs, '\0', sizeof (mbstate_t));
+			  break;
+			}
 
 		      beg += mlen;
 		      bytes_left -= mlen;
@@ -463,9 +466,12 @@ EGexecute (char const *buf, size_t size, size_t *match
 			}
 
 		      if (mlen == (size_t) -2)
-			/* Offset points inside multibyte character:
-			 * no good. */
-			break;
+			{
+			  /* Offset points inside multibyte character:
+			   * no good. */
+			  memset (&mbs, '\0', sizeof (mbstate_t));
+			  break;
+			}
 
 		      beg += mlen;
 		      bytes_left -= mlen;
@@ -926,15 +932,21 @@ Fexecute (char const *buf, size_t size, size_t *match_
 		}
 
 	      if (mlen == (size_t) -2)
-		/* Offset points inside multibyte character: no good. */
-		break;
+		{
+		  /* Offset points inside multibyte character: no good. */
+		  memset (&mbs, '\0', sizeof (mbstate_t));
+		  break;
+		}
 
 	      beg += mlen;
 	      bytes_left -= mlen;
 	    }
 
 	  if (bytes_left)
-	    continue;
+	    {
+	      beg += bytes_left;
+	      continue;
+	    }
 	}
       else
 #endif /* MBS_SUPPORT */
@@ -1052,6 +1064,7 @@ Fexecute (char const *buf, size_t size, size_t *match_
 			    {
 			      /* Offset points inside multibyte character:
 			       * no good. */
+			      memset (&mbs, '\0', sizeof (mbstate_t));
 			      break;
 			    }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201901100259.x0A2xKSZ072907>