Changeset: e3ded1baa8c5 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e3ded1baa8c5 Modified Files: buildtools/ChangeLog.Jan2014 clients/python2/monetdb/sql/pythonize.py clients/python3/monetdb/sql/pythonize.py common/stream/stream.c java/Makefile.ag java/build.properties java/pom.xml java/release.txt java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java Branch: default Log Message:
Merge with Jan2014 branch. diffs (truncated from 830 to 300 lines): diff --git a/buildtools/ChangeLog.Jan2014 b/buildtools/ChangeLog.Jan2014 --- a/buildtools/ChangeLog.Jan2014 +++ b/buildtools/ChangeLog.Jan2014 @@ -1,6 +1,10 @@ # ChangeLog file for buildtools # This file is updated with Maddlog +* Wed Apr 30 2014 Sjoerd Mullender <sjo...@acm.org> +- Lots of minor fixes were made for potential defects found by Coverity + Scan. + * Mon Mar 24 2014 Sjoerd Mullender <sjo...@acm.org> - On Windows we now build the geom module against version 3.4.2 of the geos library. diff --git a/clients/python2/monetdb/sql/pythonize.py b/clients/python2/monetdb/sql/pythonize.py --- a/clients/python2/monetdb/sql/pythonize.py +++ b/clients/python2/monetdb/sql/pythonize.py @@ -52,14 +52,20 @@ def py_bool(data): def py_time(data): """ returns a python Time """ - return datetime.datetime.strptime(data, '%H:%M:%S').time() + if '.' in data: + return datetime.datetime.strptime(data, '%H:%M:%S.%f').time() + else: + return datetime.datetime.strptime(data, '%H:%M:%S').time() def py_timetz(data): """ returns a python Time where data contains a tz code """ t, timezone_delta = _extract_timezone(data) - return (datetime.datetime.strptime(t, '%H:%M:%S.%f') + timezone_delta).time() + if '.' in t: + return (datetime.datetime.strptime(t, '%H:%M:%S.%f') + timezone_delta).time() + else: + return (datetime.datetime.strptime(t, '%H:%M:%S') + timezone_delta).time() def py_date(data): @@ -71,14 +77,19 @@ def py_date(data): def py_timestamp(data): """ Returns a python Timestamp """ - return datetime.datetime.strptime(data, '%Y-%m-%d %H:%M:%S.%f') - + if '.' in data: + return datetime.datetime.strptime(data, '%Y-%m-%d %H:%M:%S.%f') + else: + return datetime.datetime.strptime(data, '%Y-%m-%d %H:%M:%S') def py_timestamptz(data): """ Returns a python Timestamp where data contains a tz code """ dt, timezone_delta = _extract_timezone(data) - return datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S.%f') + timezone_delta + if '.' in dt: + return datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S.%f') + timezone_delta + else: + return datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S') + timezone_delta mapping = { diff --git a/clients/python3/monetdb/sql/pythonize.py b/clients/python3/monetdb/sql/pythonize.py --- a/clients/python3/monetdb/sql/pythonize.py +++ b/clients/python3/monetdb/sql/pythonize.py @@ -56,14 +56,20 @@ def py_bool(data): def py_time(data): """ returns a python Time """ - return datetime.datetime.strptime(data, '%H:%M:%S').time() + if '.' in data: + return datetime.datetime.strptime(data, '%H:%M:%S.%f').time() + else: + return datetime.datetime.strptime(data, '%H:%M:%S').time() def py_timetz(data): """ returns a python Time where data contains a tz code """ t, timezone_delta = _extract_timezone(data) - return (datetime.datetime.strptime(t, '%H:%M:%S.%f') + timezone_delta).time() + if '.' in t: + return (datetime.datetime.strptime(t, '%H:%M:%S.%f') + timezone_delta).time() + else: + return (datetime.datetime.strptime(t, '%H:%M:%S') + timezone_delta).time() def py_date(data): @@ -75,14 +81,19 @@ def py_date(data): def py_timestamp(data): """ Returns a python Timestamp """ - return datetime.datetime.strptime(data, '%Y-%m-%d %H:%M:%S.%f') - + if '.' in data: + return datetime.datetime.strptime(data, '%Y-%m-%d %H:%M:%S.%f') + else: + return datetime.datetime.strptime(data, '%Y-%m-%d %H:%M:%S') def py_timestamptz(data): """ Returns a python Timestamp where data contains a tz code """ dt, timezone_delta = _extract_timezone(data) - return datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S.%f') + timezone_delta + if '.' in dt: + return datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S.%f') + timezone_delta + else: + return datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S') + timezone_delta mapping = { diff --git a/common/stream/stream.c b/common/stream/stream.c --- a/common/stream/stream.c +++ b/common/stream/stream.c @@ -190,7 +190,7 @@ mnstr_init(void) ssize_t mnstr_read(stream *s, void *buf, size_t elmsize, size_t cnt) { - if (s == NULL) + if (s == NULL || buf == NULL) return -1; #ifdef STREAM_DEBUG printf("read %s " SZFMT " " SZFMT "\n", s->name ? s->name : "<unnamed>", elmsize, cnt); @@ -209,7 +209,7 @@ mnstr_readline(stream *s, void *buf, siz { char *b = buf, *start = buf; - if (s == NULL) + if (s == NULL || buf == NULL) return -1; #ifdef STREAM_DEBUG printf("readline %s " SZFMT "\n", s->name ? s->name : "<unnamed>", maxcnt); @@ -355,7 +355,7 @@ mnstr_fsync(stream *s) int mnstr_fgetpos(stream *s, lng *p) { - if (s == NULL) + if (s == NULL || p == NULL) return -1; #ifdef STREAM_DEBUG printf("fgetpos %s\n", s->name ? s->name : "<unnamed>"); @@ -494,24 +494,25 @@ get_extention(const char *file) static void destroy(stream *s) { - free(s->name); + if (s->name) + free(s->name); free(s); } static char * error(stream *s) { - char buf[BUFSIZ]; + char buf[128]; switch (s->errnr) { case MNSTR_OPEN_ERROR: - snprintf(buf, BUFSIZ, "error could not open file %s\n", s->name); + snprintf(buf, sizeof(buf), "error could not open file %s\n", s->name); return strdup(buf); case MNSTR_READ_ERROR: - snprintf(buf, BUFSIZ, "error reading file %s\n", s->name); + snprintf(buf, sizeof(buf), "error reading file %s\n", s->name); return strdup(buf); case MNSTR_WRITE_ERROR: - snprintf(buf, BUFSIZ, "error writing file %s\n", s->name); + snprintf(buf, sizeof(buf), "error writing file %s\n", s->name); return strdup(buf); case MNSTR_TIMEOUT: snprintf(buf, BUFSIZ, "timeout on %s\n", s->name); @@ -565,6 +566,11 @@ file_read(stream *s, void *buf, size_t e FILE *fp = (FILE *) s->stream_data.p; size_t rc = 0; + if (fp == NULL) { + s->errnr = MNSTR_READ_ERROR; + return -1; + } + if (!feof(fp)) { if (ferror(fp) || ((rc = fread(buf, elmsize, cnt, fp)) == 0 && @@ -579,10 +585,17 @@ file_read(stream *s, void *buf, size_t e static ssize_t file_write(stream *s, const void *buf, size_t elmsize, size_t cnt) { + FILE *fp = (FILE *) s->stream_data.p; + + if (fp == NULL) { + s->errnr = MNSTR_WRITE_ERROR; + return -1; + } + if (elmsize && cnt) { - size_t rc = fwrite(buf, elmsize, cnt, (FILE *) s->stream_data.p); - - if (ferror((FILE *) s->stream_data.p)) { + size_t rc = fwrite(buf, elmsize, cnt, fp); + + if (ferror(fp)) { s->errnr = MNSTR_WRITE_ERROR; return -1; } @@ -613,7 +626,8 @@ file_clrerr(stream *s) { FILE *fp = (FILE *) s->stream_data.p; - clearerr(fp); + if (fp) + clearerr(fp); } static int @@ -621,7 +635,7 @@ file_flush(stream *s) { FILE *fp = (FILE *) s->stream_data.p; - if (s->access == ST_WRITE && fflush(fp) < 0) { + if (fp == NULL || (s->access == ST_WRITE && fflush(fp) < 0)) { s->errnr = MNSTR_WRITE_ERROR; return -1; } @@ -634,19 +648,20 @@ file_fsync(stream *s) FILE *fp = (FILE *) s->stream_data.p; - if (s->access == ST_WRITE + if (fp == NULL || + (s->access == ST_WRITE #ifdef NATIVE_WIN32 - && _commit(_fileno(fp)) < 0 + && _commit(_fileno(fp)) < 0 #else #ifdef HAVE_FDATASYNC - && fdatasync(fileno(fp)) < 0 + && fdatasync(fileno(fp)) < 0 #else #ifdef HAVE_FSYNC - && fsync(fileno(fp)) < 0 + && fsync(fileno(fp)) < 0 #endif #endif #endif - ) { + )) { s->errnr = MNSTR_WRITE_ERROR; return -1; } @@ -658,6 +673,8 @@ file_fgetpos(stream *s, lng *p) { FILE *fp = (FILE *) s->stream_data.p; + if (fp == NULL || p == NULL) + return -1; #if defined(NATIVE_WIN32) && _MSC_VER >= 1400 /* Visual Studio 2005 */ *p = (lng) _ftelli64(fp); /* returns __int64 */ #else @@ -676,6 +693,8 @@ file_fsetpos(stream *s, lng p) int res = 0; FILE *fp = (FILE *) s->stream_data.p; + if (fp == NULL) + return -1; #if defined(NATIVE_WIN32) && _MSC_VER >= 1400 /* Visual Studio 2005 */ res = _fseeki64(fp, (__int64) p, SEEK_SET); #else @@ -705,7 +724,7 @@ open_stream(const char *filename, const stream *s; FILE *fp; lng pos; - char buf[4]; + char buf[UTF8BOMLENGTH + 1]; if ((s = create_stream(filename)) == NULL) return NULL; @@ -727,7 +746,7 @@ open_stream(const char *filename, const * mark the stream as being a UTF-8 stream */ if (flags[0] == 'r' && file_fgetpos(s, &pos) == 0) { - if (file_read(s, buf, 1, UTF8BOMLENGTH) == 3 && + if (file_read(s, buf, 1, UTF8BOMLENGTH) == UTF8BOMLENGTH && strncmp(buf, UTF8BOM, UTF8BOMLENGTH) == 0) s->isutf8 = 1; else @@ -747,6 +766,11 @@ stream_gzread(stream *s, void *buf, size int size = (int) (elmsize * cnt); int err = 0; + if (fp == NULL) { + s->errnr = MNSTR_READ_ERROR; + return -1; + } + if (!gzeof(fp)) { size = gzread(fp, buf, size); if (gzerror(fp, &err) != NULL && err < 0) { @@ -765,6 +789,11 @@ stream_gzwrite(stream *s, const void *bu _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list