title: Encoded text conversion always fails
body: <pre><code>int conv_utf8_to_ucs2(const char* src, size_t len)
  {
      iconv_t cb = iconv_open("UTF-16", "UTF-8");
      if (cb == (iconv_t)(-1))
          return 0;
  
      uint16_t* outBuff = new uint16_t[len + 1];
      char* pout = (char*)outBuff;
      size_t inRemains = len;
      size_t outRemains = len * sizeof(uint16_t);
  
      printf("inRemains:%d outRemains:%d\n", (int)inRemains, (int)outRemains);
  
      size_t cvtlen = iconv(cb, &amp;src, (size_t*)&amp;inRemains, (char**)&amp;pout, (size_t*)&amp;outRemains);
      if (cvtlen == (size_t)-1) {
          //CONVERSION ALWAYS FAILS
          goto out;
      }
      *pout = 0;
  
      printf("inRemains:%d outRemains:%d cvtlen:%d\n", (int)inRemains, (int)outRemains, (int)cvtlen);
  
      for (int i = 0; (i &lt; len) &amp;&amp; outBuff[i]; i++)
          printf("0x%04x\n", outBuff[i]);
  
  out:
      if (outBuff)
          delete[] outBuff;
      iconv_close(cb);
  
      return 0;
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
       char utf8_str[] = "안녕 세상아?";
       int len = strlen(utf8_str);
  
       conv_utf8_to_ucs2(utf8_str, len);
  
       return 0;
  }
  </code></pre>
  
  <p>I have this tiny program to convert a string of UTF8 to UTF16, but <code>iconv</code> function always returns -1. I debug to go into its implementation but could not find any hint. Could someone offer an insight into this libiconv usage ?                                                                                 </p>