Cast or convert integers holding file positions.

Perform casts or change variable types to make code manipulating file
positions compliant with -Wconversion.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/cc9a8169
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/cc9a8169
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/cc9a8169

Branch: refs/heads/master
Commit: cc9a8169112df6989ec32d6c357ca63d0837773c
Parents: e9afedb
Author: Marvin Humphrey <mar...@rectangular.com>
Authored: Thu Apr 28 15:13:31 2016 -0700
Committer: Marvin Humphrey <mar...@rectangular.com>
Committed: Thu Apr 28 15:38:13 2016 -0700

----------------------------------------------------------------------
 c/src/Lucy/Index/DocReader.c                 |  4 ++--
 core/Lucy/Index/BitVecDelDocs.c              |  5 ++++-
 core/Lucy/Index/LexIndex.c                   |  2 +-
 core/Lucy/Index/SortCache/NumericSortCache.c |  8 ++++----
 core/Lucy/Index/SortCache/TextSortCache.c    |  4 ++--
 core/Lucy/Store/FSFileHandle.c               | 12 ++++++------
 core/Lucy/Store/Folder.c                     |  6 +++---
 core/Lucy/Store/OutStream.c                  |  2 +-
 8 files changed, 23 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/c/src/Lucy/Index/DocReader.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Index/DocReader.c b/c/src/Lucy/Index/DocReader.c
index 97c8df0..4677153 100644
--- a/c/src/Lucy/Index/DocReader.c
+++ b/c/src/Lucy/Index/DocReader.c
@@ -44,8 +44,8 @@ DefDocReader_Fetch_Doc_IMP(DefaultDocReader *self, int32_t 
doc_id) {
     char     *field_name = (char*)MALLOCATE(field_name_cap + 1);
 
     // Get data file pointer from index, read number of fields.
-    InStream_Seek(ix_in, (int64_t)doc_id * 8);
-    start = InStream_Read_U64(ix_in);
+    InStream_Seek(ix_in, doc_id * 8);
+    start = InStream_Read_I64(ix_in);
     InStream_Seek(dat_in, start);
     num_fields = InStream_Read_CU32(dat_in);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/core/Lucy/Index/BitVecDelDocs.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/BitVecDelDocs.c b/core/Lucy/Index/BitVecDelDocs.c
index 30dcb98..217682e 100644
--- a/core/Lucy/Index/BitVecDelDocs.c
+++ b/core/Lucy/Index/BitVecDelDocs.c
@@ -41,7 +41,10 @@ BitVecDelDocs_init(BitVecDelDocs *self, Folder *folder,
     }
     // Cast away const-ness of buffer as we have no immutable BitVector.
     int64_t len    = InStream_Length(ivars->instream);
-    ivars->bits    = (uint8_t*)InStream_Buf(ivars->instream, len);
+    if (len >= (int64_t)(SIZE_MAX / 8)) {
+        THROW(ERR, "Unexpected deletions file length: %i64", len);
+    }
+    ivars->bits    = (uint8_t*)InStream_Buf(ivars->instream, (size_t)len);
     ivars->cap     = (size_t)(len * 8);
     return self;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/core/Lucy/Index/LexIndex.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/LexIndex.c b/core/Lucy/Index/LexIndex.c
index 8a406a3..0d7a0ea 100644
--- a/core/Lucy/Index/LexIndex.c
+++ b/core/Lucy/Index/LexIndex.c
@@ -83,7 +83,7 @@ LexIndex_init(LexIndex *self, Schema *schema, Folder *folder,
     }
     ivars->index_interval = Arch_Index_Interval(arch);
     ivars->skip_interval  = Arch_Skip_Interval(arch);
-    ivars->size    = (int32_t)(InStream_Length(ivars->ixix_in) / 
sizeof(int64_t));
+    ivars->size    = (int32_t)(InStream_Length(ivars->ixix_in) / 
(int32_t)sizeof(int64_t));
     ivars->offsets = (const int64_t*)InStream_Buf(ivars->ixix_in,
             (size_t)InStream_Length(ivars->ixix_in));
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/core/Lucy/Index/SortCache/NumericSortCache.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache/NumericSortCache.c 
b/core/Lucy/Index/SortCache/NumericSortCache.c
index fc83844..fe91a7c 100644
--- a/core/Lucy/Index/SortCache/NumericSortCache.c
+++ b/core/Lucy/Index/SortCache/NumericSortCache.c
@@ -113,7 +113,7 @@ F64SortCache_Value_IMP(Float64SortCache *self, int32_t ord) 
{
         UNREACHABLE_RETURN(Obj*);
     }
     else {
-        InStream_Seek(ivars->dat_in, ord * sizeof(double));
+        InStream_Seek(ivars->dat_in, ord * (int64_t)sizeof(double));
         return (Obj*)Float_new(InStream_Read_F64(ivars->dat_in));
     }
 }
