Message ID | 20200925073140.173394-9-colomar.6.4.3@gmail.com |
---|---|
State | Not applicable |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> 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 48190398640D; Fri, 25 Sep 2020 07:33:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48190398640D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601019188; bh=yMrVMcvcogTDH026oz+z3jHcV6Pa29K5G0BTDxtrSpc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=rYXreesecnt/v4jHpMGjx4EkMCdl83hM5BGU3OomJhzaVsEme0BqhKQ3z2dVlL1VZ AIdiFDeM3loN5OoEuxAbXCX+ZPtKQ+JS2u0mTBKWjWUr3oJkSUUiS09YkgAzm8+vaH FzkXsxSKMvIy9/QAg07aDT10EAhFP1M0IE24KdRc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by sourceware.org (Postfix) with ESMTPS id C6A7D3983A45 for <libc-alpha@sourceware.org>; Fri, 25 Sep 2020 07:33:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C6A7D3983A45 Received: by mail-wr1-x443.google.com with SMTP id z1so2441714wrt.3 for <libc-alpha@sourceware.org>; Fri, 25 Sep 2020 00:33:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yMrVMcvcogTDH026oz+z3jHcV6Pa29K5G0BTDxtrSpc=; b=BlYYK8SDKeNB4XuCDpPatNElNQqYntyzyQWBG0qW3Nh7yuKEQne9/pnWfXeVBQHLlL U05bw6cPfDYXY0YDDPomfb8xVgi/96XHOw/F5FdiWk03x9u/w8CeGGUtsGyz4LOOpqiU iCdJHOS+y/zzwYk3RoK/C0sB7ZbXvwGxfiFRDSokRGvsNi+GNIJV7IctQSj5NnySKnaP iFBUVTbPCGuZKQpfTWHzlHGkpCxYzLKr3Yk3hFqo+fV/4QZZbum01/mX+TymD+EvdXFH p5q0TkNp/wOjFP0G4AbAJ6mgBpcNAWTuJxOBM0MSTp5v9jLK3tmVlTo6sVXiM5/sx2UN hvJA== X-Gm-Message-State: AOAM530bVTSPPPg5FizXE0MQKzBIxD2tY4YLd99FCLy+tDTFVmgl1l22 RNnRvtgJAn1wSNfApPz9ZUKytkdqJhPArg== X-Google-Smtp-Source: ABdhPJyy7N91YJ7cLLGWkFDq3Ta6VxQLsIAiFNYwYnT4nJR/F+AqUUym3uhGLORuiwk1n2eCSE/nbA== X-Received: by 2002:adf:9bcf:: with SMTP id e15mr2855953wrc.93.1601019184714; Fri, 25 Sep 2020 00:33:04 -0700 (PDT) Received: from localhost.localdomain ([170.253.60.68]) by smtp.googlemail.com with ESMTPSA id n2sm1974314wma.29.2020.09.25.00.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 00:33:04 -0700 (PDT) To: mtk.manpages@gmail.com Subject: [PATCH 08/10] seccomp.2: Remove unneeded cast Date: Fri, 25 Sep 2020 09:31:39 +0200 Message-Id: <20200925073140.173394-9-colomar.6.4.3@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200925073140.173394-1-colomar.6.4.3@gmail.com> References: <20200925073140.173394-1-colomar.6.4.3@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Alejandro Colomar via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Alejandro Colomar <colomar.6.4.3@gmail.com> Cc: Alejandro Colomar <colomar.6.4.3@gmail.com>, linux-man@vger.kernel.org, libc-alpha@sourceware.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
Add types, and some fixes
|
|
Commit Message
Alejandro Colomar
Sept. 25, 2020, 7:31 a.m. UTC
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man2/seccomp.2 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Alex, On 9/25/20 9:31 AM, Alejandro Colomar wrote: > Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> > --- > man2/seccomp.2 | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/man2/seccomp.2 b/man2/seccomp.2 > index 58033da1c..d6b856c32 100644 > --- a/man2/seccomp.2 > +++ b/man2/seccomp.2 > @@ -1101,7 +1101,7 @@ install_filter(int syscall_nr, int t_arch, int f_errno) > }; > > struct sock_fprog prog = { > - .len = (unsigned short) (sizeof(filter) / sizeof(filter[0])), > + .len = sizeof(filter) / sizeof(filter[0]), > .filter = filter, > }; I have a small doubt about this change. With the change, there are no compilation warnings. But, if we change the code to something slightly different: [[ size_t x = (sizeof(filter) / sizeof(filter[0])); struct sock_fprog prog = { .len = x, .filter = filter, }; ]] The "cc -Wconversion" gives us the following warning: warning: conversion from ‘size_t’ {aka ‘long unsigned int’} to ‘short unsigned int’ may change value Presumably we don't get a warning for an assignment of the form .len = (sizeof(filter) / sizeof(filter[0])) because the compiler is smart enough to work out that the value of the constant expression is within the range of "unsigned short". Your thoughts? Thanks, Michael
On 2020-09-25 10:34, Michael Kerrisk (man-pages) wrote: > Hi Alex, > > On 9/25/20 9:31 AM, Alejandro Colomar wrote: >> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> >> --- >> man2/seccomp.2 | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/man2/seccomp.2 b/man2/seccomp.2 >> index 58033da1c..d6b856c32 100644 >> --- a/man2/seccomp.2 >> +++ b/man2/seccomp.2 >> @@ -1101,7 +1101,7 @@ install_filter(int syscall_nr, int t_arch, int f_errno) >> }; >> >> struct sock_fprog prog = { >> - .len = (unsigned short) (sizeof(filter) / sizeof(filter[0])), >> + .len = sizeof(filter) / sizeof(filter[0]), >> .filter = filter, >> }; > > I have a small doubt about this change. With the change, > there are no compilation warnings. > > But, if we change the code to something slightly different: > > [[ > size_t x = (sizeof(filter) / sizeof(filter[0])); > struct sock_fprog prog = { > .len = x, > .filter = filter, > }; > ]] > > The "cc -Wconversion" gives us the following warning: > > warning: conversion from ‘size_t’ {aka ‘long unsigned int’} > to ‘short unsigned int’ may change value > > Presumably we don't get a warning for an assignment of the form > > .len = (sizeof(filter) / sizeof(filter[0])) > > because the compiler is smart enough to work out that the > value of the constant expression is within the range of > "unsigned short". > > Your thoughts? Hi Michael, I'd say that the cast doesn't fix any problems at all. It silences a valid warning, and I'd use a pragma for that (to be more explicit about the intention of silencing a warning) if I do want -Wconversion enabled (which usually I don't want, because it's too noisy) and I'm sure that this won't overflow. I'd limit the use casts to only when I *really* need to. I guess that if you enable -O3, the warning will vanish again because the compiler will optimize away 'x' (but I didn't test). Thanks, Alex > > Thanks, > > Michael > >
On 9/25/20 10:42 AM, Alejandro Colomar wrote: > > > On 2020-09-25 10:34, Michael Kerrisk (man-pages) wrote: >> Hi Alex, >> >> On 9/25/20 9:31 AM, Alejandro Colomar wrote: >>> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> >>> --- >>> man2/seccomp.2 | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/man2/seccomp.2 b/man2/seccomp.2 >>> index 58033da1c..d6b856c32 100644 >>> --- a/man2/seccomp.2 >>> +++ b/man2/seccomp.2 >>> @@ -1101,7 +1101,7 @@ install_filter(int syscall_nr, int t_arch, int f_errno) >>> }; >>> >>> struct sock_fprog prog = { >>> - .len = (unsigned short) (sizeof(filter) / sizeof(filter[0])), >>> + .len = sizeof(filter) / sizeof(filter[0]), >>> .filter = filter, >>> }; >> >> I have a small doubt about this change. With the change, >> there are no compilation warnings. >> >> But, if we change the code to something slightly different: >> >> [[ >> size_t x = (sizeof(filter) / sizeof(filter[0])); >> struct sock_fprog prog = { >> .len = x, >> .filter = filter, >> }; >> ]] >> >> The "cc -Wconversion" gives us the following warning: >> >> warning: conversion from ‘size_t’ {aka ‘long unsigned int’} >> to ‘short unsigned int’ may change value >> >> Presumably we don't get a warning for an assignment of the form >> >> .len = (sizeof(filter) / sizeof(filter[0])) >> >> because the compiler is smart enough to work out that the >> value of the constant expression is within the range of >> "unsigned short". >> >> Your thoughts? > > Hi Michael, > > I'd say that the cast doesn't fix any problems at all. It silences a > valid warning, and I'd use a pragma for that (to be more explicit about > the intention of silencing a warning) if I do want -Wconversion enabled > (which usually I don't want, because it's too noisy) and I'm sure that > this won't overflow. I'd limit the use casts to only when I *really* > need to. > > I guess that if you enable -O3, the warning will vanish again because > the compiler will optimize away 'x' (but I didn't test). Fair enough! I've applied the patch. Thanks! Cheers, Michael
diff --git a/man2/seccomp.2 b/man2/seccomp.2 index 58033da1c..d6b856c32 100644 --- a/man2/seccomp.2 +++ b/man2/seccomp.2 @@ -1101,7 +1101,7 @@ install_filter(int syscall_nr, int t_arch, int f_errno) }; struct sock_fprog prog = { - .len = (unsigned short) (sizeof(filter) / sizeof(filter[0])), + .len = sizeof(filter) / sizeof(filter[0]), .filter = filter, };