From patchwork Tue Nov 8 07:01:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Shen X-Patchwork-Id: 81242 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1401489qge; Mon, 7 Nov 2016 23:01:52 -0800 (PST) X-Received: by 10.98.31.14 with SMTP id f14mr20672843pff.27.1478588512851; Mon, 07 Nov 2016 23:01:52 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 138si35514946pgg.76.2016.11.07.23.01.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 23:01:52 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-440690-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-440690-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440690-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=REJECT dis=NONE) header.from=google.com 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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=rgXUMnzVelHUfZxGFCeqdbThlq17cEEok77tyR1xdVydm7 795PxXC39Ewp5eACMrdtxTv70VXNlNvu38vgWrIbDHtLoGwZ/n8+hfVZmZGsonGS Kmq3yCWn0k6nRR4iPMGFGwqOm/on/ojAxMQIRK54sdTP3VeCDNwseKz4440o0= 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:from:date:message-id:subject:to:content-type; s= default; bh=WwlbJZE0W/R+gFSezk7QYFk2q8M=; b=FWUdgcLMfoRQSSJJx8Rb obSe3BsPkpzagCAb3pJ+fgziVY4vqncqXB/JZ+auL6j6ICwMH8SL+HEBHp27LVKj ZaLAQ3Fc+9jR7ERdtG8un1w7P1EhCTBWVAhDPrntFUd7dWfIhBFaYpFlkItA0vFH N7STBBWfzLTDljMabHfgRpU= Received: (qmail 23726 invoked by alias); 8 Nov 2016 07:01:32 -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 23689 invoked by uid 89); 8 Nov 2016 07:01:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=80, 6 X-HELO: mail-vk0-f45.google.com Received: from mail-vk0-f45.google.com (HELO mail-vk0-f45.google.com) (209.85.213.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 Nov 2016 07:01:20 +0000 Received: by mail-vk0-f45.google.com with SMTP id 137so93739885vkl.0 for ; Mon, 07 Nov 2016 23:01:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=fCZ90KH8liczI2W0I0s5zUC+dsuSVupc4Nhh8smFfZM=; b=Ux6uCg53MSFdF6rNbj1mOL5N4aDiwm49mD0HdvD/chDUGOF/vHMgm8Slv4639iG9KG oC6CAc4QR4ilaw6iN/5qpuH6+jzhdvIEVRjH3Bu1KKle6znQ74JorLJNNW+HFKHEumoD /9qK1E9Nns3Qs6Y/OTuY1vyFYP3jEOa3kLnfiVWQMfFq9CDTJr7fGqYSgoER7IUf0ZJ5 FE7a2W1VvKNqgnZB1Ht3dBpHot6UF4w9bIMYwX9ugehF84UQC5dflqb2W4ClgGkcSfQ1 E5YQ22kXxmAGUOnZLpcaLdbyzZjGUEInDnud7hssi4ZDLwygtkmCFkPnoYymWj9Llriq HvHQ== X-Gm-Message-State: ABUngveeg/lFm03Tvs/JSeTW6/NN+dXBiNnIBKHa9+AN569djj1L0OR1kKW5BleHGh+av9obtVrlCH09kOpGkWz+ X-Received: by 10.31.207.199 with SMTP id f190mr6173057vkg.32.1478588478345; Mon, 07 Nov 2016 23:01:18 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.24.133 with HTTP; Mon, 7 Nov 2016 23:01:17 -0800 (PST) From: Tim Shen Date: Mon, 7 Nov 2016 23:01:17 -0800 Message-ID: Subject: [PATCH] Fix regex_iterator end() state and operator==() To: "libstdc++" , gcc-patches This fixes libstdc++/78236. I'm surprised that this bug was not revealed until now :P. Bootstrapped and tested under x86_64-linux-gnu. I'm happy with however many backports. -- Regards, Tim Shen commit 8aee66b743b5b0ef09cbc9587ebbacf6665ba0cb Author: Tim Shen Date: Mon Nov 7 21:50:49 2016 -0800 * libstdc++-v3/include/bits/regex.h (regex_iterator::regex_iterator()): Define end() as _M_pregex == nullptr. * libstdc++-v3/include/bits/regex.tcc (regex_iterator::operator==(), regex_iterator::operator++()): Fix operator==() and operator++() to look at null-ness of _M_pregex on both sides. * testsuite/28_regex/regression.cc: New testcase. diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index a7d45e6..aadf312 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -2454,7 +2454,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * one-past-the-end of a range. */ regex_iterator() - : _M_match() + : _M_pregex() { } /** diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc index 4a3d7c3..3f8969d 100644 --- a/libstdc++-v3/include/bits/regex.tcc +++ b/libstdc++-v3/include/bits/regex.tcc @@ -496,12 +496,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>:: operator==(const regex_iterator& __rhs) const { - return (_M_match.empty() && __rhs._M_match.empty()) - || (_M_begin == __rhs._M_begin - && _M_end == __rhs._M_end - && _M_pregex == __rhs._M_pregex - && _M_flags == __rhs._M_flags - && _M_match[0] == __rhs._M_match[0]); + if (_M_pregex == nullptr && __rhs._M_pregex == nullptr) + return true; + return _M_pregex == __rhs._M_pregex + && _M_begin == __rhs._M_begin + && _M_end == __rhs._M_end + && _M_flags == __rhs._M_flags + && _M_match[0] == __rhs._M_match[0]; } template r("(f+)"); + { + std::cregex_iterator i(s, s+sizeof(s), r); + std::cregex_iterator j(s, s+sizeof(s), r); + VERIFY(i == j); + } + // The iterator manipulation code must be repeated in the same scope + // to expose the undefined read during the execution of the == + // operator (stack location reuse) + { + std::cregex_iterator i(s, s+sizeof(s), r); + std::cregex_iterator j; + VERIFY(!(i == j)); + } +} + int main() { @@ -80,6 +101,7 @@ main() test03(); test04(); test05(); + test06(); return 0; }