From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 1935C3844023 for ; Thu, 17 Jun 2021 20:44:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1935C3844023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=jguk.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jguk.org Received: by mail-wr1-x42c.google.com with SMTP id y7so8162752wrh.7 for ; Thu, 17 Jun 2021 13:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jguk.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qr4SkaeLkstWDRdpXPCobF2JCfNvbxmAghMtIiFhP9w=; b=fSXc6S17jVgkPJcVqd+SlfMo9086A6aCPdM9jhC2tS9Mx0LWXfbLpgu7MIAkZZEFJ7 SHSYVz9ONzvhX/JVj8MY++35GwZDKOnZQvZ6YA0uBSFJfVQIoi90vc0GdlVAODgEMuBb lA4QQ9GI1JKg7u1CuOu4hSWK2Ts/gmHGS/PEOSwZcgAGBFdpZYeT03mqo0j6f+Cqv4x2 xRkigWeKGdGTQdAQJnBsF61u7isXO6YR78t2PUDGZx4tAdlR+hedQySByfHZkjs9Z9u0 Lf5jrGsFu0++tZiK6jjYMq9JTVG7XQ1KAi9S0OZKgDId7Wy8057cF/56wZGLtX1XjyRD dUvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qr4SkaeLkstWDRdpXPCobF2JCfNvbxmAghMtIiFhP9w=; b=e3Nk4hfokXWxbb775PpryvV05N3RbhCtgKPumztyTNZlI0MJh/dCDDN1xl7CUk3xEi SycIFdMDtjMnv4msaka5EcZDUvwE71CBWHErNVC02ew/jrXi7KvAekipBORokS00bWfL q4vm1JRSU3geq6SIMF8Q6VmSS+mrTUWs/2Yp7q7rgO9XsdjP3eiuEVEKY4Wm2rNSk6Nl LvoI+i6jqDTAyB2+BC2Cx7XK/EgRNAeAgo4pb0grW/JJmB3BqUKBf1O5WY3L+EuDn+73 bAsjOG51Y0eHiqyQue4s7ETfS3OYOVi/3zRTimV6QZ3RXjdubkq0Moq5o6+IxZ4rAF47 mrIQ== X-Gm-Message-State: AOAM531uqwvO71emH6fqEKkLgvmihhv6Qd3XfX5HShuyDQI5Qcy1jNc1 BTDxfE6vuS/jDeDI+zt5HFb8/MextrVeag== X-Google-Smtp-Source: ABdhPJzu/6LFmh+ziTMZUL2wfQAGrRMvYp5A0gz7/zDIQbWxHR1yVhSI0X6Ha3w2DxRkfrvzuqLlsw== X-Received: by 2002:adf:d1c3:: with SMTP id b3mr8235728wrd.110.1623962669760; Thu, 17 Jun 2021 13:44:29 -0700 (PDT) Received: from [192.168.0.12] (cpc87345-slou4-2-0-cust172.17-4.cable.virginm.net. [81.101.252.173]) by smtp.gmail.com with ESMTPSA id o18sm6319239wrx.59.2021.06.17.13.44.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 13:44:29 -0700 (PDT) Subject: Re: gcc warn when pointers not checked non-null before de-referencing. To: Segher Boessenkool Cc: Xi Ruoyao , gcc-help References: <0a9ccbb7-135a-b342-e5cb-35b7c6a44a00@jguk.org> <97eb7315fd136ff8a818925b1704760a856ffe64.camel@mengyan1223.wang> <0770e060-6388-fc27-1178-205b867bfae2@jguk.org> <20210616175941.GJ5077@gate.crashing.org> From: Jonny Grant Message-ID: Date: Thu, 17 Jun 2021 21:44:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210616175941.GJ5077@gate.crashing.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2021 20:44:32 -0000 On 16/06/2021 18:59, Segher Boessenkool wrote: > On Wed, Jun 16, 2021 at 02:01:05PM +0100, Jonny Grant wrote: >> I guess a separate static analyser would do it, GCC is more focused on compilation so I shouldn't ask for it to have so many features it can't support. > > -fsanitize=undefined already catches null pointer dereferences, is that > enough for your case? > > > Segher Hello Thank you for the suggestion, yes, I had used that before. I did just check, it's runtime checks. I had hoped for something at compile time. warning for every function that didn't check pointer for NULL before de-referencing. $ ./null null.c:7:5: runtime error: load of null pointer of type 'int' Segmentation fault (core dumped) // gcc -Wall -fsanitize=undefined -o null null.c #include void f(int * p) { printf("%d\n", *p); } int main() { f(NULL); }