[haiku-commits] Re: haiku: hrev45988 - src/kits/interface headers

  • From: John Scipione <jscipione@xxxxxxxxx>
  • To: "haiku-commits@xxxxxxxxxxxxx" <haiku-commits@xxxxxxxxxxxxx>
  • Date: Sun, 25 Aug 2013 17:28:10 -0400

I

On Sunday, August 25, 2013, Axel Dörfler wrote:

> Am 25/08/2013 06:27, schrieb jscipione@xxxxxxxxx:
>
>> MenuField: Make sure input is a single byte
>>
> [...]
>
>>   void
>>   BMenuField::KeyDown(const char* bytes, int32 numBytes)
>>   {
>> +       if (numBytes != 1) {
>> +               BView::KeyDown(bytes, numBytes);
>> +               return;
>> +       }
>>
>
> This is completely useless and superfluous, please remove again


The BeBook says: "/Single-byte/ characters can be tested against ASCII codes
and these constants:" (emphasis mine) and then lists the constants used
here.

If you don't check that numBytes == 1 you could accidentally trigger the
action by passing in a multi-byte char who's first byte matches one of the
constants.

This might not be likely but in the interest of defensive programming I
wanted to prevent the problem from being able to present itself.

Am I being too cautious?


>  -       // Delete the menu window used by our submenus
>>         _DeleteMenuWindow();
>> +               // Delete the menu window used by our submenus
>>
>
> Please note that both styles may be used according to our coding style
> guide - in this case, there is only one following line, so the context is
> just the same (IOW no need to make those changes).
>

I realize that either style can be correct but I feel that in in this case
the comment is more clear indented on the next line. I'll be more
fastidious about changing comments in the future.

Thanks Axel.

Other related posts: