STRTOWSTR - Memory access error | developer.brewmp.com STRTOWSTR - Memory access error | developer.brewmp.com

Developer

STRTOWSTR - Memory access error

Forums:

Hi,
I try to remove (';') from the contents in szBuf by following code. There is no error or warnings while compiling.But emulator shows
Application error Memory access STRTOWSTR .what could be the reason.any help is welcome.

AECHAR szText [150] = {0};
char szBuf[200];
char szBuffer[200] = {0};
int len;
char* tab;

len = STRLEN(szBuf);
{
while (len > 0)
{tab = STRCHR(szBuf, ';');
if (tab == 0)
{
break;

else
{
*tab++;
len= STRLEN(tab) - STRLEN(szBuf) - 1;
STR_TO_WSTR ((char*)szBuf,szText,len);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_BOLD,ChartoAECHAR(szBuf,pMe), -1, 0, 20, 0, IDF_TEXT_TRANSPARENT|IDF_ALIGN_CENTER);
} } }

STRTOWSTR function requires NULL terminated string. Your new string (after removal of ";") does not have null termination in your implementation. BREW helper functions are very error sensitive.
ruben

STRTOWSTR function requires NULL terminated string. Your new string (after removal of ";") does not have null termination in your implementation. BREW helper functions are very error sensitive.
ruben

Hi Ruben,
Thanks for ur immediate response. Could u pls tell me how to rectify that?

Hi Ruben,
Thanks for ur immediate response. Could u pls tell me how to rectify that?

What he is saying is that you need to rewrite your code to make sure that all the strings have a nul character terminator (0), either by adding a nul at the end of the string, or by being sure to preserve the nul as you alter the strings.

What he is saying is that you need to rewrite your code to make sure that all the strings have a nul character terminator (0), either by adding a nul at the end of the string, or by being sure to preserve the nul as you alter the strings.

AECHAR szText [150] = {0};
char szBuf[200];
char szBuffer[200] = {0};
int len;
char* tab;
len = STRLEN(szBuf);
Are you really using szBuf array without initialization?
Guess not... probably, you just didn't gave us all the code... :)
As ezavada said, in whatever place you fill that szBuf array - you should make it zero-ended...
Also, your szText array is smaller than szBuf... concider making it at least 200 elements too...

AECHAR szText [150] = {0};
char szBuf[200];
char szBuffer[200] = {0};
int len;
char* tab;
len = STRLEN(szBuf);
Are you really using szBuf array without initialization?
Guess not... probably, you just didn't gave us all the code... :)
As ezavada said, in whatever place you fill that szBuf array - you should make it zero-ended...
Also, your szText array is smaller than szBuf... concider making it at least 200 elements too...

thanks..i corrected and it works...

thanks..i corrected and it works...

Quote:*tab++;
This is incrementing the pointer, then dereferencing it for no reason.

Quote:*tab++;
This is incrementing the pointer, then dereferencing it for no reason.