Commit 769a8812 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Include <sys/types.h>, <time.h> and "s-string.h".

(l2g_next_key): Don't dereference memory past the last block!
parent c9252b5f
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
#include <malloc.h> #include <malloc.h>
#include <sys/types.h>
#include <time.h>
#include "s-string.h"
#include "kom-types.h" #include "kom-types.h"
#include "local-to-global.h" #include "local-to-global.h"
...@@ -370,16 +376,7 @@ l2g_next_key(Local_to_global *l2g, Local_text_no lno) ...@@ -370,16 +376,7 @@ l2g_next_key(Local_to_global *l2g, Local_text_no lno)
return 0; return 0;
/* If lno is lower than the first text, treat this as a special case. */ /* If lno is lower than the first text, treat this as a special case. */
if (lno < binfo->start) { if (lno >= binfo->start) {
/*
* Kid of ugly. This pointer is decremented here to point one
* item before the first block, but it is incremented again
* below. This way we can use the code below without having
* to copy it here.
*/
--binfo;
} else {
/* Check the found block */ /* Check the found block */
if (binfo->key_block == NULL) { if (binfo->key_block == NULL) {
/* dense block */ /* dense block */
...@@ -395,6 +392,7 @@ l2g_next_key(Local_to_global *l2g, Local_text_no lno) ...@@ -395,6 +392,7 @@ l2g_next_key(Local_to_global *l2g, Local_text_no lno)
return binfo->key_block[i]; return binfo->key_block[i];
} }
} }
binfo++;
} }
/* /*
...@@ -402,7 +400,7 @@ l2g_next_key(Local_to_global *l2g, Local_text_no lno) ...@@ -402,7 +400,7 @@ l2g_next_key(Local_to_global *l2g, Local_text_no lno)
* until there are no more blocks. Blocks can be completely * until there are no more blocks. Blocks can be completely
* empty due to removals of entries. * empty due to removals of entries.
*/ */
while (++binfo <= l2g->blocks + l2g->num_blocks) { for (; binfo < l2g->blocks + l2g->num_blocks; ++binfo) {
/* If the block contains anything at all, get the item. */ /* If the block contains anything at all, get the item. */
if (binfo->zeroes < L2G_BLOCKSIZE){ if (binfo->zeroes < L2G_BLOCKSIZE){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment