This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/9677] New: mbsnrtowcs clobbers the conversion state when dst == NULL


The POSIX spec of mbsnrtowcs specifies that
"mbsnrtowcs() function shall be equivalent to the mbsrtowcs() function,
except that the conversion of characters pointed to by src is limited ..."

In glibc there is also another difference: When the dst argument is NULL,
the mbsrtowcs function will use a temporary state, so as to *not* modify
the state passed as argument, whereas the mbsnrtowcs function will clobber
the state passed as argument.

The spec is not very clear about when the state should be modified. My reading
is that when dst == NULL, the functions should not modify the state.
- Hint 1: the sentence "if dst is not a null pointer, the resulting state
  described shall be the initial conversion state".
- Hint 2: The purpose of passing dst == NULL is to determine the size of the
  wchar_t array needed, before calling the same function once again with
  dst != NULL.

I believe mbsnrtowcs should be changed to behave like mbsrtowcs. Cf. commit
1.20 in libc/wcsmbs/mbsrtowcs.c. Patch attached (untested).

References:
POSIX:2008 spec
<http://www.opengroup.org/onlinepubs/9699919799/functions/mbsrtowcs.html>

-- 
           Summary: mbsnrtowcs clobbers the conversion state when dst ==
                    NULL
           Product: glibc
           Version: 2.8
            Status: NEW
          Severity: normal
          Priority: P3
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: bruno at clisp dot org
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: i686-suse-linux
  GCC host triplet: i686-suse-linux
GCC target triplet: i686-suse-linux


http://sourceware.org/bugzilla/show_bug.cgi?id=9677

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]