@@ -151,7 +151,7 @@ F32SortCache_Value_IMP(Float32SortCache *self, int32_t ord) 
{
         UNREACHABLE_RETURN(Obj*);
     }
     else {
-        InStream_Seek(ivars->dat_in, ord * sizeof(float));
+        InStream_Seek(ivars->dat_in, ord * (int64_t)sizeof(float));
         return (Obj*)Float_new(InStream_Read_F32(ivars->dat_in));
     }
 }
@@ -189,7 +189,7 @@ I32SortCache_Value_IMP(Int32SortCache *self, int32_t ord) {
         UNREACHABLE_RETURN(Obj*);
     }
     else {
-        InStream_Seek(ivars->dat_in, ord * sizeof(int32_t));
+        InStream_Seek(ivars->dat_in, ord * (int64_t)sizeof(int32_t));
         return (Obj*)Int_new(InStream_Read_I32(ivars->dat_in));
     }
 }
@@ -227,7 +227,7 @@ I64SortCache_Value_IMP(Int64SortCache *self, int32_t ord) {
         UNREACHABLE_RETURN(Obj*);
     }
     else {
-        InStream_Seek(ivars->dat_in, ord * sizeof(int64_t));
+        InStream_Seek(ivars->dat_in, ord * (int64_t)sizeof(int64_t));
         return (Obj*)Int_new(InStream_Read_I64(ivars->dat_in));
     }
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/core/Lucy/Index/SortCache/TextSortCache.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache/TextSortCache.c 
b/core/Lucy/Index/SortCache/TextSortCache.c
index f3596cd..b58f0f1 100644
--- a/core/Lucy/Index/SortCache/TextSortCache.c
+++ b/core/Lucy/Index/SortCache/TextSortCache.c
@@ -94,7 +94,7 @@ TextSortCache_Value_IMP(TextSortCache *self, int32_t ord) {
     if (ord == ivars->null_ord) {
         return NULL;
     }
-    InStream_Seek(ivars->ix_in, ord * sizeof(int64_t));
+    InStream_Seek(ivars->ix_in, ord * (int64_t)sizeof(int64_t));
     int64_t offset = InStream_Read_I64(ivars->ix_in);
     if (offset == NULL_SENTINEL) {
         return NULL;
@@ -103,7 +103,7 @@ TextSortCache_Value_IMP(TextSortCache *self, int32_t ord) {
         uint32_t next_ord = ord + 1;
         int64_t next_offset;
         while (1) {
-            InStream_Seek(ivars->ix_in, next_ord * sizeof(int64_t));
+            InStream_Seek(ivars->ix_in, next_ord * (int64_t)sizeof(int64_t));
             next_offset = InStream_Read_I64(ivars->ix_in);
             if (next_offset != NULL_SENTINEL) { break; }
             next_ord++;

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/core/Lucy/Store/FSFileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSFileHandle.c b/core/Lucy/Store/FSFileHandle.c
index c190639..93d2bb6 100644
--- a/core/Lucy/Store/FSFileHandle.c
+++ b/core/Lucy/Store/FSFileHandle.c
@@ -267,15 +267,15 @@ FSFH_Release_Window_IMP(FSFileHandle *self, FileWindow 
*window) {
 bool
 FSFH_Read_IMP(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
     FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
-    const int64_t end = offset + len;
+    const int64_t end = offset + (int64_t)len;
 
     if (ivars->flags & FH_WRITE_ONLY) {
         Err_set_error(Err_new(Str_newf("Can't read from write-only 
filehandle")));
         return false;
     }
-    if (offset < 0) {
-        Err_set_error(Err_new(Str_newf("Can't read from an offset less than 0 
(%i64)",
-                                       offset)));
+    if (offset < 0 || end < offset) {
+        Err_set_error(Err_new(Str_newf("Invalid offset and len (%i64, %u64)",
+                                       offset, (uint64_t)len)));
         return false;
     }
     else if (end > ivars->len) {
@@ -381,7 +381,7 @@ SI_map(FSFileHandle *self, FSFileHandleIVARS *ivars, 
int64_t offset,
 
     if (len) {
         // Read-only memory mapping.
-        buf = mmap(NULL, len, PROT_READ, MAP_SHARED, ivars->fd, offset);
+        buf = mmap(NULL, (size_t)len, PROT_READ, MAP_SHARED, ivars->fd, 
offset);
         if (buf == (void*)(-1)) {
             Err_set_error(Err_new(Str_newf("mmap of offset %i64 and length 
%i64 (page size %i64) "
                                            "against '%o' failed: %s",
@@ -397,7 +397,7 @@ SI_map(FSFileHandle *self, FSFileHandleIVARS *ivars, 
int64_t offset,
 static CFISH_INLINE bool
 SI_unmap(FSFileHandle *self, char *buf, int64_t len) {
     if (buf != NULL) {
-        if (munmap(buf, len)) {
+        if (munmap(buf, (size_t)len)) {
             Err_set_error(Err_new(Str_newf("Failed to munmap '%o': %s",
                                            FSFH_IVARS(self)->path,
                                            strerror(errno))));

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/core/Lucy/Store/Folder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Folder.c b/core/Lucy/Store/Folder.c
index c9149da..557bdde 100644
--- a/core/Lucy/Store/Folder.c
+++ b/core/Lucy/Store/Folder.c
@@ -373,12 +373,12 @@ Folder_Slurp_File_IMP(Folder *self, String *path) {
         RETHROW(INCREF(Err_get_error()));
     }
     else {
-        uint64_t length = InStream_Length(instream);
+        int64_t length = InStream_Length(instream);
 
-        if (length >= SIZE_MAX) {
+        if (SIZE_MAX < INT64_MAX && length >= ((int64_t)SIZE_MAX)) {
             InStream_Close(instream);
             DECREF(instream);
-            THROW(ERR, "File %o is too big to slurp (%u64 bytes)", path,
+            THROW(ERR, "File %o is too big to slurp (%i64 bytes)", path,
                   length);
         }
         else {

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc9a8169/core/Lucy/Store/OutStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/OutStream.c b/core/Lucy/Store/OutStream.c
index 507cb47..cd10165 100644
--- a/core/Lucy/Store/OutStream.c
+++ b/core/Lucy/Store/OutStream.c
@@ -143,7 +143,7 @@ OutStream_Grow_IMP(OutStream *self, int64_t length) {
 int64_t
 OutStream_Tell_IMP(OutStream *self) {
     OutStreamIVARS *const ivars = OutStream_IVARS(self);
-    return ivars->buf_start + ivars->buf_pos;
+    return ivars->buf_start + (int64_t)ivars->buf_pos;
 }
 
 int64_t

Reply via email to