]> sourceware.org Git - newlib-cygwin.git/commitdiff
Fix length returned from sys_cp_wcstombs in case nwc > # of wchars
authorCorinna Vinschen <corinna@vinschen.de>
Thu, 22 Oct 2015 12:22:07 +0000 (14:22 +0200)
committerCorinna Vinschen <corinna@vinschen.de>
Thu, 22 Oct 2015 15:32:12 +0000 (17:32 +0200)
* strfuncs.cc (sys_cp_wcstombs): Always return number of multibytes
without trailing NUL as the documentation implies.  Throughout Cygwin,
fix usage to align to this pattern.
* fhandler_process.cc (format_process_winexename): Drop trailing NUL
and LF from output.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/ChangeLog
winsup/cygwin/dcrt0.cc
winsup/cygwin/environ.cc
winsup/cygwin/fhandler_process.cc
winsup/cygwin/fhandler_registry.cc
winsup/cygwin/net.cc
winsup/cygwin/path.cc
winsup/cygwin/strfuncs.cc
winsup/cygwin/uinfo.cc

index 41a02efe91f93812fd13ab4decebba737f9a859b..d3a47a4f215432b3851c560c423d9941fb8985e8 100644 (file)
@@ -1,3 +1,11 @@
+2015-10-22  Corinna Vinschen  <corinna@vinschen.de>
+
+       * strfuncs.cc (sys_cp_wcstombs): Always return number of multibytes
+       without trailing NUL as the documentation implies.  Throughout Cygwin,
+       fix usage to align to this pattern.
+       * fhandler_process.cc (format_process_winexename): Drop trailing NUL
+       and LF from output.
+
 2015-10-21  Corinna Vinschen  <corinna@vinschen.de>
 
        * thread.cc (pthread_getattr_np): Fix memory leak, remove usage of
index 8ac7f4cd5a21da16161b41d61dccf76b93564c2b..3d293f6092288fef952504ccba74a4c685d0f073 100644 (file)
@@ -952,7 +952,7 @@ dll_crt0_1 (void *)
   if (!__argc)
     {
       PWCHAR wline = GetCommandLineW ();
-      size_t size = sys_wcstombs (NULL, 0, wline);
+      size_t size = sys_wcstombs (NULL, 0, wline) + 1;
       char *line = (char *) alloca (size);
       sys_wcstombs (line, size, wline);
 
index 8f25fb19ea3b6bfece5badca62f53d829c29b2ae..ab6511be1327018b60253fe375e4acfd274597e9 100644 (file)
@@ -895,7 +895,7 @@ getwinenveq (const char *name, size_t namelen, int x)
   int totlen = GetEnvironmentVariableW (name0, valbuf, 32768);
   if (totlen > 0)
     {
-      totlen = sys_wcstombs (NULL, 0, valbuf);
+      totlen = sys_wcstombs (NULL, 0, valbuf) + 1;
       if (x == HEAP_1_STR)
        totlen += namelen;
       else
index d3ee874cdec050a1e768b35a92202082026d1d86..516fbe32ce46f5ddb319e66aa2b9bd1788fe1e1b 100644 (file)
@@ -568,9 +568,9 @@ format_process_winexename (void *data, char *&destbuf)
   _pinfo *p = (_pinfo *) data;
   size_t len = sys_wcstombs (NULL, 0, p->progname);
   destbuf = (char *) crealloc_abort (destbuf, len + 1);
-  sys_wcstombs (destbuf, len, p->progname);
-  destbuf[len] = '\n';
-  return len + 1;
+  /* With trailing \0 for backward compat reasons. */
+  sys_wcstombs (destbuf, len + 1, p->progname);
+  return len;
 }
 
 struct heap_info
index fbdb4406554b49c93d50fceb367631affda05d4a..666363725f46636b3315a306df974753f23e04e2 100644 (file)
@@ -286,7 +286,7 @@ multi_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc)
 
   while (nwc)
     {
-      siz = sys_wcstombs (dst, len, src, nwc);
+      siz = sys_wcstombs (dst, len, src, nwc) + 1;
       sum += siz;
       if (dst)
        {
@@ -555,7 +555,8 @@ fhandler_registry::fstat (struct stat *buf)
                      else
                        buf->st_size = sys_wcstombs (NULL, 0,
                                                     (wchar_t *) tmpbuf,
-                                                    dwSize / sizeof (wchar_t));
+                                                    dwSize / sizeof (wchar_t))
+                                      + 1;
                      if (tmpbuf)
                        free (tmpbuf);
                    }
