rime / librime

Rime Input Method Engine, the core library
https://rime.im
BSD 3-Clause "New" or "Revised" License
3.39k stars 556 forks source link

Can `Memory::dict_` be `NULL` ? #441

Closed hchunhui closed 3 years ago

hchunhui commented 3 years ago

https://github.com/rime/librime/blob/7d9ad77fb5e8e6e330925de5e09c6ecfc2d2f4fd/src/rime/gear/memory.cc#L73

lotem commented 3 years ago

https://github.com/rime/librime/blob/7d9ad77fb5e8e6e330925de5e09c6ecfc2d2f4fd/src/rime/gear/memory.cc#L55 Shouldn't be a null pointer as it is assigned an instance of Dictionary in the constructor. But the Dictionary may not be loaded.

hchunhui commented 3 years ago

I think Memory::dict_ can be NULL, but I'm not sure if it will happen in reality.

The Create() function may return nullptr: https://github.com/rime/librime/blob/7d9ad77fb5e8e6e330925de5e09c6ecfc2d2f4fd/src/rime/dict/dictionary.cc#L368

And there is a check before Load(): https://github.com/rime/librime/blob/7d9ad77fb5e8e6e330925de5e09c6ecfc2d2f4fd/src/rime/gear/memory.cc#L56

lotem commented 3 years ago

you are right. the case dict_ is null should be handled.