From 66a7ead100f7f41c14afc0ab528a46f928a9f3d8 Mon Sep 17 00:00:00 2001 From: Leo Koppel Date: Fri, 22 Jul 2016 12:32:02 -0400 Subject: Fix failure on loading empty file Re: brofield/simpleini#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. --- SimpleIni.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SimpleIni.h b/SimpleIni.h index aee5bee..b0cad33 100644 --- a/SimpleIni.h +++ b/SimpleIni.h @@ -1416,10 +1416,6 @@ CSimpleIniTempl::LoadData( { SI_CONVERTER converter(m_bStoreIsUtf8); - if (a_uDataLen == 0) { - return SI_OK; - } - // consume the UTF-8 BOM if it exists if (m_bStoreIsUtf8 && a_uDataLen >= 3) { if (memcmp(a_pData, SI_UTF8_SIGNATURE, 3) == 0) { @@ -1428,6 +1424,10 @@ CSimpleIniTempl::LoadData( } } + if (a_uDataLen == 0) { + return SI_OK; + } + // determine the length of the converted data size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen); if (uLen == (size_t)(-1)) { -- cgit v1.2.3