This is the mail archive of the libc-help@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]

Pointer to invalid multibyte sequence in mbsnrtowcs()


Hi all,

Contrary to mbsnrtowcs(3), *src is not left pointing to the invalid multibyte
sequence after mbsnrtowcs() completes.

There are two possible cases:

1) incomplete multibyte character is at the end of input buffer *)
2) incomplete multibyte character is not at the end of input buffer *)

*) - end of buffer is determined by nms argument.

But in either case *src is unchanged. Am I missing something obvious or it is
a bug?

Consider the following examples:

Example 1 (at the end of buffer):

    #include <locale.h>
    #include <wchar.h>
    #include <stdio.h>
    #include <string.h>
    int main(void)
    {
      setlocale(LC_CTYPE, "en_US.UTF-8");
      char *s = "\321\216\321";
      const char *x = s;
      printf("status: %d\n", mbsnrtowcs(NULL,&x,strlen(s),0,NULL));
      perror(NULL);
      printf("ori=%p\nnew=%p\n",(void *)s,(void *)x);
      return 0;
    }

Output 1:

    status: 1
    Success
    ori=0x56337c86d910
    new=0x56337c86d910


Example 2 (not at the end of buffer):

    #include <locale.h>
    #include <wchar.h>
    #include <stdio.h>
    #include <string.h>
    int main(void)
    {
      setlocale(LC_CTYPE, "en_US.UTF-8");
      char *s = "\321\216\321\321\215";
      const char *x = s;
      printf("status: %d\n", mbsnrtowcs(NULL,&x,strlen(s),0,NULL));
      perror(NULL);
      printf("ori=%p\nnew=%p\n",(void *)s,(void *)x);
      return 0;
    }

Output 2:

    status: -1
    Invalid or incomplete multibyte or wide character
    ori=0x55ad82792910
    new=0x55ad82792910


Regards,
Igor


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