Saturday, October 14, 2023
HomeiOS Developmentc++ - Bizarre bug with static array/strok on iOS 16

c++ – Bizarre bug with static array/strok on iOS 16


i am making an attempt to get enter textual content with SDL and cut up it, however character ‘3’ change into a “finish line” or one thing like that on iOS 16 for some causes!

                        static char szWorkSrc[1024] = {0};
            memset(szWorkSrc,0,sizeof(szWorkSrc));
            strcpy(szWorkSrc,lpszSrc);
 
                        static char szWorkToken[1024] = {0}; // bug right here
                        memset(szWorkToken,0,sizeof(szWorkToken));
            int nLine = 0;
 
            char* pszToken = strtok(szWorkSrc,"#");
 
            whereas(pszToken!=NULL&&nLine<nDstRow)
            {
                if(bSpaceInsert) // bSpaceInsert is fake right here
                {
                    sprintf(szWorkToken," %s",pszToken); // bug right here
                    nLine += CutText(szWorkToken,alpszDst+nLine*nDstColumn,nPixelPerLine,nDstRow-nLine,nDstColumn);
                }
                else
                {
                    nLine += CutText(pszToken,alpszDst+nLine*nDstColumn,nPixelPerLine,nDstRow-nLine,nDstColumn);
                }
                pszToken = strtok(NULL,"#");
            }
 
            return nLine;

there have 2 circumstances

  1. if i modified static char szWorkToken[1024] to char szWorkToken[1024] -> no bug
  2. if i eliminated codes inside if(bSpaceInsert) scope -> no bug

notice: bSpaceInsert is fake, sprintf by no means known as

instance enter “1234#5678”
end result

[0] "12"
[1] "4"
[2] "5678"

nevertheless it must be

[0]"1234"
[1]"4568"

i examined on iOS 15 with the identical construct, android, home windows do not have that bug

am i lacking one thing right here or it is a os bug?

thanks!



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments