From patchwork Sun Jan 19 05:52:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Shen X-Patchwork-Id: 312364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 00D942C00A5 for ; Sun, 19 Jan 2014 16:53:14 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=eIwF5d95+GzYFcetXdng/qLXWHClv27/eOzaBdiJRSoAqk Q9aFzixWERctZWbiNsEBuOmtq1xgsaouUq4WOruWzjr9hjApAhh/jN2ZAbLKyvsq TBSG6sl8lMCIuFVxkrOGKvoDkvQKF2nLFoQfRUMWYYFqv9ScsWine6jAk2vuc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=rCpwg/5yu3KrLLlnXy8aO59boaA=; b=T5vmONtjCup876NHl5yr B29ppjrU/LiA6ue3d6Hop+1u45BHnrAlufmilU3diiA10gwS7wo6kEocjxYWwU7d LwXDIbuC3ZLB/2KMDeB1y0Ir5qNhxuHyL26gFkvMgAPEhslTPqrEVwzW2oBVQYbw PAsmwNG0wYlWURD7GIWMgRQ= Received: (qmail 15345 invoked by alias); 19 Jan 2014 05:52:57 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 15327 invoked by uid 89); 19 Jan 2014 05:52:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-ob0-f169.google.com Received: from mail-ob0-f169.google.com (HELO mail-ob0-f169.google.com) (209.85.214.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 19 Jan 2014 05:52:55 +0000 Received: by mail-ob0-f169.google.com with SMTP id wo20so1689899obc.28 for ; Sat, 18 Jan 2014 21:52:53 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.182.194.5 with SMTP id hs5mr9610281obc.19.1390110772957; Sat, 18 Jan 2014 21:52:52 -0800 (PST) Received: by 10.182.162.33 with HTTP; Sat, 18 Jan 2014 21:52:52 -0800 (PST) Date: Sun, 19 Jan 2014 00:52:52 -0500 Message-ID: Subject: [Patch] Fix regex multiple consecutive quantifiers bug. From: Tim Shen To: "libstdc++" , gcc-patches X-IsSubscribed: yes Regex like "a**" will throw an unexpected exception. Now fixed (but currently no optimizations on it). Booted and tested with -m64 and -m32 respectively. Thank you! diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h index 216f8fb..fe2e5f1 100644 --- a/libstdc++-v3/include/bits/regex_compiler.h +++ b/libstdc++-v3/include/bits/regex_compiler.h @@ -83,7 +83,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_assertion(); - void + bool _M_quantifier(); bool diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc b/libstdc++-v3/include/bits/regex_compiler.tcc index 621e43f..128dac1 100644 --- a/libstdc++-v3/include/bits/regex_compiler.tcc +++ b/libstdc++-v3/include/bits/regex_compiler.tcc @@ -135,7 +135,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return true; if (this->_M_atom()) { - this->_M_quantifier(); + while (this->_M_quantifier()); return true; } return false; @@ -173,7 +173,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - void + bool _Compiler<_TraitsT>:: _M_quantifier() { @@ -276,6 +276,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } _M_stack.push(__e); } + else + return false; + return true; } #define __INSERT_REGEX_MATCHER(__func, args...)\ diff --git a/libstdc++-v3/testsuite/28_regex/basic_regex/empty_range.cc b/libstdc++-v3/testsuite/28_regex/basic_regex/empty_range.cc new file mode 100644 index 0000000..f61ae77 --- /dev/null +++ b/libstdc++-v3/testsuite/28_regex/basic_regex/empty_range.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2013-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 28.11.2 regex_match +// Tests ECMAScript empty range. + +#include +#include +#include + +using namespace __gnu_test; +using namespace std; + +int +main() +{ + regex re("a++"); + return 0; +}