Skip to content

Commit

Permalink
Use mbstowcs_s on Windows to avoid warnings about insecure functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
brofield committed Dec 1, 2024
1 parent 72c170a commit cccd82f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LICENCE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2006-2022 Brodie Thiesfield
Copyright (c) 2006-2024 Brodie Thiesfield

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
21 changes: 17 additions & 4 deletions SimpleIni.h
Original file line number Diff line number Diff line change
Expand Up @@ -3063,14 +3063,18 @@ class SI_ConvertW {
return a_uInputDataLen;
}

#if defined(SI_NO_MBSTOWCS_NULL) || (!defined(_MSC_VER) && !defined(_linux))
// get the required buffer size
#if defined(_MSC_VER)
size_t uBufSiz;
errno_t e = mbstowcs_s(&uBufSiz, NULL, 0, a_pInputData, a_uInputDataLen);
return (e == 0) ? uBufSiz : (size_t) -1;
#elif !defined(SI_NO_MBSTOWCS_NULL)
return mbstowcs(NULL, a_pInputData, a_uInputDataLen);
#else
// fall back processing for platforms that don't support a NULL dest to mbstowcs
// worst case scenario is 1:1, this will be a sufficient buffer size
(void)a_pInputData;
return a_uInputDataLen;
#else
// get the actual required buffer size
return mbstowcs(NULL, a_pInputData, a_uInputDataLen);
#endif
}

Expand Down Expand Up @@ -3119,9 +3123,18 @@ class SI_ConvertW {
}

// convert to wchar_t
#if defined(_MSC_VER)
size_t uBufSiz;
errno_t e = mbstowcs_s(&uBufSiz,
a_pOutputData, a_uOutputDataSize,
a_pInputData, a_uInputDataLen);
(void)uBufSiz;
return (e == 0);
#else
size_t retval = mbstowcs(a_pOutputData,
a_pInputData, a_uOutputDataSize);
return retval != (size_t)(-1);
#endif
}

/** Calculate the number of char required by the storage format of this
Expand Down

0 comments on commit cccd82f

Please sign in to comment.