Skip to content

Commit

Permalink
Handle possible malloc failures.
Browse files Browse the repository at this point in the history
* src/thbrk/brk-maximal.c (brk_maximal_do_impl, brk_recover_try):
  - Handle cases where brk_pool_node_new() possibly returns NULL.
    In both places, fail gracefully by behaving as if the dict state
    were single there.

Partially addresses Issue #15.
  • Loading branch information
thep committed Oct 31, 2021
1 parent 6c6ab4a commit 3adb251
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2021-09-18 Theppitak Karoonboonyanan <[email protected]>

Handle possible malloc failures.

* src/thbrk/brk-maximal.c (brk_maximal_do_impl, brk_recover_try):
- Handle cases where brk_pool_node_new() possibly returns NULL.
In both places, fail gracefully by behaving as if the dict state
were single there.

Partially addresses Issue #15.

2021-09-18 Theppitak Karoonboonyanan <[email protected]>

Fix typo in TIS-620 character name.
Expand Down
18 changes: 12 additions & 6 deletions src/thbrk/brk-maximal.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,12 @@ brk_maximal_do_impl (const thwchar_t *ws, int len,
!trie_state_is_single (shot->dict_state))
{
/* add node to mark break position instead of current */
node = brk_pool_node_new (shot, env);
pool = brk_pool_add (pool, node);
shot = &node->shot;
BrkPool *new_node = brk_pool_node_new (shot, env);
if (LIKELY (new_node)) {
node = new_node;
pool = brk_pool_add (pool, node);
shot = &node->shot;
}
}

trie_state_rewind (shot->dict_state);
Expand Down Expand Up @@ -326,9 +329,12 @@ brk_recover_try (const thwchar_t *ws, int len,
!trie_state_is_single (shot->dict_state))
{
/* add node to mark break position instead of current */
node = brk_pool_node_new (shot, env);
pool = brk_pool_add (pool, node);
shot = &node->shot;
BrkPool *new_node = brk_pool_node_new (shot, env);
if (LIKELY (new_node)) {
node = new_node;
pool = brk_pool_add (pool, node);
shot = &node->shot;
}
}

trie_state_rewind (shot->dict_state);
Expand Down

0 comments on commit 3adb251

Please sign in to comment.