Opened 13 years ago

Last modified 13 years ago

#7701 closed bug

BMessage::FindString() behaves differently from BeOS's when field does not exist — at Initial Version

Reported by: ttcoder Owned by: axeld
Priority: normal Milestone: R1
Component: Kits/Application Kit Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

m.FindString("myfield", &s) will leave 's' untouched if "myfield" is not part of 'm'. Expected behavior: in addition to returning an error code, it should also reset the string, much like m.FindInt32( "myfield", &i ) reset i to zero.

Looking at the BeBook I see it does not lean much one way or the other, so I'm tentatively categorizing this as a 'bug' only insofar as it differs from the BeOS behavior I've relied on in the past: the behavior under Haiku breaks my app (though the workaround is straight-forward). Under BeOS I could do this:

int main()
{
    BMessage m;
    m.AddString( "one", "value" );

    BString s;

    m.FindString( "one", &s );
    puts( s.String() );
    m.FindString( "two", &s );
    puts( s.String() );
}

and correctly get a blank output at the second puts() due to the absent field.

In case this sticks, here's a possible one-liner 'patch': in Message.cpp line 2635:

           const char *cstr = NULL;
	    status_t error = FindString(name, index, &cstr);
	    if (error < B_OK)
	    {
	        string->Truncate(0);  // <-- here it is, a reset that's fairly fast (Truncate() in "lazy" mode)
	        return error;
	    }
	

Change History (0)

Note: See TracTickets for help on using tickets.