Date: Thu, 31 Mar 2016 01:36:51 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r297440 - stable/10/lib/libc/locale Message-ID: <201603310136.u2V1apg6081627@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Thu Mar 31 01:36:50 2016 New Revision: 297440 URL: https://svnweb.freebsd.org/changeset/base/297440 Log: MFC r296278: mbtowc(3): set errno to EILSEQ if an incomplete character is passed. According to POSIX, The mbtowc() function shall fail if: [EILSEQ] An invalid character sequence is detected. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D5496 Obtained from: OpenBSD (Ingo Schwarze) Modified: stable/10/lib/libc/locale/mbtowc.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/locale/mbtowc.c ============================================================================== --- stable/10/lib/libc/locale/mbtowc.c Thu Mar 31 00:53:23 2016 (r297439) +++ stable/10/lib/libc/locale/mbtowc.c Thu Mar 31 01:36:50 2016 (r297440) @@ -32,6 +32,7 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <errno.h> #include <stdlib.h> #include <wchar.h> #include "mblocal.h" @@ -49,9 +50,15 @@ mbtowc_l(wchar_t * __restrict pwc, const return (0); } rval = XLOCALE_CTYPE(locale)->__mbrtowc(pwc, s, n, &locale->mbtowc); - if (rval == (size_t)-1 || rval == (size_t)-2) + switch (rval) { + case (size_t)-2: + errno = EILSEQ; + /* FALLTHROUGH */ + case (size_t)-1: return (-1); - return ((int)rval); + default: + return ((int)rval); + } } int mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603310136.u2V1apg6081627>