wcsrtombs(3) doesn't update src wide character pointer when found illegal wide character.

Issue #66 closed
Takehiko NOZAKI repo owner created an issue

http://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsrtombs.html

spec says:

Conversion shall stop earlier in the following cases:

  • When a code is reached that does not correspond to a valid character

and:

the pointer object pointed to by src shall be assigned (...) the address just past the last wide character converted (...)

but our implementation doesn't update src wide character pointer when found illegal wide character.

try following testcase:

#include <assert.h>
#include <locale.h>
#include <limits.h>
#include <wchar.h>
#include <stdlib.h>
#include <string.h>

int
main(void)
{
        wchar_t wcs[] = { L'A', 0xFFFF, L'\0' };
        const wchar_t *pwcs = wcs;
        char s[MB_LEN_MAX * 3];
        mbstate_t st;
        size_t ret;

        setlocale(LC_CTYPE, "C");
        memset(&st, 0, sizeof(st));
        ret = wcsrtombs(s, &pwcs, sizeof(s), &st);
        assert(ret == (size_t)-1);
        assert(pwcs == &wcs[1]);
        assert(s[0] == 'A');
}

Comments (4)

  1. Log in to comment