lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20221024085222.179528-1-kunyu@nfschina.com>
Date:   Mon, 24 Oct 2022 16:52:22 +0800
From:   Li kunyu <kunyu@...china.com>
To:     krisman@...labora.com
Cc:     linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
        Li kunyu <kunyu@...china.com>
Subject: [PATCH] unicode: mkutf8data: Add unicode_data_malloc function

Add unicode_data_malloc function, used to simplify unicode_data member
assignment use.

Signed-off-by: Li kunyu <kunyu@...china.com>
---
 fs/unicode/mkutf8data.c | 43 +++++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/fs/unicode/mkutf8data.c b/fs/unicode/mkutf8data.c
index bc1a7c8b5c8d..f86fa700f7dc 100644
--- a/fs/unicode/mkutf8data.c
+++ b/fs/unicode/mkutf8data.c
@@ -2113,6 +2113,16 @@ static int ignore_compatibility_form(char *type)
 	return 0;
 }
 
+static void unicode_data_malloc(void *src, void **dst, size_t len)
+{
+	unsigned int *um = malloc(len);
+
+	if (um)
+		memcpy(um, src, len);
+
+	*dst = um;
+}
+
 static void nfdi_init(void)
 {
 	FILE *file;
@@ -2120,7 +2130,6 @@ static void nfdi_init(void)
 	unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */
 	char *s;
 	char *type;
-	unsigned int *um;
 	int count;
 	int i;
 	int ret;
@@ -2159,10 +2168,8 @@ static void nfdi_init(void)
 		}
 		mapping[i++] = 0;
 
-		um = malloc(i * sizeof(unsigned int));
-		memcpy(um, mapping, i * sizeof(unsigned int));
-		unicode_data[unichar].utf32nfdi = um;
-
+		unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdi,
+				i * sizeof(unsigned int));
 		if (verbose > 1)
 			print_utf32nfdi(unichar);
 		count++;
@@ -2181,7 +2188,6 @@ static void nfdicf_init(void)
 	unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */
 	char status;
 	char *s;
-	unsigned int *um;
 	int i;
 	int count;
 	int ret;
@@ -2215,10 +2221,8 @@ static void nfdicf_init(void)
 		}
 		mapping[i++] = 0;
 
-		um = malloc(i * sizeof(unsigned int));
-		memcpy(um, mapping, i * sizeof(unsigned int));
-		unicode_data[unichar].utf32nfdicf = um;
-
+		unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdicf,
+				i * sizeof(unsigned int));
 		if (verbose > 1)
 			print_utf32nfdicf(unichar);
 		count++;
@@ -2307,7 +2311,6 @@ static void corrections_init(void)
 	unsigned int minor;
 	unsigned int revision;
 	unsigned int age;
-	unsigned int *um;
 	unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */
 	char *s;
 	int i;
@@ -2359,10 +2362,8 @@ static void corrections_init(void)
 		}
 		mapping[i++] = 0;
 
-		um = malloc(i * sizeof(unsigned int));
-		memcpy(um, mapping, i * sizeof(unsigned int));
-		corrections[count].utf32nfdi = um;
-
+		unicode_data_malloc(mapping, &corrections[count].utf32nfdi,
+				i * sizeof(unsigned int));
 		if (verbose > 1)
 			printf(" %X -> %s -> %s V%d_%d_%d\n",
 				unichar, buf0, buf1, major, minor, revision);
@@ -2437,7 +2438,6 @@ static void hangul_decompose(void)
 	/* unsigned int sc = (lc * nc); */
 	unsigned int unichar;
 	unsigned int mapping[4];
-	unsigned int *um;
         int count;
 	int i;
 
@@ -2458,15 +2458,12 @@ static void hangul_decompose(void)
 			mapping[i++] = tb + ti;
 		mapping[i++] = 0;
 
-		assert(!unicode_data[unichar].utf32nfdi);
-		um = malloc(i * sizeof(unsigned int));
-		memcpy(um, mapping, i * sizeof(unsigned int));
-		unicode_data[unichar].utf32nfdi = um;
+		unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdi,
+				i * sizeof(unsigned int));
 
 		assert(!unicode_data[unichar].utf32nfdicf);
-		um = malloc(i * sizeof(unsigned int));
-		memcpy(um, mapping, i * sizeof(unsigned int));
-		unicode_data[unichar].utf32nfdicf = um;
+		unicode_data_malloc(mapping, &unicode_data[unichar].utf32nfdicf,
+				i * sizeof(unsigned int));
 
 		/*
 		 * Add a cookie as a reminder that the hangul syllable
-- 
2.18.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