Changeset: 8f4ff4af17c8 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8f4ff4af17c8 Modified Files: sql/backends/monet5/rel_bin.c sql/backends/monet5/sql.c sql/backends/monet5/sql_cat.c sql/backends/monet5/sql_statement.c sql/include/sql_catalog.h sql/server/rel_optimizer.c sql/server/rel_propagate.c sql/server/rel_schema.c sql/server/rel_select.c sql/server/rel_updates.c sql/storage/sql_catalog.c tools/monetdbe/monetdbe.c Branch: scoping2 Log Message:
Merged with default diffs (truncated from 4032 to 300 lines): diff --git a/buildtools/coverity_model.c b/buildtools/coverity_model.c new file mode 100644 --- /dev/null +++ b/buildtools/coverity_model.c @@ -0,0 +1,166 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V. + */ + +/* + * This file contains a model for Coverity Scan. + * This file is not a normal source file. It is not compiled by any + * compiler, but instead it is uploaded to the Coverity site and used + * during any analysis they do on our code. + * + * We model our use of the various allocation functions. + * Things we want to do is model that GDKmalloc and friends are paired + * with GDKfree, and that exceptions created by createException and + * createMalException should be freed with freeException. + * + * author: Sjoerd Mullender + */ + +typedef enum { GDK_FAIL, GDK_SUCCEED } gdk_return; +typedef struct {} *MalBlkPtr; + +void +GDKfree(void *blk) +{ + if (blk) { + __coverity_free__(blk); + __coverity_mark_as_afm_freed__(blk, "GDKfree"); + } +} + +void * +GDKmalloc(size_t size) +{ + int has_memory; + __coverity_negative_sink__(size); + if(has_memory) { + void *p = __coverity_alloc__(size); + __coverity_mark_as_afm_allocated__(p, "GDKfree"); + __coverity_mark_as_uninitialized_buffer__(p); + return p; + } + return 0; +} + +void * +GDKzalloc(size_t size) +{ + void *p = GDKmalloc(size); + if (p) { + for (size_t i = 0; i < size; i++) + ((char *) p)[i] = 0; + } + return p; +} + +char * +GDKstrdup(const char *s) +{ + char *p; + size_t i; + int has_memory; + if (s == 0) + return 0; + __coverity_string_null_sink__(s); + __coverity_string_size_sink__(s); + if (has_memory) { + p = __coverity_alloc_nosize__(); + __coverity_mark_as_afm_allocated__(p, "GDKfree"); + for (i = 0; (p[i] = s[i]); i++) + ; + return p; + } + return 0; +} + +char * +GDKstrndup(const char *s, size_t size) +{ + char *p; + size_t i; + __coverity_negative_sink__(size); + if (s == 0) + return 0; + p = GDKmalloc(size + 1); + if (p) { + for (i = 0; i < size && (p[i] = s[i]); i++) + ; + p[i] = 0; + } + return p; +} + +void * +GDKrealloc(void *blk, size_t size) +{ + void *p = GDKmalloc(size); + if (p != 0) + GDKfree(blk); + return p; +} + +void * +GDKmmap(const char *path, int mode, size_t size) +{ + int has_memory; + __coverity_negative_sink__(size); + if (has_memory) { + void *p = __coverity_alloc__(size); + __coverity_mark_as_afm_allocated__(p, "GDKmunmap"); + __coverity_writeall__(p); + return p; + } + return 0; +} + +gdk_return +GDKmunmap(void *p, size_t size) +{ + int failed; + __coverity_free__(p); + __coverity_mark_as_afm_freed__(p, "GDKmunmap"); + return failed ? GDK_FAIL : GDK_SUCCEED; +} + +void * +GDKmremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size) +{ + void *p = GDKmmap(path, mode, new_size); + if (p) { + (void) GDKmunmap(old_address, old_size); + } + return p; +} + +char * +createException(enum malexception type, const char *fcn, const char *format, ...) +{ + char *p; + __coverity_format_string_sink__(format); + p = __coverity_alloc_nosize__(); + __coverity_mark_as_afm_allocated__(p, "freeException"); + return p; +} + +char * +createMalException(MalBlkPtr mb, int pc, enum malexception type, const char *format, ...) +{ + char *p; + __coverity_format_string_sink__(format); + p = __coverity_alloc_nosize__(); + __coverity_mark_as_afm_allocated__(p, "freeException"); + return p; +} + +void +freeException(char *p) +{ + if (p) { + __coverity_free__(p); + __coverity_mark_as_afm_freed__(p, "freeException"); + } +} diff --git a/clients/examples/C/streamcat.c b/clients/examples/C/streamcat.c --- a/clients/examples/C/streamcat.c +++ b/clients/examples/C/streamcat.c @@ -207,6 +207,8 @@ int cmd_read(char *argv[]) copy_stream_to_file(s, out, bufsize); close_stream(s); + if (out != stdout) + fclose(out); return 0; } @@ -318,6 +320,9 @@ int cmd_write(char *argv[]) copy_file_to_stream(in, s, bufsize, do_flush, flush_level); close_stream(s); + if (in != stdin) + fclose(in); + return 0; } @@ -557,13 +562,13 @@ int cmd_bstream(char *argv[]) fclose(f); mnstr_flush(bs, MNSTR_FLUSH_DATA); } - mnstr_destroy(bs); - if (additional) { - mnstr_printf(s, "%s", additional); - } - mnstr_close(s); } + mnstr_destroy(bs); + if (additional) { + mnstr_printf(s, "%s", additional); + } + mnstr_close(s); return 0; } diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c --- a/common/utils/msabaoth.c +++ b/common/utils/msabaoth.c @@ -75,7 +75,7 @@ getFarmPath(char *pathbuf, size_t size, snprintf(pathbuf, size, "%s", _sabaoth_internal_dbfarm); } else { snprintf(pathbuf, size, "%s%c%s", - _sabaoth_internal_dbfarm, DIR_SEP, extra); + _sabaoth_internal_dbfarm, DIR_SEP, extra); } return(NULL); @@ -95,11 +95,11 @@ getDBPath(char *pathbuf, size_t size, co if (extra == NULL) { snprintf(pathbuf, size, "%s%c%s", - _sabaoth_internal_dbfarm, DIR_SEP, _sabaoth_internal_dbname); + _sabaoth_internal_dbfarm, DIR_SEP, _sabaoth_internal_dbname); } else { snprintf(pathbuf, size, "%s%c%s%c%s", - _sabaoth_internal_dbfarm, DIR_SEP, - _sabaoth_internal_dbname, DIR_SEP, extra); + _sabaoth_internal_dbfarm, DIR_SEP, + _sabaoth_internal_dbname, DIR_SEP, extra); } return(NULL); @@ -174,10 +174,9 @@ msab_init(const char *dbfarm, const char /* remove trailing slashes, newlines and spaces */ len--; while (len > 0 && ( - _sabaoth_internal_dbfarm[len] == '/' || - _sabaoth_internal_dbfarm[len] == '\n' || - _sabaoth_internal_dbfarm[len] == ' ')) - { + _sabaoth_internal_dbfarm[len] == '/' || + _sabaoth_internal_dbfarm[len] == '\n' || + _sabaoth_internal_dbfarm[len] == ' ')) { _sabaoth_internal_dbfarm[len] = '\0'; len--; } @@ -314,7 +313,7 @@ msab_marchScenario(const char *lang) return(NULL); } snprintf(buf, sizeof(buf), "failed to open file: %s (%s)", - strerror(errno), pathbuf); + strerror(errno), pathbuf); return(strdup(buf)); } @@ -358,7 +357,7 @@ msab_retreatScenario(const char *lang) len = strlen(buf) + 1; if (fwrite(buf, 1, len, f) < len) { snprintf(buf, sizeof(buf), "failed to write: %s (%s)", - strerror(errno), pathbuf); + strerror(errno), pathbuf); (void)fclose(f); return(strdup(buf)); } @@ -373,7 +372,7 @@ msab_retreatScenario(const char *lang) if (ferror(f)) { /* some error */ snprintf(buf, sizeof(buf), "failed to write: %s (%s)", - strerror(errno), pathbuf); + strerror(errno), pathbuf); (void)fclose(f); return strdup(buf); } @@ -383,7 +382,7 @@ msab_retreatScenario(const char *lang) } } snprintf(buf, sizeof(buf), "failed to open file: %s (%s)", - strerror(errno), pathbuf); + strerror(errno), pathbuf); return(strdup(buf)); } @@ -407,7 +406,7 @@ msab_marchConnection(const char *host, c if (port <= 0 && host[0] != '/') return(strdup("UNIX domain connections should be given as " - "absolute path")); + "absolute path")); if ((f = fopen(pathbuf, "a")) != NULL) { /* append to the file */ @@ -422,7 +421,7 @@ msab_marchConnection(const char *host, c } else { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list