Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GuiText manipulating underlying string #3

Open
V10lator opened this issue Apr 26, 2020 · 2 comments
Open

GuiText manipulating underlying string #3

V10lator opened this issue Apr 26, 2020 · 2 comments

Comments

@V10lator
Copy link

V10lator commented Apr 26, 2020

Code says more than thousand words:

// CODE:

	debugPrintf("Asked to add \"%s\"", str);
	
	GuiText *text = new GuiText(str);
	
	text->setPosition(row * 24, column * 24);
	text->setMaxWidth(tvWidth - (row * 24) - 100, GuiText::SCROLL_HORIZONTAL);
	
	debugPrintf("Adding \"%s\" at %d/%d", text->toUTF8().c_str(), row * 24, column * 24);
	
	tvWindow->append(text);

/* OUTPUT:
 * Asked to add "Could not download from"
 * Adding "Could not download fromw" at 0/0
 * Asked to add "http://enter.that.title.key/site/here"
 * Adding "http://enter.that.title.key/site/herezKH" at 0/24
 * Asked to add "Press (A) to enter a new URL"
 * Adding "Press (A) to enter a new URL" at 0/72
 * Asked to add "Press (B) to exit"
 * Adding "Press (B) to exit�" at 0/96
 */

So it added "w" at the end of the first string, "zKH" at the end of the second, correctly handled the third and added one unprintable char to the end of the fourth.

@V10lator
Copy link
Author

I looked a bit more into it and it seems the string return by text->toUTF8().c_str() is simply missing the null terminator.

@V10lator
Copy link
Author

V10lator commented Apr 26, 2020

First error found: https://github.com/wiiu-env/libgui/blob/master/source/gui/FreeTypeGX.cpp#L76 - if we look at http://man7.org/linux/man-pages/man3/mbstowcs.3.html we see that n should include the NULL character, so it should be

int32_t bt = mbstowcs(strWChar, strChar, strlen(strChar) + 1);

Also it seems the NULL character is discarded here: https://github.com/wiiu-env/libgui/blob/master/source/gui/FreeTypeGX.cpp#L115 (it stops the loop when strChar[i] is NULL which means it stops before it copies the NULL).

Please note that this was just found by overlooking the sourcecodes real quick. I did not test potential fixes in any way.

//EDIT: https://github.com/wiiu-env/libgui/blob/master/source/gui/FreeTypeGX.cpp#L77 is wrong, too. It should be if (bt < strlen(strChar)) { and you might want to add an extra check for -1 (error) before that.

V10lator added a commit to V10lator/libgui that referenced this issue Apr 26, 2020
Signed-off-by: Thomas Rohloff <[email protected]>
V10lator added a commit to V10lator/libgui that referenced this issue Apr 26, 2020
Signed-off-by: Thomas Rohloff <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant