Refactor to use new protocol module and sipo.
[bertos.git] / bertos / io / kfile_block.c
index 57c6f8d32fcf895636789d726bfeb6aa974b26b9..e3bcdd3917fc1a21c6461701972900a17ffb7663 100644 (file)
@@ -32,6 +32,9 @@
  *
  * \brief KFile interface over a KBlock.
  *
+ * \author Francesco Sacchi <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
+ *
  */
 
 #include "kfile_block.h"
@@ -59,6 +62,8 @@ INLINE KFileBlock * KFILEBLOCK_CAST(KFile *fd)
        while (size) \
        { \
                block_idx_t id = (fd)->seek_pos / fb->blk->blk_size; \
+               if (id >= fb->blk->blk_cnt) \
+                       break; \
                size_t offset = (fd)->seek_pos % fb->blk->blk_size; \
                size_t count = MIN(size, (size_t)(fb->blk->blk_size - offset)); \
                size_t ret_len = kblock_##dir(fb->blk, id, buf, offset, count); \