1*4882a593SmuzhiyunFrom 4e04afc2df9bbc26e5ab524b53a6f4f1e61d7c9e Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Javier Martinez Canillas <javierm@redhat.com>
3*4882a593SmuzhiyunDate: Tue, 5 Mar 2019 17:23:32 +0100
4*4882a593SmuzhiyunSubject: [PATCH] ucs2.h: fix logic that checks for UCS-2 string termination
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunCurrently the loop to count the lenght of the UCS-2 string ends if either
7*4882a593Smuzhiyunof the two bytes are 0, but 0 is a valid value for UCS-2 character codes.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunSo only break the loop when 0 is the value for both UCS-2 char bytes.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunSigned-off-by: Javier Martinez Canillas <javierm@redhat.com>
12*4882a593SmuzhiyunSigned-off-by: Peter Korsgaard <peter@korsgaard.com>
13*4882a593Smuzhiyun---
14*4882a593Smuzhiyun src/ucs2.h | 2 +-
15*4882a593Smuzhiyun 1 file changed, 1 insertion(+), 1 deletion(-)
16*4882a593Smuzhiyun
17*4882a593Smuzhiyundiff --git a/src/ucs2.h b/src/ucs2.h
18*4882a593Smuzhiyunindex e0390c3..fd8b056 100644
19*4882a593Smuzhiyun--- a/src/ucs2.h
20*4882a593Smuzhiyun+++ b/src/ucs2.h
21*4882a593Smuzhiyun@@ -29,7 +29,7 @@ ucs2len(const void *vs, ssize_t limit)
22*4882a593Smuzhiyun 	const uint8_t *s8 = vs;
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun 	for (i = 0;
25*4882a593Smuzhiyun-	     i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0;
26*4882a593Smuzhiyun+	     i < (limit >= 0 ? limit : i+1) && !(s8[0] == 0 && s8[1] == 0);
27*4882a593Smuzhiyun 	     i++, s8 += 2)
28*4882a593Smuzhiyun 		;
29*4882a593Smuzhiyun 	return i;
30*4882a593Smuzhiyun--
31*4882a593Smuzhiyun2.20.1
32*4882a593Smuzhiyun
33