From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.groups.io with SMTP id smtpd.web10.1698.1571046416085276398 for ; Mon, 14 Oct 2019 02:46:56 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: philmd@redhat.com) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75EA9C04AC50 for ; Mon, 14 Oct 2019 09:46:55 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id w10so8262690wrl.5 for ; Mon, 14 Oct 2019 02:46:55 -0700 (PDT) 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=5OQIEMjtsGFPW8xpAhn+NNEBw4seOk8fiYMHdTl63lY=; b=dqzRFCt73ykQud6O7K59kkPp54sVoLW1IgaP5RG1g7hCLdoZUpGWrYcsFTa7rZ45dP NB0xoIX8MEUoETjMUzRHTm2MtcCo2SdamRJbUoEHxYqvLCTILDmxK4UgYVKI/94RV8Xg hjq11fRvU4FHBzrbeCHMHwiD65um48Qs7CkRsTA3VN0/nP6W7nmJEmeURYl88L0h6och J/QOpXbsC2R6QEjBrBaufX1J0qu/PALmRKJzH0N/Tse3fw9uXNLcAgEp/8HuRZxPpKkZ zw11VRPmjo6pvrFzE/RMYL0wmivzwU1lJPdEKJvx0npUzK4eEFmf4ngfwM2LXbSPNxhk TdMg== X-Gm-Message-State: APjAAAU/xftLBEkd4ri58kqzwuTyZS18pX45oYHoFTSWF8lAdNvoL8Cb Qm0LdPdJ7iQmNyu415QbamVuqVwxoqEh1/Z35g/Rsobj7w2N1Gwb7fqXvA0zsvVkiiw7OLnkSqu vwgXCq8MoeBiVMQ== X-Received: by 2002:adf:db0e:: with SMTP id s14mr26203306wri.341.1571046414185; Mon, 14 Oct 2019 02:46:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyiulBAS1wZ0cM99SYUwJLZ0qIMd4m1NxZkhBuE+wC+9VAYLwPdYOkdQDn6Ofi6LBnQfYzMw== X-Received: by 2002:adf:db0e:: with SMTP id s14mr26203294wri.341.1571046414018; Mon, 14 Oct 2019 02:46:54 -0700 (PDT) Received: from [192.168.50.32] (243.red-88-26-246.staticip.rima-tde.net. [88.26.246.243]) by smtp.gmail.com with ESMTPSA id n14sm14989665wro.83.2019.10.14.02.46.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Oct 2019 02:46:53 -0700 (PDT) Subject: Re: [edk2-devel] [PATCH] NetworkPkg/DxeNetLib: Change the order of conditions in IF statement To: devel@edk2.groups.io, shenglei.zhang@intel.com Cc: Siyuan Fu , Jiaxin Wu , Laszlo Ersek References: <20191012074302.11928-1-shenglei.zhang@intel.com> <20191012074302.11928-2-shenglei.zhang@intel.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: Date: Mon, 14 Oct 2019 11:46:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20191012074302.11928-2-shenglei.zhang@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Hi Zhang, On 10/12/19 9:43 AM, Zhang, Shenglei wrote: > The condition, NET_HEADSPACE(&(Nbuf->BlockOp[Index])) < Len, is meaningless > if Index < 0. So 'Index < 0' should be performed first in the if statement. > > Cc: Siyuan Fu > Cc: Jiaxin Wu > Signed-off-by: Shenglei Zhang > --- > NetworkPkg/Library/DxeNetLib/NetBuffer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/NetworkPkg/Library/DxeNetLib/NetBuffer.c b/NetworkPkg/Library/DxeNetLib/NetBuffer.c > index 2408e9a10456..a35e67aa1f6c 100644 > --- a/NetworkPkg/Library/DxeNetLib/NetBuffer.c > +++ b/NetworkPkg/Library/DxeNetLib/NetBuffer.c > @@ -1063,7 +1063,7 @@ NetbufAllocSpace ( > } else { > NetbufGetByte (Nbuf, 0, &Index); > > - if ((NET_HEADSPACE(&(Nbuf->BlockOp[Index])) < Len) && (Index > 0)) { > + if ((Index > 0) && (NET_HEADSPACE(&(Nbuf->BlockOp[Index])) < Len)) { I'm not sure this is correct. Index is unsigned, so it won't be negative. NetbufGetByte() can set Index=0. With your change this case is not covered anymore. Maybe your tool is unhappy because the return value of NetbufGetByte() isn't checked? > Index--; > } > } >