koreader/koreader — pull request #470 by thotypous (2014-01-19 03:09:02+00:00)
Title: Fix crash trying to select text in an empty page

If `boxes == {}`, which happens e.g. when we are in an empty page, `getWordFromBoxes` would crash and `getWordBoxIndices` would return `1,1`, making `getTextFromBoxes` also crash. We can avoid it by checking for `#boxes == 0` in the relevant functions.

The change in `readerhighlight.lua` is also needed because now `selected_word` might be an empty table (making `getWordFromBoxes` return `nil` would require to place checks in lots of points in the code).

Example of crash fixed by this PR:
```
# hold position in page {
["page"] = 2,
["x"] = 337,31398416887,
["y"] = 401,68337730871,
["rotation"] = 0,
["zoom"] = 1,2718120805369
}
./luajit: ./frontend/document/koptinterface.lua:598: attempt to index a nil value
stack traceback:
./frontend/document/koptinterface.lua:598: in function 'getWordFromBoxes'
./frontend/document/koptinterface.lua:738: in function 'getWordFromPosition'
./frontend/ui/reader/readerhighlight.lua:260: in function 'handleEvent'
./frontend/ui/widget/container/widgetcontainer.lua:63: in function 'propagateEvent'
./frontend/ui/widget/container/widgetcontainer.lua:75: in function 'handleEvent'
./frontend/ui/uimanager.lua:119: in function 'sendEvent'
./frontend/ui/uimanager.lua:307: in function 'run'
./reader.lua:196: in main chunk
[C]: in function 'dofile'
./koreader-base:37: in main chunk
[C]: at 0x0000bd45
```