From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 26751389941F for ; Sat, 26 Nov 2022 15:48:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 26751389941F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62f.google.com with SMTP id d3so1448724plr.10 for ; Sat, 26 Nov 2022 07:48:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=vZNDhoyO9OSGjGjt0jxzNSm/X2FDlsf9i8lwwpI13L0=; b=Kkc1w5vvnvWilTbUFzZM9WvSV0RM3UzeSBTatKMdEH4E0/E6mERijMca6BoFggbhLY iAOxJnucQZuIHms6p0gntzT8Cjv4W0jbkjDSOhPpRjScRao29cQLqQkSuXr1kCBNLNcG xLZwutbEvVsE6vMFy/HO7kIhNkVpBBIjL5lDswgSfxMD/xtKAnHIyRDM+51qY9u7m3iJ rsMd7HkW6TCzt0nlHArVjI7uQiPF7G0Gx0RqAsmnfrCMai17KIiFlo6CbiBhlci45U0Z OfXZ21PtT/pPrqZz/Xjg/7agsHgueBJfAgQbVTlICdLdXT+1EouABi+nMJLD4VeA1+Uc AWWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vZNDhoyO9OSGjGjt0jxzNSm/X2FDlsf9i8lwwpI13L0=; b=hFXmBHiUAKkWFgkToM712N6BsgBEPAJS9Z5vBVqTyq1ppDGn7cNf4P+lc5u+29+Sbq VA5nLn4ibr6siDaNb41EeDuQC70zDLw8smkT1W3JUqE1qD9E9gDzvpg5JrfbOd1rrGtp BRuU49G+LpW5OXVKyNaKb8Hg9/FGdRTVYMWeFfcdB+4SnNOXPK3ZmO8k/ZU+3mfK/++c S5ldr1UzElbaJEwC/LBrNzclkQfDsfzQYVTvYULckH/8npTFu6iO0JhK+ppbcfNSrWq4 Jyn/bOQp221y71lDcgGpob2jz4/noBn5Zwp8BWxUa5o5jxfTLVsAGY7ECOUyY1F9A4/d 9UQQ== X-Gm-Message-State: ANoB5pm6hTcUgYCoDjWF5gwZAigg1h+cCszq+DEYG5LEek7UEOeAxsF4 20YhibEou6pT87Njmy8vE61DYJGhDcShHWWZTQ8= X-Google-Smtp-Source: AA0mqf5lSBVahWze4stPFnVDBsmCbkNmlqmvtFVWxn/f7LEECSnFueqwIpNHTiI/cn735hhYux8OZPodPh5IjDbbPRU= X-Received: by 2002:a17:902:ebc1:b0:187:af13:5212 with SMTP id p1-20020a170902ebc100b00187af135212mr25976577plg.72.1669477733031; Sat, 26 Nov 2022 07:48:53 -0800 (PST) MIME-Version: 1.0 References: <0613ff41dd219231948d4ac7da651e32a6a084a3.camel@redhat.com> In-Reply-To: From: Gavin Ray Date: Sat, 26 Nov 2022 10:48:44 -0500 Message-ID: Subject: Re: -fanalyzer: Questions on C vs CPP + use of GCC attr's like malloc()/access() To: Jonathan Wakely Cc: David Malcolm , "gcc@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: I was using if (fd != -1) and was still getting the warning which confused me My suggestion was maybe to add the exact condition the fd analyzer is looking for to the warning so that folks know how to fix it/trigger its 'true' branch. e.g. instead of: "fd may not be valid" Something like this, or thereabouts: "fd may not be valid (expecting fd >= 0)" On Sat, Nov 26, 2022 at 9:09 AM Jonathan Wakely wrote: > > > > On Fri, 25 Nov 2022, 18:55 Gavin Ray via Gcc, wrote: >> >> >> On a related note, the "fd" analyzers warn: "fd may not be valid" but don't >> clarify what "valid" means. > > > A valid file descriptor is one that was returned by the C library and refers to an open file. That's not something GCC defines. > >> >> I found the DOT diagrams in the analyzer source and it turns out that the key is >> to check "if (fd >= 0)". > > > The point is that the OS functions that return a new file descriptor return a negative value on error, so all valid file descriptors are non-negative. But not all non-negative integers are valid file descriptors. > > You should check for errors when calling open, dup2, socket etc. so you know whether it succeeded. > > >> Maybe this could be added to the "fd" analyzer >> warnings/info, too? > > > I don't think that's a good idea unless word carefully, it's not as simple as "test if it's non-negative". You should check for errors when using OS APIs, but that's always true, it's not difficult to the analyzer output. > > >> >> >> >>