Fix get_cursor() for max-sized block
commit783900d70d0a1338f4ff0dc8ec024b2af8410e67
authorPetr Tesarik <petr@tesarici.cz>
Fri, 18 May 2018 07:42:48 +0000 (18 09:42 +0200)
committerPetr Tesarik <petr@tesarici.cz>
Fri, 18 May 2018 07:42:48 +0000 (18 09:42 +0200)
tree8f18c1b612f9eee7e6d01d3d1c19e96a0236dd70
parentfb6f00d1e6e0f63a5423e3ee1120224c81e8b3ca
Fix get_cursor() for max-sized block

Since the size of a max-sized block overflows hed_uoff_t, its tree
node appears to be a zero-sized block and is not returned by
find_in_tree().

First, this is the only way find_block() can ever fail.

Second, there can be only one max-sized block in a file: either if
the file is empty, or if its size is MAX_UOFF + 1. Note that the
latter case is not yet handled, and not even made possible by the
operating system for regular files.

Consequently, if block search fails, it must be because there is a
max-sized block somewhere in the chain, possibly preceded by one or
more zero-sized insert block(s) and/or followed by a zero-sized
terminal block.

In other words, the max-sized block must be either:

  a. the terminal block (for empty files), or
  b. the block just before the terminal block.

Signed-off-by: Petr Tesarik <petr@tesarici.cz>
libhed/file.c