[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-recutils] [PATCH 05/13] src: fix index file builder.
From: |
Michał Masłowski |
Subject: |
[bug-recutils] [PATCH 05/13] src: fix index file builder. |
Date: |
Mon, 20 Aug 2012 18:21:26 +0200 |
---
ChangeLog | 9 +++++++++
src/rec-idx-file.c | 27 +++++++++++++++++++++++----
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a7a45b5..2a61ffe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-08-18 Michał Masłowski <address@hidden>
+
+ src: fix index file builder.
+ * src/rec-idx-file.c (rec_idx_build_file): Add padding after rset
+ names.
+ (rec_idx_build_add_index): Correctly check fwrite return value.
+ (rec_idx_build_num_indices): Correctly check fseek and fwrite
+ return values.
+
2012-08-15 Michał Masłowski <address@hidden>
src,torture: implement index builder.
diff --git a/src/rec-idx-file.c b/src/rec-idx-file.c
index e4b6d7a..1713d2c 100644
--- a/src/rec-idx-file.c
+++ b/src/rec-idx-file.c
@@ -331,9 +331,11 @@ rec_idx_build_file (rec_db_t db,
{
struct rec_idx_file_header_s header;
struct rec_idx_file_rset_s rset_header;
- size_t n, num_rsets, name_length;
+ size_t n, num_rsets, name_length, padding;
char *rset_name;
rec_rset_t rset;
+ long pos;
+ char zeros[8];
num_rsets = rec_db_size (db);
@@ -390,6 +392,23 @@ rec_idx_build_file (rec_db_t db,
return false;
}
}
+
+ /* Add padding to eight octets. */
+ pos = ftell (idx);
+ if (pos == -1)
+ {
+ return false;
+ }
+ else if (pos % 8 != 0)
+ {
+ padding = 8 - (pos % 8);
+ memset (zeros, 0, padding);
+ if (fwrite (zeros, 1, padding, idx) != padding)
+ {
+ return false;
+ }
+ }
+
return true;
}
@@ -411,7 +430,7 @@ rec_idx_build_add_index (FILE *idx,
index_header.type = type;
index_header.size = size;
if (fwrite (&index_header, sizeof (index_header), 1, idx)
- != sizeof (index_header))
+ != 1)
{
return false;
}
@@ -430,13 +449,13 @@ rec_idx_build_num_indices (FILE *idx,
{
struct rec_idx_file_header_s header;
if (fseek (idx, offsetof (struct rec_idx_file_header_s, num_indices),
- SEEK_SET))
+ SEEK_SET) == -1)
{
return false;
}
header.num_indices = num_indices;
if (fwrite (&(header.num_indices), sizeof (header.num_indices), 1, idx)
- != sizeof (header.num_indices))
+ != 1)
{
return false;
}
--
1.7.11.4
- [bug-recutils] Index trees, Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 01/13] src,torture: imple ment abstract record iterators., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 02/13] src,torture: imple ment initial index tree support without nodes., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 06/13] utils,doc: make re cfix --build-index add index trees., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 05/13] src: fix index file builder.,
Michał Masłowski <=
- [bug-recutils] [PATCH 04/13] src,torture: imple ment index builder., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 12/13] src: implement a tri vial query planner., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 09/13] src,torture: suppo rt duplicating index tree objects., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 10/13] src: keep indexes in rsets., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 11/13] src: support index t rees that point to a leaf too left of the key searched f or., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 08/13] utils: add recfix -- add-index command., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 13/13] torture: use index t rees for performance tests., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 07/13] src: fix index range checks., Michał Masłowski, 2012/08/20
- [bug-recutils] [PATCH 03/13] src,torture: imple ment index tree scans., Michał Masłowski, 2012/08/20