From patchwork Tue Jan 31 13:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 64014 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE847382E6A6 for ; Tue, 31 Jan 2023 13:29:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 93E5338468E6 for ; Tue, 31 Jan 2023 13:29:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 93E5338468E6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-ej1-x636.google.com with SMTP id dr8so19997130ejc.12 for ; Tue, 31 Jan 2023 05:29:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NK/KcQKh7msOycO1o9c0hM19wkVs25rFAkXQX/vMjEs=; b=Dp15vYiABxIdcbBav4LJJMFeet7NjGyESXFi7PMzTGEXtZGlMSGk3+ecDm8JESyv5Y BLoVUromtY9Cfx8Ya/sCIr0QEVHaxwjcxWTEVYeQoLaO4enviDolzmCZG33jYTq0mtG3 Ki1fruU9Y8B9J+713QzrXk7ppcb7mPLaxJCUoxrvtn66T2ZdJtWAdkvcuAGFWddZcs/v ISs3GhbbBt3qqzGrA3UGF5ImbctEO1jzm+4TTbeGAJZ6ZbIIU3fKX2aiDME7lgvAkqBO 56U6CmcV9CylieoUFJlSkIgEhWB2feoSV5VzWEW9EpLGBm3zoSld4ON/UAS2ZUpfAxzN uvVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NK/KcQKh7msOycO1o9c0hM19wkVs25rFAkXQX/vMjEs=; b=VDiyz+OljVrOkIP3U7oy3xaP8Bnqw+15vKZTSGYg/Wdjq3/GZtOdx+S8f2Ab2pyFCt z/llhZ4pT3I8etmo+7DlPIYKfu3rrCJ7EgNV/6avGrK6rfNLejIAivjiPywJzlosI+HJ eCLrRg4A0bbGLsvO1ryaYSeLw7N8zB2vH96GmFr/Hauap1B3OiRoysANqGI4Jv5mjEx0 LiNRBQLUil7zfh8R7wqG5DXMzgY4WpJs8pQNsQ/n8zfVhkC9m5sPBsgbCVVVndUiuQ+g r/6sxRC2UWF2CpVR75cH33YgOcEVl5ZwzIS3cXR/0Ce3knNWweX3U4GjCZ3HQrxy0HwA IBUg== X-Gm-Message-State: AO0yUKUiLAyGASm3ipg4LByACO/x9Nmp64hzWl4J6Re0xhAWfXkeqftO 7R/GTwf8zB0zkS0+sWgL5DhhvYtpJVTLIhWpYg== X-Google-Smtp-Source: AMrXdXsFKSN41NVUjS0E1C4aOUAK0zunBl9b7iVyCxqr4H524xpCgAzdOQj317g+XxfWrpQyCEx/Pg== X-Received: by 2002:a1c:f203:0:b0:3da:fa42:bbf2 with SMTP id s3-20020a1cf203000000b003dafa42bbf2mr52307011wmc.28.1675171290615; Tue, 31 Jan 2023 05:21:30 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id b48-20020a05600c4ab000b003db1ca20170sm6763651wmp.37.2023.01.31.05.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:21:30 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [COMMITTED] gccrs: Add guards against getting data from an empty vector Date: Tue, 31 Jan 2023 14:25:15 +0100 Message-Id: <20230131132515.661993-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-15.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyctx.cc (TypeCheckContext::pop_return_type): Add guards around `std::vector.pop_back()`. (TypeCheckContext::peek_context): Likewise for `std::vector.back()`. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/typecheck/rust-tyctx.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/rust/typecheck/rust-tyctx.cc b/gcc/rust/typecheck/rust-tyctx.cc index ad5f67cc1dd..af86b064c6c 100644 --- a/gcc/rust/typecheck/rust-tyctx.cc +++ b/gcc/rust/typecheck/rust-tyctx.cc @@ -142,12 +142,14 @@ TypeCheckContext::push_return_type (TypeCheckContextItem item, void TypeCheckContext::pop_return_type () { + rust_assert (!return_type_stack.empty ()); return_type_stack.pop_back (); } TypeCheckContextItem & TypeCheckContext::peek_context () { + rust_assert (!return_type_stack.empty ()); return return_type_stack.back ().first; }