0

I'm adapting the example of Forms Management here and found AppLog to mangle my reported strings strangely.

void
MyFormsApp::OnUserEventReceivedN (RequestId requestId, IList *pArgs)
{
    AppLog("OnUEveRxdNb, beginning");
    if(!pArgs) {
        AppLog("OnUserEventReceivedN, null List");
        return;
    }

    if(requestId==TabsForm::TABS_SWITCH_CALL)
    {
        Integer * tabindex = static_cast<Integer *>(pArgs->GetAt(0));
        MyLog(L"OnUEveRxdN, formID : ", formID->ToInt());
        //MyLog(L"OnUserEventReceivedN, formID : ", formID->ToInt());
        if(tabindex)
        {
            switch(tabindex->ToInt())
            {
            case TabsForm::SEARCH_TAB:
                frame_->SetCurrentForm(*search_form_);
                search_form_->RequestRedraw(true);
                break;
            case TabsForm::RESULTS_TAB:
                frame_->SetCurrentForm(*results_form_);
                results_form_->RequestRedraw(true);
                break;
            case TabsForm::CONTENTS_TAB:
                frame_->SetCurrentForm(*contents_form_);
                contents_form_->RequestRedraw(true);
                break;
            }
        }
    }
    pArgs->RemoveAll(true);
    delete pArgs;
} //closebracket

MyLog is

void MyLog(const String &badaStr) {
    char *natStr = new char[badaStr.GetLength()];
    for (int i = 0; i < badaStr.GetLength(); ++i)
        natStr[i] = badaStr[i];
    AppLog(natStr);
    delete[] natStr;
}

void MyLog(const mchar *pValue, const int int_param) {
    String str(pValue);
    result r = str.Append(int_param);
    MyLog(str);
}

void MyLog(const char *pValue, const int int_param) {
    String str(pValue);
    result r = str.Append(int_param);
    MyLog(str);
}

If you see where I've got the two calls to it the second was commented out because it appends garbage to the end of my string. I call these functions from various other places in my application without trouble but here the string must be truncated. It's not a total char count per function either because replacing the first AppLog with AppLog("BadaReader::OnUserEventReceivedN, beginning"); makes no difference.

Can anyone spot my mistake or is Bada 2.0.2 known for this kind of random glitch?

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
John
  • 6,433
  • 7
  • 47
  • 82
  • I've recreated this behaviour in another method. I think it might have something to do with subsequent exceptions overwriting some of the buffer set aside for `AppLog` because when I last encountered this problem, it was in conjunction, ie before an exception was, err, caused. – John Dec 02 '11 at 19:59
  • Solved: `natStr[badaStr.GetLength()] = '\0';` missing from where I inlined that into `MyLog` – John Dec 04 '11 at 00:23

1 Answers1

1

Why do you need separate logging functions? bada has three AppLog Macros.Yoc can use them. Also, if you need to print String do,

AppLog("Log Statement %s",string_name->GetPointer());

string_name->GetPointer() returns const char*.

Yogi
  • 1,035
  • 2
  • 13
  • 39
  • Ah, so that's how you use %s/%S. I've now found where it says `AppLog` has `printf` functionality but `printf` doesn't know about `Osp::Base::String`. BTW it _is_ `%S` with `GetPointer()` and not `%s`. – John Dec 05 '11 at 22:30