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

LoadFile() fails on empty file with Unicode, UTF-8 #19

Closed
leokoppel opened this issue Jul 22, 2016 · 1 comment
Closed

LoadFile() fails on empty file with Unicode, UTF-8 #19

leokoppel opened this issue Jul 22, 2016 · 1 comment

Comments

@leokoppel
Copy link
Contributor

Ran into this when trying a simple "will this compile and run?" without anything in the ini file. SI_CONVERT_WIN32 is set.

const PWSTR filename= L"empty.ini";

CSimpleIniW ini(true, false, false);

// Write empty file
SI_Error retval = ini.SaveFile(filename);
assert(retval == SI_OK);

// Attempt to load empty file - fails
retval = ini.LoadFile(filename);
assert(retval == SI_FAIL);

The problem seems to be in the Windows version of SizeFromStore for that combination of flags. It calls MultiByteToWideChar with a cbMultiByte of 0, which fails.

I'll see if there's a safe simple fix but I'm not familiar with these character set functions. Otherwise, this may at least help someone else who runs into the issue.

leokoppel added a commit to leokoppel/simpleini that referenced this issue Jul 22, 2016
Re: brofield#19

The Windows, Unicode, UTF-8 version of SizeFromStore returns failure when
given zero-length data. Fix by moving a_uDataLen == 0 check to after the
UTF-8 BOM removal.
@brofield
Copy link
Owner

Thanks for your patch.

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

2 participants