From patchwork Tue May 19 22:12:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ihar Hrachyshka X-Patchwork-Id: 1293808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VKs4ZRp+; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49RVW70MKLz9sPK for ; Wed, 20 May 2020 08:12:51 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id C5DBA87779; Tue, 19 May 2020 22:12:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SVTeNkaujckd; Tue, 19 May 2020 22:12:47 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 9686F87729; Tue, 19 May 2020 22:12:47 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7780AC0881; Tue, 19 May 2020 22:12:47 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 569E1C0176 for ; Tue, 19 May 2020 22:12:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 432E28773D for ; Tue, 19 May 2020 22:12:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b1GTql0cy67r for ; Tue, 19 May 2020 22:12:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by whitealder.osuosl.org (Postfix) with ESMTPS id 8D43D87729 for ; Tue, 19 May 2020 22:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589926364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5O72HwJ159OPnE/p02L63J7YF6TAkFOWztD917I3JRs=; b=VKs4ZRp+aJEjEiTiRZbMVXOniq4lcwdPQrXBCj4m10y6v2JL6t/QVlcoQBqp130Z3dGHti C3fz0Z9HwCyToLwDJFgXztXmHUVOzMs+NVggIFVsVs4LQrDvUJCbnQkbnYTB71K10A1ELc qywSBCWdCp7TnCM8pq82tjhrf8BShDc= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-VRmnwcDoPwmKhqIUXE__Rw-1; Tue, 19 May 2020 18:12:42 -0400 X-MC-Unique: VRmnwcDoPwmKhqIUXE__Rw-1 Received: by mail-qk1-f199.google.com with SMTP id i17so1634640qka.4 for ; Tue, 19 May 2020 15:12:42 -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:mime-version :content-transfer-encoding; bh=5O72HwJ159OPnE/p02L63J7YF6TAkFOWztD917I3JRs=; b=tiHRC03mlDaSZsp+Uy1mQdVQyGj00u7hvL5vpEA08sFRj1wjcNdH7WdcyHnDgfDIJT htwpVAkFneEvxzOyvtwgREL+vhyLWjzPRK2UPP3a4yGU5eDF8vQhuovMeruQNAZiWB91 nTtbfW0uATcdCEQab8FKnhV3V0iY7sHEYPTzTSWdAkdpFYdHcKXjTBPCI0QQUrcgWsiB ncR/xA2/J42Mr25D2IXQIzsIJYPN7dzOG3eYzLdXSMTYE55IHkkfHxdyQ/G8B3zs1s2S WgWJaFnPklgHfDYpMOc9cFHAAXKwo3ydm8p1o8DEf84t/2yGfGD4YSwSt4e/9iG2OeZ5 IiTw== X-Gm-Message-State: AOAM530fLaFGUYTzxML8+kpBPPKcCLYVer1RLiUQjyB62Z0Vv8EZEeUu m4zjEYwX+xbPWrgZ3BTcpaTSccADZtJrwV1Wkn5YHCpVralj0g1qFrad0vQG2GzyrismUL2vRMo n2GFUOqztH/6h X-Received: by 2002:aed:366a:: with SMTP id e97mr2217422qtb.223.1589926361881; Tue, 19 May 2020 15:12:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyFPt0KbRV6XMmyZ8YbJs9KFPNwNC/r3e4VBqCo71lw/CCXGpwXXBP915umldBZNHxD9QCyw== X-Received: by 2002:aed:366a:: with SMTP id e97mr2217405qtb.223.1589926361631; Tue, 19 May 2020 15:12:41 -0700 (PDT) Received: from localhost.localdomain.com (cpe-172-73-180-250.carolina.res.rr.com. [172.73.180.250]) by smtp.googlemail.com with ESMTPSA id a62sm740470qkg.5.2020.05.19.15.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 15:12:40 -0700 (PDT) From: Ihar Hrachyshka To: dev@openvswitch.org Date: Tue, 19 May 2020 18:12:31 -0400 Message-Id: <20200519221231.168406-1-ihrachys@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn] Don't leak values other than 1 or 0 as bool return values on C89 compiler X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" While the code base makes use of bool type defined in C99, we don't assume C99 semantics for integer or pointer conversions to bool. (This is explained in the project coding style guide.) In C89 environments, it's important to normalize bool variables and returned values to 1 | 0 to avoid issues down the line. This patch updates all functions in the tree that return bool values and that could, in degenerate cases, return bools set to values different from 1 | 0. Signed-off-by: Ihar Hrachyshka Acked-by: Ankur Sharma --- controller/pinctrl.c | 6 +++--- ic/ovn-ic.c | 2 +- lib/ovn-util.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/controller/pinctrl.c b/controller/pinctrl.c index bea446c89..18b5c68dd 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -1674,7 +1674,7 @@ pinctrl_handle_tcp_reset(struct rconn *swconn, const struct flow *ip_flow, static bool is_dhcp_flags_broadcast(ovs_be16 flags) { - return flags & htons(DHCP_BROADCAST_FLAG); + return !!(flags & htons(DHCP_BROADCAST_FLAG)); } /* Called with in the pinctrl_handler thread context. */ @@ -4606,7 +4606,7 @@ pinctrl_ip_mcast_handle_igmp(struct ip_mcast_snoop *ip_ms, break; } ovs_rwlock_unlock(&ip_ms->ms->rwlock); - return group_change; + return !!group_change; } static bool @@ -4654,7 +4654,7 @@ pinctrl_ip_mcast_handle_mld(struct ip_mcast_snoop *ip_ms, break; } ovs_rwlock_unlock(&ip_ms->ms->rwlock); - return group_change; + return !!group_change; } static void diff --git a/ic/ovn-ic.c b/ic/ovn-ic.c index a1ed25623..9e7ceaf98 100644 --- a/ic/ovn-ic.c +++ b/ic/ovn-ic.c @@ -525,7 +525,7 @@ get_router_uuid_by_sb_pb(struct ic_context *ctx, { const struct sbrec_port_binding *router_pb = find_peer_port(ctx, sb_pb); if (!router_pb || !router_pb->datapath) { - return NULL; + return false; } return smap_get_uuid(&router_pb->datapath->external_ids, "logical-router", diff --git a/lib/ovn-util.c b/lib/ovn-util.c index 3482edb8d..10345b012 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -210,7 +210,7 @@ extract_ip_addresses(const char *address, struct lport_addresses *laddrs) { int ofs; if (parse_and_store_addresses(address, laddrs, &ofs, false)) { - return (laddrs->n_ipv4_addrs || laddrs->n_ipv6_addrs); + return !!(laddrs->n_ipv4_addrs || laddrs->n_ipv6_addrs); } return false;