From 50284d3a634eb1173abac87e12d3c3addd8d3775 Mon Sep 17 00:00:00 2001 From: Brodie Thiesfield Date: Fri, 1 Feb 2013 01:44:24 +0000 Subject: Fix for issue 7: mbstowcs is used in non-standard way, thus casing crash with gcc --- SimpleIni.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/SimpleIni.h b/SimpleIni.h index 04e2b48..534e190 100644 --- a/SimpleIni.h +++ b/SimpleIni.h @@ -2836,9 +2836,15 @@ public: // the source text. return a_uInputDataLen; } - else { - return mbstowcs(NULL, a_pInputData, a_uInputDataLen); - } + +#if !defined(_WIN32) && !defined(_linux) + // fall back processing for platforms that don't support C99 usage of mbstowcs + // worst case scenario is 1:1, this should be a sufficient buffer size + return a_uInputDataLen; +#else + // get the actual required buffer size + return mbstowcs(NULL, a_pInputData, a_uInputDataLen); +#endif } /** Convert the input string from the storage format to SI_CHAR. @@ -2884,11 +2890,11 @@ public: } return retval == conversionOK; } - else { - size_t retval = mbstowcs(a_pOutputData, - a_pInputData, a_uOutputDataSize); - return retval != (size_t)(-1); - } + + // convert to wchar_t + size_t retval = mbstowcs(a_pOutputData, + a_pInputData, a_uOutputDataSize); + return retval != (size_t)(-1); } /** Calculate the number of char required by the storage format of this -- cgit v1.2.3