<div dir="ltr">Hi Mike,<div><br></div><div>I earlier assumed that both the fallthrough were intentional and just made it evident by writing the comment. It was hence written actually for the code reader and not the static analyzer. The comment was similar in nature and style to existing No/1-byte/... data comments. <b>Incidentally, the comment satisfied the static analyzer as well. </b>It was beyond my expectation and I was pleasantly surprised too. Without digging deep into the particular code and to avoid any functional code change, I just thought that's it.</div><div><div><br></div><div>Your comment forced me to come back specifically to the particular code and to analyze it a bit more.</div><div><br></div><div>My analysis now says that the fallthrough doesn't serve any real functional purpose as there is absolutely no chance of <i><b>if</b></i> blocks of the fallthrough <i><b>case</b>(</i>s) being executed later and not executed in the original <b><i>case:</i></b> and hence the fallthrough if it happens still leads to execution of <i><b>return NULL;</b> </i>at the end of the function<i> </i>only. This is better communicated by adding <i><b><span class="gmail-il">break</span>;</b></i> statement in the original <i><b>case:</b></i> and in a way, one may agree with the static analyzer that there was a <span class="gmail-il">MISSING_BREAK</span>. I should hence follow it up with a v2 patch for this.</div></div><div><br></div><div>Ranbir Singh</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 5, 2023 at 12:17 AM Kinney, Michael D <<a href="mailto:michael.d.kinney@intel.com">michael.d.kinney@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I do not prefer special comments for one static analyzer.<br>
<br>
Is there an alternative design/implementation of this code<br>
to make it more readable and not trigger any static analysis<br>
false positives?<br>
<br>
Mike<br>
<br>
> -----Original Message-----<br>
> From: <a href="mailto:devel@edk2.groups.io" target="_blank">devel@edk2.groups.io</a> <<a href="mailto:devel@edk2.groups.io" target="_blank">devel@edk2.groups.io</a>> On Behalf Of Ranbir<br>
> Singh<br>
> Sent: Tuesday, October 3, 2023 10:48 PM<br>
> To: <a href="mailto:devel@edk2.groups.io" target="_blank">devel@edk2.groups.io</a>; <a href="mailto:rsingh@ventanamicro.com" target="_blank">rsingh@ventanamicro.com</a><br>
> Cc: Wu, Hao A <<a href="mailto:hao.a.wu@intel.com" target="_blank">hao.a.wu@intel.com</a>>; Ni, Ray <<a href="mailto:ray.ni@intel.com" target="_blank">ray.ni@intel.com</a>>;<br>
> Veeresh Sangolli <<a href="mailto:veeresh.sangolli@dellteam.com" target="_blank">veeresh.sangolli@dellteam.com</a>><br>
> Subject: [edk2-devel] [PATCH v1 2/2] MdeModulePkg/Bus/Usb/UsbMouseDxe:<br>
> Fix MISSING_BREAK Coverity issues<br>
> <br>
> From: Ranbir Singh <Ranbir.Singh3@Dell.com><br>
> <br>
> The function GetNextHidItem has a switch-case code in which the<br>
> case 1: falls through to case 2: and then case 2: falls through<br>
> to case 3: in the block.<br>
> <br>
> While this may be intentional, it is not evident to any general<br>
> code reader as well as any static analyzer tool. Just adding<br>
> <br>
>     // No break; here as this is an intentional fallthrough.<br>
> <br>
> as comment in between makes a reader as well as Coverity happy.<br>
> <br>
> REF: <a href="https://bugzilla.tianocore.org/show_bug.cgi?id=4222" rel="noreferrer" target="_blank">https://bugzilla.tianocore.org/show_bug.cgi?id=4222</a><br>
> <br>
> Cc: Hao A Wu <<a href="mailto:hao.a.wu@intel.com" target="_blank">hao.a.wu@intel.com</a>><br>
> Cc: Ray Ni <<a href="mailto:ray.ni@intel.com" target="_blank">ray.ni@intel.com</a>><br>
> Co-authored-by: Veeresh Sangolli <<a href="mailto:veeresh.sangolli@dellteam.com" target="_blank">veeresh.sangolli@dellteam.com</a>><br>
> Signed-off-by: Ranbir Singh <Ranbir.Singh3@Dell.com><br>
> Signed-off-by: Ranbir Singh <<a href="mailto:rsingh@ventanamicro.com" target="_blank">rsingh@ventanamicro.com</a>><br>
> ---<br>
>  MdeModulePkg/Bus/Usb/UsbMouseDxe/MouseHid.c | 8 ++++++++<br>
>  1 file changed, 8 insertions(+)<br>
> <br>
> diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/MouseHid.c<br>
> b/MdeModulePkg/Bus/Usb/UsbMouseDxe/MouseHid.c<br>
> index acc19acd98e0..bc9a4824208b 100644<br>
> --- a/MdeModulePkg/Bus/Usb/UsbMouseDxe/MouseHid.c<br>
> +++ b/MdeModulePkg/Bus/Usb/UsbMouseDxe/MouseHid.c<br>
> @@ -89,6 +89,10 @@ GetNextHidItem (<br>
>            return StartPos;<br>
> <br>
>          }<br>
> <br>
> <br>
> <br>
> +        //<br>
> <br>
> +        // No break; here as this is an intentional fallthrough<br>
> <br>
> +        //<br>
> <br>
> +<br>
> <br>
>        case 2:<br>
> <br>
>          //<br>
> <br>
>          // 2-byte data<br>
> <br>
> @@ -99,6 +103,10 @@ GetNextHidItem (<br>
>            return StartPos;<br>
> <br>
>          }<br>
> <br>
> <br>
> <br>
> +        //<br>
> <br>
> +        // No break; here as this is an intentional fallthrough<br>
> <br>
> +        //<br>
> <br>
> +<br>
> <br>
>        case 3:<br>
> <br>
>          //<br>
> <br>
>          // 4-byte data, adjust size<br>
> <br>
> --<br>
> 2.34.1<br>
> <br>
> <br>
> <br>
> -=-=-=-=-=-=<br>
> Groups.io Links: You receive all messages sent to this group.<br>
> View/Reply Online (#109309):<br>
> <a href="https://edk2.groups.io/g/devel/message/109309" rel="noreferrer" target="_blank">https://edk2.groups.io/g/devel/message/109309</a><br>
> Mute This Topic: <a href="https://groups.io/mt/101750274/1643496" rel="noreferrer" target="_blank">https://groups.io/mt/101750274/1643496</a><br>
> Group Owner: <a href="mailto:devel%2Bowner@edk2.groups.io" target="_blank">devel+owner@edk2.groups.io</a><br>
> Unsubscribe: <a href="https://edk2.groups.io/g/devel/unsub" rel="noreferrer" target="_blank">https://edk2.groups.io/g/devel/unsub</a><br>
> [<a href="mailto:michael.d.kinney@intel.com" target="_blank">michael.d.kinney@intel.com</a>]<br>
> -=-=-=-=-=-=<br>
> <br>
<br>
</blockquote></div>


<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>


Groups.io Links:<p>


  
    You receive all messages sent to this group.
  
  


<p>
<a target="_blank" href="https://edk2.groups.io/g/devel/message/109342">View/Reply Online (#109342)</a> |


  

|

  <a target="_blank" href="https://groups.io/mt/101750274/1813853">Mute This Topic</a>


| <a href="https://edk2.groups.io/g/devel/post">New Topic</a>

<br>




<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>