Changeset: 297a9a43ae9f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/297a9a43ae9f
Removed Files:
        monetdb5/optimizer/opt_prelude.c
        monetdb5/optimizer/opt_prelude.h
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal_namespace.c
        monetdb5/mal/mal_namespace.h
        monetdb5/modules/atoms/str.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_cat.c
        sql/backends/monet5/sql_statement.c
        sql/common/sql_types.c
        sql/storage/bat/bat_logger.c
        sql/storage/store.c
Branch: ordered-set-aggregates
Log Message:

merged with default


diffs (truncated from 6871 to 300 lines):

diff --git a/clients/mapilib/connect.c b/clients/mapilib/connect.c
--- a/clients/mapilib/connect.c
+++ b/clients/mapilib/connect.c
@@ -797,10 +797,11 @@ mapi_handshake(Mapi mid)
                if (motdlen > 0) {
                        mid->motd = malloc(motdlen + 1);
                        *mid->motd = 0;
+                       char *p = mid->motd;
                        for (i = 0; i < result->cache.writer; i++)
                                if (result->cache.line[i].rows && 
result->cache.line[i].rows[0] == '#') {
-                                       strcat(mid->motd, 
result->cache.line[i].rows);
-                                       strcat(mid->motd, "\n");
+                                       p = stpcpy(p, 
result->cache.line[i].rows);
+                                       p = stpcpy(p, "\n");
                                }
                }
 
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -1561,10 +1561,8 @@ add_error(struct MapiResultSet *result, 
        REALLOC(result->errorstr, size + strlen(error) + 2);
        if (result->errorstr == NULL)
                result->errorstr = mapi_nomem;
-       else {
-               strcpy(result->errorstr + size, error);
-               strcat(result->errorstr + size, "\n");
-       }
+       else
+               stpcpy(stpcpy(result->errorstr + size, error), "\n");
 }
 
 const char *
