[haiku-commits] Re: r40826 - haiku/trunk/src/apps/screenshot

  • From: Philippe Saint-Pierre <stpere@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 6 Mar 2011 09:17:58 -0500

Hi Axel!

On Sun, Mar 6, 2011 at 5:16 AM, Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> wrote:

> stpere@xxxxxxxxx wrote:
> > +             case B_REFS_RECEIVED:
> > +             {
> > +                     entry_ref ref;
> > +                     if (message->FindRef("refs", &ref) == B_OK) {
> > +                             BEntry entry(&ref, true);
> > +                             BPath path;
> > +                             entry.GetPath(&path);
>
> Error checks! The link you might resolve can be as invalid as the
> entry_ref you got in the first place.


Sorry about that!  I'm a bit rusty.. (if that can be used as an excuse..)

> +                             BString label(path.Path());
> > +                             _AddItemToPathMenu(path.Path(), label, 3,
> true);
>
> Looks like a bad API decision to use BStrings here.


It seems the reason it's been chosen is to use BView::TruncateString()
later.  Would it be best to translate it to BString only at this step or to
use BStrings from the start of the process.. ?


> > +     for (int32 i = fOutputPathMenu->CountItems(); i > 0; --i) {
> > +             BMenuItem* menuItem = fOutputPathMenu->ItemAt(i - 1);
> > +             BMessage* message = menuItem->Message();
> > +             const char* pathFromItem;
> > +             if (message != NULL && message->what == kLocationChanged) {
> > +                     if (message->FindString("path", &pathFromItem) ==
> B_OK) {
> > +                             if (!strcmp(path, pathFromItem)) {
>
> This desperately cries for the && operator :-)
>

Ugh.. no further comments :P sorry about this mess :P

Philippe 'stpere'

Other related posts: