Changeset: 81246e8105e5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/81246e8105e5
Modified Files:
        clients/Tests/exports.stable.out
        common/stream/stdio_stream.c
        common/stream/stream.h
        gdk/gdk_logger.c
        monetdb5/mal/mal_import.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/vaults/csv/csv.c
Branch: default
Log Message:

make getFileSize return a int64_t rather than size_t

It's dangerous to convert a file size to size_t on 32 bit platforms.

We use int64_t rather than uint64_t because in some places file sizes
are stored in a lng, which is signed.  Also, st_size is usually a signed
type anyway, so using a signed type means fewer tricky signedness
conversions.


diffs (123 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1714,7 +1714,7 @@ stream *file_rstream(FILE *restrict fp, 
 stream *file_wstream(FILE *restrict fp, bool binary, const char *restrict 
name);
 FILE *getFile(stream *s);
 int getFileNo(stream *s);
-size_t getFileSize(stream *s);
+int64_t getFileSize(stream *s);
 stream *gz_stream(stream *inner, int preset);
 bool isa_block_stream(const stream *s);
 stream *lz4_stream(stream *inner, int preset);
diff --git a/common/stream/stdio_stream.c b/common/stream/stdio_stream.c
--- a/common/stream/stdio_stream.c
+++ b/common/stream/stdio_stream.c
@@ -368,14 +368,14 @@ getFileNo(stream *s)
        return fileno(f);
 }
 
-size_t
+int64_t
 getFileSize(stream *s)
 {
        struct stat stb;
        int fd = getFileNo(s);
 
        if (fd >= 0 && fstat(fd, &stb) == 0)
-               return (size_t) stb.st_size;
+               return (int64_t) stb.st_size;
        return 0;               /* unknown */
 }
 
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -189,7 +189,7 @@ stream_export stream *compressed_stream(
 
 stream_export FILE *getFile(stream *s); // gdk_logger.c progress messages
 stream_export int getFileNo(stream *s);        /* fileno(getFile(s)) */ // 
mclient.c, gdk_logger.c progress messages
-stream_export size_t getFileSize(stream *s); // mal_import.c, sql_scenario.c, 
store.c, bat_logger.c
+stream_export int64_t getFileSize(stream *s); // mal_import.c, sql_scenario.c, 
store.c, bat_logger.c
 
 typedef struct buffer {
        char *buf;
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1408,7 +1408,7 @@ log_read_transaction(logger *lg, BAT *id
        bool skip_entry = false;
        ATOMIC_BASE_TYPE dbg = ATOMIC_GET(&GDKdebug);
        time_t t0 = 0;
-       size_t fs = 0;
+       int64_t fs = 0;
 
        (void) maxupdated;      /* only used inside assert() */
 
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -92,7 +92,7 @@ static str
 malLoadScript(str name, bstream **fdin)
 {
        stream *fd;
-       size_t sz;
+       int64_t sz;
 
        fd = malOpenSource(name);
        if (fd == NULL || mnstr_errnr(fd) == MNSTR_OPEN_ERROR) {
@@ -101,11 +101,11 @@ malLoadScript(str name, bstream **fdin)
                          mnstr_peek_error(NULL));
        }
        sz = getFileSize(fd);
-       if (sz > (size_t) 1 << 29) {
+       if (sz > (1 << 29)) {
                close_stream(fd);
                throw(MAL, "malInclude", "file %s too large to process", name);
        }
-       *fdin = bstream_create(fd, sz == 0 ? (size_t) (2 * 128 * BLOCK) : sz);
+       *fdin = bstream_create(fd, sz == 0 ? (size_t) (2 * 128 * BLOCK) : 
(size_t)sz);
        if (*fdin == NULL) {
                close_stream(fd);
                throw(MAL, "malInclude", SQLSTATE(HY013) MAL_MALLOC_FAIL);
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1078,7 +1078,7 @@ SQLinclude(Client cntxt, MalBlkPtr mb, M
        str *name = getArgReference_str(stk, pci, 1);
        str msg = MAL_SUCCEED, fullname;
        mvc *m;
-       size_t sz;
+       int64_t sz;
        allocator *ta = MT_thread_getallocator();
        allocator_state ta_state = ma_open(ta);
 
@@ -1091,14 +1091,14 @@ SQLinclude(Client cntxt, MalBlkPtr mb, M
                throw(MAL, "sql.include", SQLSTATE(42000) "%s\n", 
mnstr_peek_error(NULL));
        }
        sz = getFileSize(fd);
-       if (sz > (size_t) 1 << 29) {
+       if (sz > (1 << 29)) {
                close_stream(fd);
                msg = createException(MAL, "sql.include", SQLSTATE(42000) "file 
%s too large to process", fullname);
                ma_close(&ta_state);
                return msg;
        }
        ma_close(&ta_state);
-       if ((bfd = bstream_create(fd, sz == 0 ? (size_t) (128 * BLOCK) : sz)) 
== NULL) {
+       if ((bfd = bstream_create(fd, sz == 0 ? (size_t) (128 * BLOCK) : 
(size_t)sz)) == NULL) {
                close_stream(fd);
                throw(MAL, "sql.include", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
diff --git a/sql/backends/monet5/vaults/csv/csv.c 
b/sql/backends/monet5/vaults/csv/csv.c
--- a/sql/backends/monet5/vaults/csv/csv.c
+++ b/sql/backends/monet5/vaults/csv/csv.c
@@ -431,7 +431,7 @@ csv_relation(mvc *sql, sql_subfunc *f, c
         */
        char buf[8196+1];
        *est = 0;
-       size_t fs = getFileSize(file);
+       int64_t fs = getFileSize(file);
        ssize_t l = mnstr_read(file, buf, 1, 8196);
        mnstr_close(file);
        mnstr_destroy(file);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to