From patchwork Sun Jan 18 16:31:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 430227 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 0FABE1401D0 for ; Mon, 19 Jan 2015 03:32:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=lN58B+jKyq0vy8VvIMWgGbRJGGNUTq/jFqmqJHTzDr5a/Qg9JqOQA O+AhvtVurXtQ8PFi+DRg/nEwcJ104DkIFdLhyZg+QVxCaZXzoaa9+BPE8Ccbc6+b VFk8gB5aOVpepQveaJLNZ/5/l4MRkqbszOIaeZQuvrgFAx4qRMF4ZU= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=tiItZBcRGqBtJXAlll1Zg9hUI/M=; b=JkwcOPN/wPN8m5klFVYA OkSbkdDE3ezw+BASGybwGsSQCTwKlTPYnXeHcSVoOTcfnBeG0xHRm2ozKBdXiTNP Mfq2G+9jqKt4p9Qf0eRGTlpZWUoNLNDnZgk8c0goLUEwIWJgKwwQczELtoEbjqBr JOaJQVtDTjcdlDhEiahEg+o= Received: (qmail 16645 invoked by alias); 18 Jan 2015 16:31:43 -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 16458 invoked by uid 89); 18 Jan 2015 16:31:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sun, 18 Jan 2015 16:31:41 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0IGVdUS031145 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 18 Jan 2015 11:31:39 -0500 Received: from localhost (ovpn-116-18.ams2.redhat.com [10.36.116.18]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0IGVcwA025403; Sun, 18 Jan 2015 11:31:39 -0500 Date: Sun, 18 Jan 2015 16:31:38 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] libstdc++/64646 fix 4-iterator overload of std::is_permutation Message-ID: <20150118163138.GC3360@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Fix a past-the-end dereference in the new C++14 version of is_permutation. This only affects C++14 mode, but fixes a new function that exists entirely because it's meant to be safer than the C++98 version ... but it isn't safer if it goes past-the-end! Tested x86_64-linux, committed to 4.9 and trunk. commit dd920757d437ffa60a0f9b008e57507d4c8ee831 Author: redi Date: Sun Jan 18 16:31:06 2015 +0000 PR libstdc++/64646 * include/bits/stl_algo.h (__is_permutation): Also test for reaching end of the second range. * testsuite/25_algorithms/is_permutation/64646.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219821 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 3325b94..c27c092 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -3601,7 +3601,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Efficiently compare identical prefixes: O(N) if sequences // have the same elements in the same order. - for (; __first1 != __last1; ++__first1, ++__first2) + for (; __first1 != __last1 && __first2 != __last2; + ++__first1, ++__first2) if (!__pred(__first1, __first2)) break; diff --git a/libstdc++-v3/testsuite/25_algorithms/is_permutation/64646.cc b/libstdc++-v3/testsuite/25_algorithms/is_permutation/64646.cc new file mode 100644 index 0000000..799a18c --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/is_permutation/64646.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2015 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 +// . + +// { dg-options "-std=gnu++14" } + +#include +#include +#include + +void +test01() +{ + std::forward_list l1{0}, l2; + VERIFY( !std::is_permutation(l1.begin(), l1.end(), l2.begin(), l2.end()) ); +} + +int +main() +{ + test01(); +}