Skip to content

Commit 719ece8

Browse files
committed
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/krisman/unicode.git
2 parents 76a6929 + b500d6d commit 719ece8

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

fs/unicode/mkutf8data.c

+24-14
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@ static void tree_walk(struct tree *tree)
486486
nodes, leaves, singletons);
487487
}
488488

489+
static void *xmalloc(size_t size)
490+
{
491+
void *p = malloc(size);
492+
493+
if (p)
494+
return p;
495+
fprintf(stderr, "Out of memory.\n");
496+
exit(1);
497+
}
498+
489499
/*
490500
* Allocate an initialize a new internal node.
491501
*/
@@ -494,7 +504,7 @@ static struct node *alloc_node(struct node *parent)
494504
struct node *node;
495505
int bitnum;
496506

497-
node = malloc(sizeof(*node));
507+
node = xmalloc(sizeof(*node));
498508
node->left = node->right = NULL;
499509
node->parent = parent;
500510
node->leftnode = NODE;
@@ -2159,7 +2169,7 @@ static void nfdi_init(void)
21592169
}
21602170
mapping[i++] = 0;
21612171

2162-
um = malloc(i * sizeof(unsigned int));
2172+
um = xmalloc(i * sizeof(unsigned int));
21632173
memcpy(um, mapping, i * sizeof(unsigned int));
21642174
unicode_data[unichar].utf32nfdi = um;
21652175

@@ -2215,7 +2225,7 @@ static void nfdicf_init(void)
22152225
}
22162226
mapping[i++] = 0;
22172227

2218-
um = malloc(i * sizeof(unsigned int));
2228+
um = xmalloc(i * sizeof(unsigned int));
22192229
memcpy(um, mapping, i * sizeof(unsigned int));
22202230
unicode_data[unichar].utf32nfdicf = um;
22212231

@@ -2256,11 +2266,11 @@ static void ignore_init(void)
22562266
line_fail(prop_name, line);
22572267
for (unichar = first; unichar <= last; unichar++) {
22582268
free(unicode_data[unichar].utf32nfdi);
2259-
um = malloc(sizeof(unsigned int));
2269+
um = xmalloc(sizeof(unsigned int));
22602270
*um = 0;
22612271
unicode_data[unichar].utf32nfdi = um;
22622272
free(unicode_data[unichar].utf32nfdicf);
2263-
um = malloc(sizeof(unsigned int));
2273+
um = xmalloc(sizeof(unsigned int));
22642274
*um = 0;
22652275
unicode_data[unichar].utf32nfdicf = um;
22662276
count++;
@@ -2277,11 +2287,11 @@ static void ignore_init(void)
22772287
if (!utf32valid(unichar))
22782288
line_fail(prop_name, line);
22792289
free(unicode_data[unichar].utf32nfdi);
2280-
um = malloc(sizeof(unsigned int));
2290+
um = xmalloc(sizeof(unsigned int));
22812291
*um = 0;
22822292
unicode_data[unichar].utf32nfdi = um;
22832293
free(unicode_data[unichar].utf32nfdicf);
2284-
um = malloc(sizeof(unsigned int));
2294+
um = xmalloc(sizeof(unsigned int));
22852295
*um = 0;
22862296
unicode_data[unichar].utf32nfdicf = um;
22872297
if (verbose > 1)
@@ -2359,7 +2369,7 @@ static void corrections_init(void)
23592369
}
23602370
mapping[i++] = 0;
23612371

2362-
um = malloc(i * sizeof(unsigned int));
2372+
um = xmalloc(i * sizeof(unsigned int));
23632373
memcpy(um, mapping, i * sizeof(unsigned int));
23642374
corrections[count].utf32nfdi = um;
23652375

@@ -2459,12 +2469,12 @@ static void hangul_decompose(void)
24592469
mapping[i++] = 0;
24602470

24612471
assert(!unicode_data[unichar].utf32nfdi);
2462-
um = malloc(i * sizeof(unsigned int));
2472+
um = xmalloc(i * sizeof(unsigned int));
24632473
memcpy(um, mapping, i * sizeof(unsigned int));
24642474
unicode_data[unichar].utf32nfdi = um;
24652475

24662476
assert(!unicode_data[unichar].utf32nfdicf);
2467-
um = malloc(i * sizeof(unsigned int));
2477+
um = xmalloc(i * sizeof(unsigned int));
24682478
memcpy(um, mapping, i * sizeof(unsigned int));
24692479
unicode_data[unichar].utf32nfdicf = um;
24702480

@@ -2473,7 +2483,7 @@ static void hangul_decompose(void)
24732483
* decompositions must not be stored in the generated
24742484
* trie.
24752485
*/
2476-
unicode_data[unichar].utf8nfdi = malloc(2);
2486+
unicode_data[unichar].utf8nfdi = xmalloc(2);
24772487
unicode_data[unichar].utf8nfdi[0] = HANGUL;
24782488
unicode_data[unichar].utf8nfdi[1] = '\0';
24792489

@@ -2523,13 +2533,13 @@ static void nfdi_decompose(void)
25232533
if (ret)
25242534
break;
25252535
free(unicode_data[unichar].utf32nfdi);
2526-
um = malloc(i * sizeof(unsigned int));
2536+
um = xmalloc(i * sizeof(unsigned int));
25272537
memcpy(um, mapping, i * sizeof(unsigned int));
25282538
unicode_data[unichar].utf32nfdi = um;
25292539
}
25302540
/* Add this decomposition to nfdicf if there is no entry. */
25312541
if (!unicode_data[unichar].utf32nfdicf) {
2532-
um = malloc(i * sizeof(unsigned int));
2542+
um = xmalloc(i * sizeof(unsigned int));
25332543
memcpy(um, mapping, i * sizeof(unsigned int));
25342544
unicode_data[unichar].utf32nfdicf = um;
25352545
}
@@ -2577,7 +2587,7 @@ static void nfdicf_decompose(void)
25772587
if (ret)
25782588
break;
25792589
free(unicode_data[unichar].utf32nfdicf);
2580-
um = malloc(i * sizeof(unsigned int));
2590+
um = xmalloc(i * sizeof(unsigned int));
25812591
memcpy(um, mapping, i * sizeof(unsigned int));
25822592
unicode_data[unichar].utf32nfdicf = um;
25832593
}

0 commit comments

Comments
 (0)