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

String truncation not working properly with new INI parser #485

Closed
NovaRain opened this issue Jun 26, 2023 · 0 comments
Closed

String truncation not working properly with new INI parser #485

NovaRain opened this issue Jun 26, 2023 · 0 comments
Assignees
Labels

Comments

@NovaRain
Copy link
Collaborator

Taking IniConfigFolder option for example:

// in ScriptExtender.cpp
std::string ScriptExtender::iniConfigFolder;

iniConfigFolder = IniReader::GetConfigString("Scripts", "IniConfigFolder", "", 64);
size_t len = iniConfigFolder.length();
dlog_f("IniConfigFolder: %s, len: %d\n", DL_MAIN, iniConfigFolder.c_str(), len); // for testing

With IniConfigFolder=mods\thisismysuperawesomemod\withlotsofqolfeatures\youshouldreallycheckit in ddraw.ini, before the result string was truncated as it should be:

IniConfigFolder: mods\thisismysuperawesomemod\withlotsofqolfeatures\youshouldrea, len: 63

But now with new INI parser it doesn't get truncated at all:

IniConfigFolder: mods\thisismysuperawesomemod\withlotsofqolfeatures\youshouldreallycheckit, len: 73

If changing ScriptExtender::iniConfigFolder to a char array:

char ScriptExtender::iniConfigFolder[64];

size_t len = IniReader::GetConfigString("Scripts", "IniConfigFolder", "", iniConfigFolder, 64);
dlog_f("IniConfigFolder: %s, len: %d\n", DL_MAIN, iniConfigFolder.c_str(), len); // for testing

The result string is truncated correctly, but the returned size_t value is still "full length":

IniConfigFolder: mods\thisismysuperawesomemod\withlotsofqolfeatures\youshouldrea, len: 73

For GetString() variant returning size_t value, I think the mismatch can be fixed by return strlen(buf); instead of return value->size();. For the variant returning std:string, I can only think of this:

if (value->length() >= bufSize) {
	std::string truncVal(*value);
	truncVal.resize(bufSize - 1);
	return truncVal;
}
@NovaRain NovaRain added the bug label Jun 26, 2023
phobos2077 added a commit that referenced this issue Jun 26, 2023
- Fix return value of getString with buffer argument
- Increase max line length to 2048
@NovaRain NovaRain closed this as completed Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants