From owner-svn-src-user@FreeBSD.ORG Fri Feb 24 13:11:50 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EC5AE106566C; Fri, 24 Feb 2012 13:11:50 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D76AD8FC15; Fri, 24 Feb 2012 13:11:50 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q1ODBoEe060273; Fri, 24 Feb 2012 13:11:50 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1ODBo76060269; Fri, 24 Feb 2012 13:11:50 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201202241311.q1ODBo76060269@svn.freebsd.org> From: Gabor Kovesdan Date: Fri, 24 Feb 2012 13:11:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r232110 - user/gabor/tre-integration/usr.bin/grep X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Feb 2012 13:11:51 -0000 Author: gabor Date: Fri Feb 24 13:11:50 2012 New Revision: 232110 URL: http://svn.freebsd.org/changeset/base/232110 Log: - Add an error handling after pattern matching (there was no error handling so far, although such error rarely occurs). - Simplify code Modified: user/gabor/tre-integration/usr.bin/grep/util.c Modified: user/gabor/tre-integration/usr.bin/grep/util.c ============================================================================== --- user/gabor/tre-integration/usr.bin/grep/util.c Fri Feb 24 13:05:10 2012 (r232109) +++ user/gabor/tre-integration/usr.bin/grep/util.c Fri Feb 24 13:11:50 2012 (r232110) @@ -285,20 +285,25 @@ procline(struct str *l, int nottext) (size_t)pmatch.rm_eo; if (r == REG_NOMATCH) continue; + else if (ret != REG_OK) + // XXX: better error msg? + errx(2, "Failed processing input."); + /* Check for full match */ - if (r == REG_OK && xflag) + if (xflag) if (pmatch.rm_so != 0 || (size_t)pmatch.rm_eo != l->len) - r = REG_NOMATCH; - if (r == REG_OK) { - if (m == 0) - c++; - if (m < MAX_LINE_MATCHES) - matches[m++] = pmatch; - /* matches - skip further patterns */ - if ((color == NULL && !oflag) || qflag || lflag) - break; - } + continue; + + /* If reached here, we have a match. */ + if (m == 0) + c++; + if (m < MAX_LINE_MATCHES) + matches[m++] = pmatch; + + /* matches - skip further patterns */ + if ((color == NULL && !oflag) || qflag || lflag) + break; if (vflag) { c = !c; @@ -306,7 +311,6 @@ procline(struct str *l, int nottext) } } - /* Count the matches if we have a match limit */ if (mflag) mcount -= c;