@@ -972,7 +973,7 @@ fhandler_registry::fill_filebuf ()
        }
       if (type == REG_SZ || type == REG_EXPAND_SZ || type == REG_LINK)
        bufalloc = sys_wcstombs (NULL, 0, (wchar_t *) tmpbuf,
-                                size / sizeof (wchar_t));
+                                size / sizeof (wchar_t)) + 1;
       else if (type == REG_MULTI_SZ)
        bufalloc = multi_wcstombs (NULL, 0, (wchar_t *) tmpbuf,
                                   size / sizeof (wchar_t));
index 20b4d3cb1deefd01a29d28898be0219d41ebf1ff..0f3946a4d3bc26dc5824cf847fbc188ca04f2898 100644 (file)
@@ -2107,7 +2107,7 @@ get_friendlyname (struct ifall *ifp, PIP_ADAPTER_ADDRESSES pap)
                                 &ifp->ifa_frndlyname;
   iff->ifrf_len = sys_wcstombs (iff->ifrf_friendlyname,
                                IFRF_FRIENDLYNAMESIZ,
-                               pap->FriendlyName);
+                               pap->FriendlyName) + 1;
 }
 
 static void
index c65c1cac7fefdafa5ed17c12732288af67082466..96cf3f5b253469890d92d1d43a56d0ed5c21dd89 100644 (file)
@@ -2166,7 +2166,7 @@ symlink_info::check_shortcut (HANDLE h)
        {
          char *tmpbuf = tp.c_get ();
          if (sys_wcstombs (tmpbuf, NT_MAX_PATH, (PWCHAR) (cp + 2))
-             > SYMLINK_MAX + 1)
+             > SYMLINK_MAX)
            return 0;
          res = posixify (tmpbuf);
        }
@@ -2247,7 +2247,7 @@ symlink_info::check_sysfile (HANDLE h)
            srcbuf += 2;
          char *tmpbuf = tp.c_get ();
          if (sys_wcstombs (tmpbuf, NT_MAX_PATH, (PWCHAR) srcbuf)
-             > SYMLINK_MAX + 1)
+             > SYMLINK_MAX)
            debug_printf ("symlink string too long");
          else
            res = posixify (tmpbuf);
@@ -2367,7 +2367,7 @@ symlink_info::check_nfs_symlink (HANDLE h)
       PWCHAR spath = (PWCHAR)
                     (pffei->EaName + pffei->EaNameLength + 1);
       res = sys_wcstombs (contents, SYMLINK_MAX + 1,
-                         spath, pffei->EaValueLength) - 1;
+                         spath, pffei->EaValueLength);
       pflags |= PATH_SYMLINK;
     }
   return res;
index 94ce82ce5772f25d650d642840443bcda6d49132..0be0f53f218c825ecad5ed5fceff14aeb5328644 100644 (file)
@@ -474,7 +474,6 @@ sys_cp_wcstombs (wctomb_p f_wctomb, const char *charset, char *dst, size_t len,
        }
       if (n + bytes <= len)
        {
-         n += bytes;
          if (dst)
            {
              for (int i = 0; i < bytes; ++i)
@@ -482,6 +481,7 @@ sys_cp_wcstombs (wctomb_p f_wctomb, const char *charset, char *dst, size_t len,
            }
          if (*pwcs++ == 0x00)
            break;
+         n += bytes;
        }
       else
        break;
index da5809f647e6f1927c5afa140f5ef12438d63fdd..df7d42f8e28ae56f504975e073b22aa447614c4f 100644 (file)
@@ -56,7 +56,7 @@ cygheap_user::init ()
   if (GetEnvironmentVariableW (L"USERNAME", user_name, user_name_len)
       || GetEnvironmentVariableW (L"USER", user_name, user_name_len))
     {
-      char mb_user_name[user_name_len = sys_wcstombs (NULL, 0, user_name)];
+      char mb_user_name[user_name_len = sys_wcstombs (NULL, 0, user_name) + 1];
       sys_wcstombs (mb_user_name, user_name_len, user_name);
       set_name (mb_user_name);
     }
This page took 0.041079 seconds and 5 git commands to generate.