]> granicus.if.org Git - taglib/commitdiff
Correctly initialize std::mbstate_t.
authorRaphael Kubo da Costa <rakuco@FreeBSD.org>
Mon, 29 Apr 2013 20:56:07 +0000 (23:56 +0300)
committerRaphael Kubo da Costa <rakuco@FreeBSD.org>
Mon, 29 Apr 2013 20:56:07 +0000 (23:56 +0300)
mbstate_t is an opaque type that is often a union or a struct, so setting it
directly to 0 is incorrect and causes build failures with some compilers
such as clang.

taglib/toolkit/tstring.cpp

index 392f32ed711e1ff4724d58f1ebd03f34c4fcfd0a..eaf5291eb21aa1f5612059dff9ec4e79f88dbea8 100644 (file)
@@ -78,9 +78,10 @@ namespace
     char *dstBegin = dst;
     char *dstEnd   = dstBegin + dstLength;
 
-    std::mbstate_t st = 0;
+    std::mbstate_t st;
     const wchar_t *source;
     char *target;
+    memset(&st, 0, sizeof(st));
     std::codecvt_base::result result = utf8_utf16_t().out(
       st, srcBegin, srcEnd, source, dstBegin, dstEnd, target);
 
@@ -123,9 +124,10 @@ namespace
     wchar_t *dstBegin = dst;
     wchar_t *dstEnd   = dstBegin + dstLength;
 
-    std::mbstate_t st = 0;
+    std::mbstate_t st;
     const char *source;
     wchar_t *target;
+    memset(&st, 0, sizeof(st));
     std::codecvt_base::result result = utf8_utf16_t().in(
       st, srcBegin, srcEnd, source, dstBegin, dstEnd, target);