@@ -486,6 +486,16 @@ static void tree_walk(struct tree *tree)
486
486
nodes , leaves , singletons );
487
487
}
488
488
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
+
489
499
/*
490
500
* Allocate an initialize a new internal node.
491
501
*/
@@ -494,7 +504,7 @@ static struct node *alloc_node(struct node *parent)
494
504
struct node * node ;
495
505
int bitnum ;
496
506
497
- node = malloc (sizeof (* node ));
507
+ node = xmalloc (sizeof (* node ));
498
508
node -> left = node -> right = NULL ;
499
509
node -> parent = parent ;
500
510
node -> leftnode = NODE ;
@@ -2159,7 +2169,7 @@ static void nfdi_init(void)
2159
2169
}
2160
2170
mapping [i ++ ] = 0 ;
2161
2171
2162
- um = malloc (i * sizeof (unsigned int ));
2172
+ um = xmalloc (i * sizeof (unsigned int ));
2163
2173
memcpy (um , mapping , i * sizeof (unsigned int ));
2164
2174
unicode_data [unichar ].utf32nfdi = um ;
2165
2175
@@ -2215,7 +2225,7 @@ static void nfdicf_init(void)
2215
2225
}
2216
2226
mapping [i ++ ] = 0 ;
2217
2227
2218
- um = malloc (i * sizeof (unsigned int ));
2228
+ um = xmalloc (i * sizeof (unsigned int ));
2219
2229
memcpy (um , mapping , i * sizeof (unsigned int ));
2220
2230
unicode_data [unichar ].utf32nfdicf = um ;
2221
2231
@@ -2256,11 +2266,11 @@ static void ignore_init(void)
2256
2266
line_fail (prop_name , line );
2257
2267
for (unichar = first ; unichar <= last ; unichar ++ ) {
2258
2268
free (unicode_data [unichar ].utf32nfdi );
2259
- um = malloc (sizeof (unsigned int ));
2269
+ um = xmalloc (sizeof (unsigned int ));
2260
2270
* um = 0 ;
2261
2271
unicode_data [unichar ].utf32nfdi = um ;
2262
2272
free (unicode_data [unichar ].utf32nfdicf );
2263
- um = malloc (sizeof (unsigned int ));
2273
+ um = xmalloc (sizeof (unsigned int ));
2264
2274
* um = 0 ;
2265
2275
unicode_data [unichar ].utf32nfdicf = um ;
2266
2276
count ++ ;
@@ -2277,11 +2287,11 @@ static void ignore_init(void)
2277
2287
if (!utf32valid (unichar ))
2278
2288
line_fail (prop_name , line );
2279
2289
free (unicode_data [unichar ].utf32nfdi );
2280
- um = malloc (sizeof (unsigned int ));
2290
+ um = xmalloc (sizeof (unsigned int ));
2281
2291
* um = 0 ;
2282
2292
unicode_data [unichar ].utf32nfdi = um ;
2283
2293
free (unicode_data [unichar ].utf32nfdicf );
2284
- um = malloc (sizeof (unsigned int ));
2294
+ um = xmalloc (sizeof (unsigned int ));
2285
2295
* um = 0 ;
2286
2296
unicode_data [unichar ].utf32nfdicf = um ;
2287
2297
if (verbose > 1 )
@@ -2359,7 +2369,7 @@ static void corrections_init(void)
2359
2369
}
2360
2370
mapping [i ++ ] = 0 ;
2361
2371
2362
- um = malloc (i * sizeof (unsigned int ));
2372
+ um = xmalloc (i * sizeof (unsigned int ));
2363
2373
memcpy (um , mapping , i * sizeof (unsigned int ));
2364
2374
corrections [count ].utf32nfdi = um ;
2365
2375
@@ -2459,12 +2469,12 @@ static void hangul_decompose(void)
2459
2469
mapping [i ++ ] = 0 ;
2460
2470
2461
2471
assert (!unicode_data [unichar ].utf32nfdi );
2462
- um = malloc (i * sizeof (unsigned int ));
2472
+ um = xmalloc (i * sizeof (unsigned int ));
2463
2473
memcpy (um , mapping , i * sizeof (unsigned int ));
2464
2474
unicode_data [unichar ].utf32nfdi = um ;
2465
2475
2466
2476
assert (!unicode_data [unichar ].utf32nfdicf );
2467
- um = malloc (i * sizeof (unsigned int ));
2477
+ um = xmalloc (i * sizeof (unsigned int ));
2468
2478
memcpy (um , mapping , i * sizeof (unsigned int ));
2469
2479
unicode_data [unichar ].utf32nfdicf = um ;
2470
2480
@@ -2473,7 +2483,7 @@ static void hangul_decompose(void)
2473
2483
* decompositions must not be stored in the generated
2474
2484
* trie.
2475
2485
*/
2476
- unicode_data [unichar ].utf8nfdi = malloc (2 );
2486
+ unicode_data [unichar ].utf8nfdi = xmalloc (2 );
2477
2487
unicode_data [unichar ].utf8nfdi [0 ] = HANGUL ;
2478
2488
unicode_data [unichar ].utf8nfdi [1 ] = '\0' ;
2479
2489
@@ -2523,13 +2533,13 @@ static void nfdi_decompose(void)
2523
2533
if (ret )
2524
2534
break ;
2525
2535
free (unicode_data [unichar ].utf32nfdi );
2526
- um = malloc (i * sizeof (unsigned int ));
2536
+ um = xmalloc (i * sizeof (unsigned int ));
2527
2537
memcpy (um , mapping , i * sizeof (unsigned int ));
2528
2538
unicode_data [unichar ].utf32nfdi = um ;
2529
2539
}
2530
2540
/* Add this decomposition to nfdicf if there is no entry. */
2531
2541
if (!unicode_data [unichar ].utf32nfdicf ) {
2532
- um = malloc (i * sizeof (unsigned int ));
2542
+ um = xmalloc (i * sizeof (unsigned int ));
2533
2543
memcpy (um , mapping , i * sizeof (unsigned int ));
2534
2544
unicode_data [unichar ].utf32nfdicf = um ;
2535
2545
}
@@ -2577,7 +2587,7 @@ static void nfdicf_decompose(void)
2577
2587
if (ret )
2578
2588
break ;
2579
2589
free (unicode_data [unichar ].utf32nfdicf );
2580
- um = malloc (i * sizeof (unsigned int ));
2590
+ um = xmalloc (i * sizeof (unsigned int ));
2581
2591
memcpy (um , mapping , i * sizeof (unsigned int ));
2582
2592
unicode_data [unichar ].utf32nfdicf = um ;
2583
2593
}
0 commit comments