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

Re: [PATCH] [BZ #17596] mblen return code when n is zero



On 11/13/2014 09:37 PM, Paul Eggert wrote:
Andreas Schwab wrote:
A non-existing character is valid, no?

Yes, mbrtowc should return (size_t) -2 when given an empty input buffer.

Thanks for the comment.Attaching the patch changing the rc to -2.

>From 959044f00cf11f3d46269ebca1a858a237d9ff4e Mon Sep 17 00:00:00 2001
From: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
Date: Fri, 14 Nov 2014 00:47:17 -0600
Subject: [PATCH] [BZ #17596] mblen return code when n is zero

This patch adds a check to return -2 when n is zero in mblen(),
mbrlen(),mbrtowc() and mbrtoc16().

	[BZ #17596]
	* wcsmbs/mbrtowc.c (__mbrtowc): Add check for n=0.
	* wcsmbs/mbrtoc16.c (mbrtoc16): Likewise.
---
 NEWS              | 2 +-
 wcsmbs/mbrtoc16.c | 2 ++
 wcsmbs/mbrtowc.c  | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index c582c8e..d8dc436 100644
--- a/NEWS
+++ b/NEWS
@@ -34,7 +34,7 @@ Version 2.20
   16966, 16967, 16977, 16978, 16984, 16990, 16996, 17009, 17022, 17031,
   17042, 17048, 17050, 17058, 17061, 17062, 17069, 17075, 17078, 17079,
   17084, 17086, 17088, 17092, 17097, 17125, 17135, 17137, 17150, 17153,
-  17187, 17213, 17259, 17261, 17262, 17263, 17319, 17325, 17354.
+  17187, 17213, 17259, 17261, 17262, 17263, 17319, 17325, 17354, 17596.
 
 * Optimized strchrnul implementation for AArch64.  Contributed by ARM Ltd.
 
diff --git a/wcsmbs/mbrtoc16.c b/wcsmbs/mbrtoc16.c
index 69105ba..d2ad553 100644
--- a/wcsmbs/mbrtoc16.c
+++ b/wcsmbs/mbrtoc16.c
@@ -77,6 +77,8 @@ mbrtoc16 (char16_t *pc16, const char *s, size_t n, mbstate_t *ps)
       n = 1;
     }
 
+  if (n == 0)
+    return (size_t) -2;
   /* Tell where we want the result.  */
   data.__outbuf = outbuf;
   data.__outbufend = outbuf + sizeof (wchar_t);
diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c
index 8070bd8..bfcb4b7 100644
--- a/wcsmbs/mbrtowc.c
+++ b/wcsmbs/mbrtowc.c
@@ -59,6 +59,8 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
       n = 1;
     }
 
+  if (n == 0)
+    return (size_t) -2;
   /* Tell where we want the result.  */
   data.__outbuf = outbuf;
   data.__outbufend = outbuf + sizeof (wchar_t);
-- 
1.8.3.1


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