@@ -329,20 +329,15 @@ bool InvokeCallbackForDatePattern(const char* locale,
329
329
UErrorCode ignore = U_ZERO_ERROR;
330
330
int32_t patternLen = udat_toPattern (pFormat, false , nullptr , 0 , &ignore);
331
331
332
- UChar* pattern = (UChar*) calloc ( patternLen + 1 , sizeof (UChar) );
332
+ std::vector< UChar> pattern ( patternLen + 1 , ' \0 ' );
333
333
334
- if (pattern == nullptr )
335
- return false ;
336
-
337
- udat_toPattern (pFormat, false , pattern, patternLen + 1 , &err);
334
+ udat_toPattern (pFormat, false , pattern.data (), patternLen + 1 , &err);
338
335
339
336
if (U_SUCCESS (err))
340
337
{
341
- callback (pattern, context);
338
+ callback (pattern. data () , context);
342
339
}
343
340
344
- free (pattern);
345
-
346
341
return U_SUCCESS (err);
347
342
}
348
343
@@ -368,22 +363,15 @@ bool InvokeCallbackForDateTimePattern(const char* locale,
368
363
UErrorCode ignore = U_ZERO_ERROR;
369
364
int32_t patternLen = udatpg_getBestPattern (pGenerator, patternSkeleton, -1 , nullptr , 0 , &ignore);
370
365
371
- UChar* bestPattern = (UChar*)calloc (patternLen + 1 , sizeof (UChar));
372
-
373
- if (bestPattern == nullptr )
374
- {
375
- return false ;
376
- }
366
+ std::vector<UChar> bestPattern (patternLen + 1 , ' \0 ' );
377
367
378
- udatpg_getBestPattern (pGenerator, patternSkeleton, -1 , bestPattern, patternLen + 1 , &err);
368
+ udatpg_getBestPattern (pGenerator, patternSkeleton, -1 , bestPattern. data () , patternLen + 1 , &err);
379
369
380
370
if (U_SUCCESS (err))
381
371
{
382
- callback (bestPattern, context);
372
+ callback (bestPattern. data () , context);
383
373
}
384
374
385
- free (bestPattern);
386
-
387
375
return U_SUCCESS (err);
388
376
}
389
377
0 commit comments