Merge pull request #164 from libtom/pr/wchar-warnings-visual-studio-2008

fix wchar_t related warnings on Visual Studio 2008
This commit is contained in:
karel-m 2017-03-09 21:01:26 +01:00 committed by GitHub
commit 44f29d895c
3 changed files with 13 additions and 4 deletions

View File

@ -612,10 +612,17 @@ int der_printable_char_encode(int c);
int der_printable_value_decode(int v);
/* UTF-8 */
#if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR)
#if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(__WCHAR_MAX__) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR)
#include <wchar.h>
#if defined(__WCHAR_MAX__)
#define LTC_WCHAR_MAX __WCHAR_MAX__
#elif defined(WCHAR_MAX)
#define LTC_WCHAR_MAX WCHAR_MAX
#endif
/* please note that it might happen that LTC_WCHAR_MAX is undefined */
#else
typedef ulong32 wchar_t;
#define LTC_WCHAR_MAX 0xFFFFFFFF
#endif
int der_encode_utf8_string(const wchar_t *in, unsigned long inlen,

View File

@ -87,7 +87,9 @@ int der_encode_utf8_string(const wchar_t *in, unsigned long inlen,
case 1: out[x++] = (unsigned char)in[y]; break;
case 2: out[x++] = 0xC0 | ((in[y] >> 6) & 0x1F); out[x++] = 0x80 | (in[y] & 0x3F); break;
case 3: out[x++] = 0xE0 | ((in[y] >> 12) & 0x0F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break;
#if !defined(LTC_WCHAR_MAX) || LTC_WCHAR_MAX > 0xFFFF
case 4: out[x++] = 0xF0 | ((in[y] >> 18) & 0x07); out[x++] = 0x80 | ((in[y] >> 12) & 0x3F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break;
#endif
}
}

View File

@ -27,7 +27,7 @@ unsigned long der_utf8_charsize(const wchar_t c)
return 1;
} else if (c <= 0x7FF) {
return 2;
#if __WCHAR_MAX__ == 0xFFFF
#if LTC_WCHAR_MAX == 0xFFFF
} else {
return 3;
}
@ -48,10 +48,10 @@ unsigned long der_utf8_charsize(const wchar_t c)
int der_utf8_valid_char(const wchar_t c)
{
LTC_UNUSED_PARAM(c);
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ > 0xFFFF
#if !defined(LTC_WCHAR_MAX) || LTC_WCHAR_MAX > 0xFFFF
if (c > 0x10FFFF) return 0;
#endif
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ != 0xFFFF && __WCHAR_MAX__ != 0xFFFFFFFF
#if LTC_WCHAR_MAX != 0xFFFF && LTC_WCHAR_MAX != 0xFFFFFFFF
if (c < 0) return 0;
#endif
return 1;