svn commit: r298367 - head/lib/libc/locale

Andrey Chernov ache at freebsd.org
Thu Apr 21 07:22:54 UTC 2016


On 21.04.2016 9:29, Baptiste Daroussin wrote:
>>>> Modified: head/lib/libc/locale/ascii.c
>>>> ==============================================================================
>>>> --- head/lib/libc/locale/ascii.c	Wed Apr 20 20:43:05 2016	(r298366)
>>>> +++ head/lib/libc/locale/ascii.c	Wed Apr 20 20:44:30 2016	(r298367)
>>>> @@ -133,11 +133,14 @@ _ascii_mbsnrtowcs(wchar_t * __restrict d
>>>>  
>>>>  	if (dst == NULL) {
>>>>  		s = memchr(*src, '\0', nms);
>>>> +		if (s == NULL)
>>>> +			return (nms);
>>>> +
>>>>  		if (*s & 0x80) {
>>>>  			errno = EILSEQ;
>>>>  			return ((size_t)-1);
>>>>  		}
>>>> -		return (s != NULL ? s - *src : nms);
>>>> +		return (s - *src);
>>>>  	}
>>>>  
>>>>  	s = *src;
>>>>
>>>
>>> The whole code is incorrect, only the very first char is checked, there
>>> must be a loop like in -stable:
>>>
>>> 	if (dst == NULL) {
>>>                 for (s = *src; nms > 0 && *s != '\0'; s++, nms--) {
>>>                         if (*s & 0x80) {
>>>                                 errno = EILSEQ;
>>>                                 return ((size_t)-1);
>>>                         }
>>>                 }
>>>                 return (s - *src);
>>> 	}
>>>
>>> Since svn history is lost on deleting, I don't know why incorrect
>>> version was committed.
>>>
>>
>> Typo, the very first == the very last, i.e. only NUL char is checked
>> which always pass.
>>
> 
> I have restored the history (I hope correctly)
> 
> Bapt
> 

All the restored history is related to none.c, but ascii.c was made
afterwards a bit differently and transition history between none.c ->
ascii.c is lost in any case somehow.
We still have correct version in -stable.
The diff is attached.
BTW, recent none.c from which ascii.c is made don't have this two
copyrights too:
- * Copyright 2013 Garrett D'Amore <garrett at damore.org>
- * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
-------------- next part --------------
Index: ascii.c
===================================================================
--- ascii.c	(.../head/lib/libc/locale/ascii.c)	(revision 298395)
+++ ascii.c	(.../stable/10/lib/libc/locale/ascii.c)	(working copy)
@@ -1,6 +1,4 @@
-/*
- * Copyright 2013 Garrett D'Amore <garrett at damore.org>
- * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
+/*-
  * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
  * Copyright (c) 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -36,8 +34,6 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- * @(#)none.c	8.1 (Berkeley) 6/4/93
  */
 
 #include <sys/cdefs.h>
@@ -65,7 +61,7 @@
 		    size_t, size_t, mbstate_t * __restrict);
 
 int
-_ascii_init(struct xlocale_ctype *l, _RuneLocale *rl)
+_ascii_init(struct xlocale_ctype *l,_RuneLocale *rl)
 {
 
 	l->__mbrtowc = _ascii_mbrtowc;
@@ -82,6 +78,7 @@
 static int
 _ascii_mbsinit(const mbstate_t *ps __unused)
 {
+
 	/*
 	 * Encoding is not state dependent - we are always in the
 	 * initial state.
@@ -93,6 +90,7 @@
 _ascii_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
     mbstate_t * __restrict ps __unused)
 {
+
 	if (s == NULL)
 		/* Reset to initial shift state (no-op) */
 		return (0);
@@ -132,13 +130,11 @@
 	size_t nchr;
 
 	if (dst == NULL) {
-		s = memchr(*src, '\0', nms);
-		if (s == NULL)
-			return (nms);
-
-		if (*s & 0x80) {
-			errno = EILSEQ;
-			return ((size_t)-1);
+		for (s = *src; nms > 0 && *s != '\0'; s++, nms--) {
+			if (*s & 0x80) {
+				errno = EILSEQ;
+				return ((size_t)-1);
+			}
 		}
 		return (s - *src);
 	}
@@ -193,3 +189,4 @@
 	*src = s;
 	return (nchr);
 }
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/svn-src-all/attachments/20160421/b1a23b6e/attachment.sig>


More information about the svn-src-all mailing list