From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 67D131F61A for ; Tue, 25 Feb 2020 20:35:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728762AbgBYUfn (ORCPT ); Tue, 25 Feb 2020 15:35:43 -0500 Received: from pb-smtp2.pobox.com ([64.147.108.71]:60487 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728471AbgBYUfn (ORCPT ); Tue, 25 Feb 2020 15:35:43 -0500 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 398F250BEA; Tue, 25 Feb 2020 15:35:41 -0500 (EST) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=Z4LnYthXNvzr5/OFZh27btrRqoA=; b=r4TrjP lb/S2A3ltr0qnqhnEDi5rLhLubgaRF5YHu79Id/AdoTDiR+htvpjBubBG2zrO4aU /jNcW4CvCiCt/+sQ9Ggu0KHAgcmZWSLKIBNMsH06iZVlPkd/OSzvQrvYrJE2nc2k hpnCmIN6hT1z8PfiSHXpNGUDutV5DOzbj13xQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=X8Y8ZcTxPKvRmDm8n9PsyoqTMhO6lhkK FECyPn3UYu030EyH5yvXNAh60avIhIcvNqh6WU/Y+RXQq6l0PLYxTuBmY25X1mUs 0Qfc/2jyVD4i3nrIICzW/FTeIYGqrbpiu7QuQeho5IejTh/sU8GMv+qotUS8r+dx 42N7B2BGSZI= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 3136A50BE9; Tue, 25 Feb 2020 15:35:41 -0500 (EST) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.76.80.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 97C9E50BE8; Tue, 25 Feb 2020 15:35:40 -0500 (EST) (envelope-from junio@pobox.com) From: Junio C Hamano To: Heba Waly via GitGitGadget Cc: Emily Shaffer , git@vger.kernel.org, Heba Waly Subject: Re: [PATCH v5 2/3] advice: revamp advise API References: <20200225195648.GA212281@google.com> Date: Tue, 25 Feb 2020 12:35:39 -0800 In-Reply-To: (Junio C. Hamano's message of "Tue, 25 Feb 2020 12:09:12 -0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 634361E6-580E-11EA-9238-D1361DBA3BAF-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Junio C Hamano writes: > Emily Shaffer writes: > >>> ... Your get_config_value() would then become a mere lookup >>> in advice_setting[] array, e.g. >>> >>> int advice_enabled(unsigned advice_type) >>> { >>> static int initialized; >>> >>> if (!initialized) { >>> initialized = 1; >>> git_config(populate_advice_settings, NULL); >>> } >>> if (ARRAY_SIZE(advice_setting) <= advice_type) >>> BUG("OOB advice type requested???"); >>> return !advice_setting[advice_type].disabled; >>> } >>> >>> with your "push-update-rejected has two names" twist added. One beauty of the approach is that the "twist" can be done in the initialization codepath, e.g. int advice_enabled(unsigned advice_type) { static int initialized; if (!initialized) { initialized = 1; git_config(populate_advice_settings, NULL); advice_setting[ADVICE_PUSH_UPDATE_REJECTED] &= advice_setting[ADVICE_PUSH_UPDATE_REJECTED_ALIAS]; } if (ARRAY_SIZE(advice_setting) <= advice_type) BUG("OOB advice type requested???"); return !advice_setting[advice_type].disabled; } which means that the function literally becomes an array access that is guarded for out-of-bounds index. Thanks, Emily, for making me look at the suggested code again to realize this ;-)