From patchwork Sat Jan 19 19:23:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 213880 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]) by ozlabs.org (Postfix) with SMTP id B8E812C0087 for ; Sun, 20 Jan 2013 06:23:54 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1359228236; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Cc:Subject:Date:Message-ID: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=IjXgHk8xQ12Be4wZtUPTGt7MH8Y=; b=yGPOz8GISSV8ksR p8b0uMV1T5em+nVRG/D3HDtca8DJKhhZ82EHZdIp7Egk+PQL5JxDM1PVqPH4kD9l aNe3r56lFeToADh38QJkh4nI1PZTsA+Pyc9HPhGzBGqQngLOnP7puQL2kfbKrrwS fRohaAjAwS13T+NSvpIUtDniouIU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:X-Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=PgPAcNA4doxNFtee2nTIWeSrwHb8UCN2+2+mu2+9rl1hqaOewf1gXxZbeqAHVR ZmAz96hjcL2mrwObyuzv4f3vKt9EfAUfWvqCybCKQOj4UUHo9cK27NFYKE2z65rY rJtvR/VMyg0LXoKe6Fnvm2vE0qeeQgwDPSHVHEeijhiS0=; Received: (qmail 14288 invoked by alias); 19 Jan 2013 19:23:49 -0000 Received: (qmail 14280 invoked by uid 22791); 19 Jan 2013 19:23:48 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-ye0-f202.google.com (HELO mail-ye0-f202.google.com) (209.85.213.202) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 19 Jan 2013 19:23:42 +0000 Received: by mail-ye0-f202.google.com with SMTP id r9so550873yen.3 for ; Sat, 19 Jan 2013 11:23:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:mime-version :content-type:x-gm-message-state; bh=cNJ3yFAAe4uwsUdqbWMhkluSR+xc7TaanG/nj+lL884=; b=n7OzLJ8LQPJuIL4vRv1kvpMknCZx0OB7bJ/20+V6rpxupzgQ7dYWIvzrpIWquqne9O mMcLA5kASiqESOCvR+lJBR6yiE5u5z3eB4xAk6pQNicp4bVDH4/eTGsDBw1XTXlbF6jk RRauGZ4E0jM889V8JRZ5JpKw6MjGHJp4LNy8dUxNx0pYGJ0xFX+3RWrzdCdP0LzqC+cL tYiwNAGypXrjw24XaGbwW+221wgW9FGiwayuCtUQRj8TMHrhIYgPrTy5CfytBmOybYec F/7LCM0FD47xy4TIMXZkQonFiEUeFUeUDaIJV6Ib99uG1VMdfLNvrcX7rXY7gQ8RawFT 1MCw== X-Received: by 10.236.154.34 with SMTP id g22mr1556855yhk.3.1358623421287; Sat, 19 Jan 2013 11:23:41 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id i63si358293yhk.5.2013.01.19.11.23.41 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sat, 19 Jan 2013 11:23:41 -0800 (PST) Received: from elbrus2.mtv.corp.google.com (elbrus2.mtv.corp.google.com [172.17.128.95]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 24FB331C1DD; Sat, 19 Jan 2013 11:23:41 -0800 (PST) Received: by elbrus2.mtv.corp.google.com (Postfix, from userid 74925) id BEFFE1C4611; Sat, 19 Jan 2013 11:23:40 -0800 (PST) From: Paul Pluzhnikov To: dnovillo@google.com, gcc-patches@gcc.gnu.org Cc: ppluzhnikov@google.com Subject: [google gcc-4_7, integration] Add lightweight checks for front()/back() on empty vector Date: Sat, 19 Jan 2013 11:23:40 -0800 Message-ID: MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkV2kgm0PFybVIaPuAhl+cx8omn86tVBMKnHpxA4KKmKD3dCuKpH9UBDmvaAV8LPimdq6cn4/JrJuEAtfb3jrxbaVQLfuacaZlfhnYPYx9/0TKFDaxqlyutetE4jtKz5bB27PKoKjRoC/8TUygNwFHTtMdqCFvmqauUl5u+gepvSGooBQkZN7rGbVRP5Ym/ONl/LywVnMdAy8r08D85Jl9MZ8MhyCkWsu3MNYtbfsB4T1kU580= 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 This patch adds lightweight checks for front()/back() on empty vector. Google ref b/7939186 Ok for google/gcc-4_7 and google/integration branches? --- Paul Pluzhnikov Index: libstdc++-v3/include/bits/stl_vector.h =================================================================== --- libstdc++-v3/include/bits/stl_vector.h (revision 195313) +++ libstdc++-v3/include/bits/stl_vector.h (working copy) @@ -878,7 +878,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ reference front() - { return *begin(); } + { +#if __google_stl_debug_vector + if (empty()) __throw_logic_error("begin() on empty vector"); +#endif + return *begin(); + } /** * Returns a read-only (constant) reference to the data at the first @@ -886,7 +891,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ const_reference front() const - { return *begin(); } + { +#if __google_stl_debug_vector + if (empty()) __throw_logic_error("begin() on empty vector"); +#endif + return *begin(); + } /** * Returns a read/write reference to the data at the last @@ -894,7 +904,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ reference back() - { return *(end() - 1); } + { +#if __google_stl_debug_vector + if (empty()) __throw_logic_error("back() on empty vector"); +#endif + return *(end() - 1); + } /** * Returns a read-only (constant) reference to the data at the @@ -902,7 +917,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ const_reference back() const - { return *(end() - 1); } + { +#if __google_stl_debug_vector + if (empty()) __throw_logic_error("back() on empty vector"); +#endif + return *(end() - 1); + } // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 464. Suggestion for new member functions in standard containers. @@ -917,7 +937,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER pointer #endif data() _GLIBCXX_NOEXCEPT - { return std::__addressof(front()); } + { +#if __google_stl_debug_vector + if (empty()) return 0; +#endif + return std::__addressof(front()); + } #ifdef __GXX_EXPERIMENTAL_CXX0X__ const _Tp* @@ -925,7 +950,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER const_pointer #endif data() const _GLIBCXX_NOEXCEPT - { return std::__addressof(front()); } + { +#if __google_stl_debug_vector + if (empty()) return 0; +#endif + return std::__addressof(front()); + } // [23.2.4.3] modifiers /**