Patrick Ouellet wrote in message <17299@palm-dev-forum>...
>
>Ok I had the "MyApps"  1.0 has just read
>directly from NULL (memory location zero)
>
>I know what it mean, but I want to know to to solve this problem...
>What am I doing wrong.
>
>These are my global variable:
>
>UInt CurChar = 0;
>CharPtr TempCode[5];

As someone else pointed out, this should be

Char TempCode[5];

>
>This is my code:
>
>static Boolean MainFormHandleEvent(EventPtr eventP)
>{
>    Boolean handled = false;
>    FormPtr frmP;
>
> switch (eventP->eType)
> {
>  case ctlSelectEvent:
>  {
>   switch(eventP->data.ctlEnter.controlID)
>   {
>    case MainBtnStarButton:
>     FrmCustomAlert(TestAlertAlert, *TempCode, NULL, NULL);

You do -not- want to dereference TempCode here (or
many other places in your code).  Get rid of the *.

>     break;
>
>    case MainBtnToeButton:
>     StrCopy(*TempCode, "");

again, get rid of the * ... (and assume the same wherever else you have
*TempCode below)

>     CurChar = 0;
>     break;
>
>    case MainBtn0Button:
>     StrCat(*TempCode, "0");
>     CurChar++;
>     break;
>
>    case MainBtn1Button:
>     StrCat(*TempCode, "1");
>     CurChar++;
>     break;
>
>    case MainBtn2Button:
>     StrCat(*TempCode, "2");
>     CurChar++;
>     break;
>
>    case MainBtn3Button:
>     StrCat(*TempCode, "3");
>     CurChar++;
>     break;
>
>    case MainBtn4Button:
>     StrCat(*TempCode, "4");
>     CurChar++;
>     break;
>   }
>
>   handled = true;
>
>
>   if (CurChar == 4)
>   {
>    FrmCustomAlert(TestAlertAlert, "4 Char", NULL, NULL);
>   }


This is nice, but I see nothing that prevents anybody pressing
another button, raising CurChar > 4, and attempting to append
additional chars to TempCode beyond the memory you have
allocated for it.  You should certainly have such protections
in place to prevent writing off the end of TempCode.

>   break;
>  }
>  case menuEvent:
>   return MainFormDoCommand(eventP->data.menu.itemID);
>
>  case frmOpenEvent:
>   frmP = FrmGetActiveForm();
>   MainFormInit( frmP);
>   FrmDrawForm ( frmP);
>   handled = true;
>   break;
>
>  default:
>   break;
>
> }
> return handled;
>}
>
>
>
>
>



--
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi/sec: not just a good idea, it's the LAW!




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to