This is the mail archive of the libc-locales@sourceware.org mailing list for the GNU libc locales 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 localedata/17596] New: mblen() does not return -1 for invalid input


https://sourceware.org/bugzilla/show_bug.cgi?id=17596

            Bug ID: 17596
           Summary: mblen() does not return -1 for invalid input
           Product: glibc
           Version: 2.21
            Status: NEW
          Severity: minor
          Priority: P2
         Component: localedata
          Assignee: unassigned at sourceware dot org
          Reporter: raji at linux dot vnet.ibm.com
                CC: libc-locales at sourceware dot org

The standard document for mblen() states:

#include <stdlib.h>
int mblen(const char *s, size_t n);

The standard states:
"If s is a null pointer, the mblen function returns a nonzero or zero value, if
multibyte character encodings, respectively,
 do or do not have state-dependent encodings. If s is not a null pointer, the
mblen function either returns 0
(if s points to the null character), or returns the number of bytes that are
contained in the multibyte character
(if the next n or fewer bytes form a valid multibyte character), or returns -1
(if they do not form a valid multibyte character). "


The case n=0 is not explicitly mentioned in the standards document and is also
not handled in the code(stdlib/mblen.c)
When compiled on AIX (v6.1 and other releases) mblen() returns -1.

$ cat mblen_t.c
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

main() {
     char sbcs_st[]  = "12345";

     if ( setlocale( LC_ALL, "" ) == NULL ) {
        printf( "setlocale() failed\n" );
     }
     printf("RC is %d\n", mblen(sbcs_st, 0));
}

$ gcc -o mblen_t mblen_t.c;./mblen_t
RC is 0


https://sourceware.org/ml/libc-alpha/2014-11/msg00191.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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