diff --git a/common/stream/memio.c b/common/stream/memio.c
--- a/common/stream/memio.c
+++ b/common/stream/memio.c
@@ -20,9 +20,11 @@ buffer_init(buffer *restrict b, char *re
 {
        if (b == NULL || buf == NULL)
                return;
-       b->pos = 0;
-       b->buf = buf;
-       b->len = size;
+       *b = (buffer) {
+               .pos = 0,
+               .buf = buf,
+               .len = size,
+       };
 }
 
 buffer *
diff --git a/common/utils/mstring.h b/common/utils/mstring.h
--- a/common/utils/mstring.h
+++ b/common/utils/mstring.h
@@ -23,8 +23,17 @@
 #define GCC_Pragma(pragma)
 #endif
 
+#if defined(__has_attribute)
+#if ! __has_attribute(__access__)
+#define __access__(...)
+#endif
+#else
+#define __access__(...)
+#endif
+
 /* copy at most (n-1) bytes from src to dst and add a terminating NULL
  * byte; return length of src (i.e. can be more than what is copied) */
+__attribute__((__access__(write_only, 1, 3)))
 static inline size_t
 strcpy_len(char *restrict dst, const char *restrict src, size_t n)
 {
@@ -63,6 +72,8 @@ GCC_Pragma("GCC diagnostic pop")
 
 /* copy the NULL terminated list of src strings with a maximum of n
  * bytes to dst; return the combined length of the src strings */
+__attribute__((__access__(write_only, 1, 2)))
+__attribute__((__sentinel__))
 static inline size_t
 strconcat_len(char *restrict dst, size_t n, const char *restrict src, ...)
 {
diff --git a/ctest/tools/monetdbe/example_copy.c 
b/ctest/tools/monetdbe/example_copy.c
--- a/ctest/tools/monetdbe/example_copy.c
+++ b/ctest/tools/monetdbe/example_copy.c
@@ -21,8 +21,8 @@
 int
 main(void)
 {
-       char sql[1000];
        char csv_path[PATH_MAX];
+       char sql[sizeof(csv_path) + 60];
        char* err = NULL;
        monetdbe_database mdbe;
        monetdbe_result* result = NULL;
@@ -44,22 +44,21 @@ main(void)
        }
        strcat(csv_path, "/test.csv");
 
-       strcpy(sql, "COPY SELECT * FROM test INTO '");
-       strcat(sql, csv_path);
-       strcat(sql, "' USING DELIMITERS ','");
+       snprintf(sql, sizeof(sql),
+                        "COPY SELECT * FROM test INTO '%s' USING DELIMITERS 
','",
+                        csv_path);
 
        if ((err = monetdbe_query(mdbe, sql, NULL, NULL)) != NULL)
                error(err)
-       
+
        if ((err = monetdbe_query(mdbe, "CREATE TABLE test_copy (x integer, y 
string, ts timestamp, dt date, t time, b blob)", NULL, NULL)) != NULL) {
                delete_file(csv_path)
                error(err)
        }
 
-       memset(sql, 0, 1000);
-       strcpy(sql, "COPY INTO test_copy FROM '");
-       strcat(sql, csv_path);
-       strcat(sql, "' DELIMITERS ','");
+       snprintf(sql, sizeof(sql),
+                        "COPY INTO test_copy FROM '%s' DELIMITERS ','",
+                        csv_path);
 
        if ((err = monetdbe_query(mdbe, sql, NULL, NULL)) != NULL) {
                delete_file(csv_path)
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1484,8 +1484,10 @@ gdk_export gdk_return BATsave(BAT *b)
        __attribute__((__warn_unused_result__));
 
 #define NOFARM (-1) /* indicate to GDKfilepath to create relative path */
+#define MAXPATH        1024            /* maximum supported file path */
 
-gdk_export char *GDKfilepath(int farmid, const char *dir, const char *nme, 
const char *ext);
+gdk_export gdk_return GDKfilepath(char *buf, size_t bufsize, int farmid, const 
char *dir, const char *nme, const char *ext)
+       __attribute__((__access__(write_only, 1, 2)));
 gdk_export bool GDKinmemory(int farmid);
 gdk_export bool GDKembedded(void);
 gdk_export gdk_return GDKcreatedir(const char *nme);
@@ -2530,7 +2532,7 @@ TIMEOUT_TEST(QryCtx *qc)
        } while (0)
 
 typedef struct gdk_callback {
-       char *name;
+       const char *name;
        int argc;
        int interval;  // units sec
        lng last_called; // timestamp GDKusec
@@ -2541,9 +2543,9 @@ typedef struct gdk_callback {
 
 typedef gdk_return gdk_callback_func(int argc, void *argv[]);
 
-gdk_export gdk_return gdk_add_callback(char *name, gdk_callback_func *f, int 
argc, void
-               *argv[], int interval);
-gdk_export gdk_return gdk_remove_callback(char *, gdk_callback_func *f);
+gdk_export gdk_return gdk_add_callback(const char *name, gdk_callback_func *f,
+                                      int argc, void *argv[], int interval);
+gdk_export gdk_return gdk_remove_callback(const char *, gdk_callback_func *f);
 
 
 #include <setjmp.h>
@@ -2555,7 +2557,7 @@ typedef struct exception_buffer {
        jmp_buf state;
 #endif
        int code;
-       char *msg;
+       const char *msg;
        int enabled;
 } exception_buffer;
 
@@ -2568,7 +2570,7 @@ gdk_export exception_buffer *eb_init(exc
 #else
 #define eb_savepoint(eb) ((eb)->enabled = 1, setjmp((eb)->state))
 #endif
-gdk_export _Noreturn void eb_error(exception_buffer *eb, char *msg, int val);
+gdk_export _Noreturn void eb_error(exception_buffer *eb, const char *msg, int 
val);
 
 typedef struct allocator {
        struct allocator *pa;
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2327,7 +2327,7 @@ static gdk_return
 backup_new(Heap *hp, bool lock)
 {
        int batret, bakret, ret = -1;
-       char *batpath, *bakpath;
+       char batpath[MAXPATH], bakpath[MAXPATH];
        struct stat st;
 
        char *bak_filename = NULL;
@@ -2336,9 +2336,8 @@ backup_new(Heap *hp, bool lock)
        else
                bak_filename = hp->filename;
        /* check for an existing X.new in BATDIR, BAKDIR and SUBDIR */
-       batpath = GDKfilepath(hp->farmid, BATDIR, hp->filename, "new");
-       bakpath = GDKfilepath(hp->farmid, BAKDIR, bak_filename, "new");
-       if (batpath != NULL && bakpath != NULL) {
+       if (GDKfilepath(batpath, sizeof(batpath), hp->farmid, BATDIR, 
hp->filename, "new") == GDK_SUCCEED &&
+           GDKfilepath(bakpath, sizeof(bakpath), hp->farmid, BAKDIR, 
bak_filename, "new") == GDK_SUCCEED) {
                /* file actions here interact with the global commits */
                if (lock)
                        BBPtmlock();
@@ -2364,8 +2363,6 @@ backup_new(Heap *hp, bool lock)
                if (lock)
                        BBPtmunlock();
        }
-       GDKfree(batpath);
-       GDKfree(bakpath);
        return ret ? GDK_FAIL : GDK_SUCCEED;
 }
 
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -894,7 +894,7 @@ BBPcheckbats(unsigned bbpversion)
        for (bat bid = 1, size = (bat) ATOMIC_GET(&BBPsize); bid < size; bid++) 
{
                struct stat statb;
                BAT *b;
-               char *path;
+               char path[MAXPATH];
 
                b = BBP_desc(bid);
                if (b->batCacheid == 0 || b->ttype == TYPE_void) {
@@ -902,20 +902,17 @@ BBPcheckbats(unsigned bbpversion)
                        continue;
                }
                if (b->theap->free > 0) {
-                       path = GDKfilepath(0, BATDIR, b->theap->filename, NULL);
-                       if (path == NULL)
+                       if (GDKfilepath(path, sizeof(path), 0, BATDIR, 
b->theap->filename, NULL) != GDK_SUCCEED)
                                return GDK_FAIL;
                        /* first check string offset heap with width,
                         * then without */
                        if (MT_stat(path, &statb) < 0) {
                                GDKsyserror("cannot stat file %s (expected size 
%zu)\n",
                                            path, b->theap->free);
-                               GDKfree(path);
                                return GDK_FAIL;
                        }
                        if ((size_t) statb.st_size < b->theap->free) {
                                GDKerror("file %s too small (expected %zu, 
actual %zu)\n", path, b->theap->free, (size_t) statb.st_size);
-                               GDKfree(path);
                                return GDK_FAIL;
                        }
                        size_t hfree = b->theap->free;
@@ -930,21 +927,17 @@ BBPcheckbats(unsigned bbpversion)
                                        (void) close(fd);
                                }
                        }
-                       GDKfree(path);
                }
                if (b->tvheap != NULL && b->tvheap->free > 0) {
-                       path = GDKfilepath(0, BATDIR, 
BBP_physical(b->batCacheid), "theap");
-                       if (path == NULL)
+                       if (GDKfilepath(path, sizeof(path), 0, BATDIR, 
BBP_physical(b->batCacheid), "theap") != GDK_SUCCEED)
                                return GDK_FAIL;
                        if (MT_stat(path, &statb) < 0) {
                                GDKsyserror("cannot stat file %s\n",
                                            path);
-                               GDKfree(path);
                                return GDK_FAIL;
                        }
                        if ((size_t) statb.st_size < b->tvheap->free) {
                                GDKerror("file %s too small (expected %zu, 
actual %zu)\n", path, b->tvheap->free, (size_t) statb.st_size);
-                               GDKfree(path);
                                return GDK_FAIL;
                        }
                        size_t hfree = b->tvheap->free;
@@ -959,7 +952,6 @@ BBPcheckbats(unsigned bbpversion)
                                        (void) close(fd);
                                }
                        }
-                       GDKfree(path);
                }
        }
        return GDK_SUCCEED;
@@ -1110,7 +1102,7 @@ BBPaddfarm(const char *dirname, uint32_t
                        }
                        BBPfarms[i].roles = rolemask;
                        if ((rolemask & 1) == 0 && dirname != NULL) {
-                               char *bbpdir;
+                               char bbpdir[MAXPATH];
                                int j;
 
                                for (j = 0; j < i; j++)
@@ -1122,28 +1114,22 @@ BBPaddfarm(const char *dirname, uint32_t
                                 * don't find a BBP.dir there that
                                 * might belong to an existing
                                 * database */
-                               bbpdir = GDKfilepath(i, BATDIR, "BBP", "dir");
-                               if (bbpdir == NULL) {
+                               if (GDKfilepath(bbpdir, sizeof(bbpdir), i, 
BATDIR, "BBP", "dir") != GDK_SUCCEED) {
                                        return GDK_FAIL;
                                }
                                if (MT_stat(bbpdir, &st) != -1 || errno != 
ENOENT) {
-                                       GDKfree(bbpdir);
                                        if (logerror)
                                                GDKerror("%s is a database\n", 
dirname);
                                        return GDK_FAIL;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to