Changeset: f37c6a7f3840 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f37c6a7f3840 Modified Files: common/stream/stream.c gdk/gdk_atoms.c java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java monetdb5/mal/mal_atom.c monetdb5/mal/mal_builder.c monetdb5/mal/mal_factory.c monetdb5/mal/mal_instruction.c monetdb5/mal/mal_interpreter.c monetdb5/mal/mal_linker.c monetdb5/mal/mal_module.c monetdb5/mal/mal_namespace.c monetdb5/mal/mal_parser.c monetdb5/mal/mal_profiler.c monetdb5/mal/mal_resolve.c monetdb5/mal/mal_session.c monetdb5/modules/atoms/inet.c monetdb5/modules/mal/bbp.c monetdb5/optimizer/opt_centipede.c monetdb5/optimizer/opt_macro.c monetdb5/optimizer/opt_mapreduce.c monetdb5/optimizer/opt_octopus.c monetdb5/optimizer/opt_pushselect.c monetdb5/scheduler/run_octopus.c monetdb5/scheduler/srvpool.c sql/backends/monet5/sql.c sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_scenario.c sql/common/sql_string.c sql/server/rel_psm.c Branch: default Log Message:
Merge with Jan2014 branch. diffs (truncated from 3351 to 300 lines): diff --git a/common/stream/stream.c b/common/stream/stream.c --- a/common/stream/stream.c +++ b/common/stream/stream.c @@ -3111,10 +3111,12 @@ bstream_read(bstream *s, size_t size) return 0; if (s->pos > 0) { - if (s->pos < s->len) + if (s->pos < s->len) { /* move all data and end of string marker */ memmove(s->buf, s->buf + s->pos, s->len - s->pos + 1); - s->len -= s->pos; + s->len -= s->pos; + } else + s->len = 0; s->pos = 0; } @@ -3159,10 +3161,12 @@ bstream_readline(bstream *s) return 0; if (s->pos > 0 && s->len + size >= s->size) { - if (s->pos < s->len) + if (s->pos < s->len) { /* move all data and end of string marker */ memmove(s->buf, s->buf + s->pos, s->len - s->pos + 1); - s->len -= s->pos; + s->len -= s->pos; + } else + s->len = 0; s->pos = 0; } diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c --- a/gdk/gdk_atoms.c +++ b/gdk/gdk_atoms.c @@ -167,7 +167,7 @@ ATOMallocate(const char *id) if (strlen(id) >= IDLENGTH) GDKfatal("ATOMallocate: name too long"); memset(BATatoms + t, 0, sizeof(atomDesc)); - strncpy(BATatoms[t].name, id, IDLENGTH); + snprintf(BATatoms[t].name, IDLENGTH, "%s", id); BATatoms[t].size = sizeof(int); /* default */ BATatoms[t].align = sizeof(int); /* default */ BATatoms[t].linear = 1; /* default */ @@ -321,7 +321,8 @@ ATOMformat(int t, const void *p, char ** { int (*tostr) (str *, int *, const void *); - if (p && (t >= 0) && (t < GDKatomcnt) && (tostr = BATatoms[t].atomToStr)) { + if (p && 0 <= t && t < GDKatomcnt && + (tostr = BATatoms[t].atomToStr)) { int sz = 0, l = (*tostr) (buf, &sz, p); return l; @@ -329,8 +330,7 @@ ATOMformat(int t, const void *p, char ** *buf = GDKmalloc(4); if (*buf == NULL) return -1; - strncpy(*buf, "nil", 4); - return 3; + return snprintf(*buf, 4, "nil"); } ptr @@ -377,8 +377,7 @@ TYPE##ToStr(char **dst, int *len, const { \ atommem(char, TYPE##Strlen); \ if (*src == TYPE##_nil) { \ - strncpy(*dst, "nil", *len); \ - return 3; \ + return snprintf(*dst, *len, "nil"); \ } \ snprintf(*dst, *len, FMT, FMTCAST *src); \ return (int) strlen(*dst); \ @@ -411,8 +410,7 @@ voidToStr(str *dst, int *len, void *src) (void) src; atommem(char, 4); - strncpy(*dst, "nil", *len); - return 3; + return snprintf(*dst, *len, "nil"); } #endif @@ -468,15 +466,11 @@ bitToStr(char **dst, int *len, const bit { atommem(char, 6); - if (*src == bit_nil) { - strncpy(*dst, "nil", *len); - return 3; - } else if (*src) { - strncpy(*dst, "true", *len); - return 4; - } - strncpy(*dst, "false", *len); - return 5; + if (*src == bit_nil) + return snprintf(*dst, *len, "nil"); + if (*src) + return snprintf(*dst, *len, "true"); + return snprintf(*dst, *len, "false"); } static bit * @@ -538,13 +532,11 @@ batToStr(char **dst, int *len, const bat if (b == bat_nil || (s = BBPname(b)) == NULL || *s == 0) { atommem(char, 4); - strncpy(*dst, "nil", *len); - return 3; + return snprintf(*dst, *len, "nil"); } i = (int) (strlen(s) + 4); atommem(char, i); - snprintf(*dst, *len, "<%s>", s); - return (int) strlen(*dst); + return snprintf(*dst, *len, "<%s>", s); } static bat * @@ -1486,8 +1478,7 @@ strToStr(char **dst, int *len, const cha if (GDK_STRNIL((str) src)) { atommem(char, 4); - strncpy(*dst, "nil", *len); - return 3; + return snprintf(*dst, *len, "nil"); } else { int sz = escapedStrlen(src, NULL, NULL, '"'); atommem(char, sz + 3); @@ -1701,11 +1692,9 @@ OIDtoStr(char **dst, int *len, const oid atommem(char, oidStrlen); if (*src == oid_nil) { - strncpy(*dst, "nil", *len); - return 3; + return snprintf(*dst, *len, "nil"); } - snprintf(*dst, *len, OIDFMT "@0", *src); - return (int) strlen(*dst); + return snprintf(*dst, *len, OIDFMT "@0", *src); } atomDesc BATatoms[MAXATOMS] = { diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java @@ -1276,8 +1276,23 @@ public class MonetPreparedStatement * @throws SQLFeatureNotSupportedException the JDBC driver does * not support this method */ - public void setClob(int i, Reader x) throws SQLException { - throw new SQLFeatureNotSupportedException("setClob(int, Reader) not supported", "0A000"); + public void setClob(int i, Reader reader) throws SQLException { + if (reader == null) { + setNull(i, -1); + return; + } + // Some buffer. Size of 8192 is default for BufferedReader, so... + char[] arr = new char[8192]; + StringBuffer buf = new StringBuffer(); + int numChars; + try { + while ((numChars = reader.read(arr, 0, arr.length)) > 0) { + buf.append(arr, 0, numChars); + } + setString(i, buf.toString()); + } catch (IOException e) { + throw new SQLException(e); + } } /** @@ -1298,11 +1313,10 @@ public class MonetPreparedStatement * @throws SQLException if a database access error occurs */ public void setClob(int i, Reader reader, long length) throws SQLException { - if (reader == null) { + if (reader == null || length < 0) { setNull(i, -1); return; } - // simply serialise the CLOB into a variable for now... far from // efficient, but might work for a few cases... CharBuffer buf = CharBuffer.allocate((int)length); // have to down cast :( @@ -1312,6 +1326,8 @@ public class MonetPreparedStatement throw new SQLException("failed to read from stream: " + e.getMessage(), "M1M25"); } + // We have to rewind the buffer, because otherwise toString() returns "". + buf.rewind(); setString(i, buf.toString()); } diff --git a/monetdb5/mal/mal_atom.c b/monetdb5/mal/mal_atom.c --- a/monetdb5/mal/mal_atom.c +++ b/monetdb5/mal/mal_atom.c @@ -55,7 +55,7 @@ int malAtomProperty(MalBlkPtr mb, InstrP assert(pci != 0); name = getFunctionId(pci); tpe = getTypeIndex(getModuleId(pci), (int)strlen(getModuleId(pci)), TYPE_any); - if (tpe < 0 || tpe >= GDKatomcnt) + if (tpe < 0 || tpe >= MAXATOMS) return 0; assert(pci->fcn != NULL); switch (name[0]) { @@ -226,7 +226,7 @@ int malAtomSize(int size, int align, cha void showAtoms(stream *fd) { int i; - for (i = 0; BATatoms[i].name[0] && i < MAXATOMS; i++) { + for (i = 0; i < MAXATOMS && BATatoms[i].name[0]; i++) { mnstr_printf(fd, "%s", BATatoms[i].name); if (BATatoms[i + 1].name[0]) mnstr_printf(fd, ","); } diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c --- a/monetdb5/mal/mal_builder.c +++ b/monetdb5/mal/mal_builder.c @@ -36,8 +36,17 @@ newAssignment(MalBlkPtr mb) { InstrPtr q = newInstruction(mb,ASSIGNsymbol); - getArg(q,0)= newTmpVariable(mb,TYPE_any); + if (q == NULL) + return NULL; + if ((getArg(q,0)= newTmpVariable(mb,TYPE_any)) < 0) { + freeInstruction(q); + return NULL; + } pushInstruction(mb, q); + if (mb->errors) { + freeInstruction(q); + return NULL; + } return q; } @@ -46,10 +55,20 @@ newStmt(MalBlkPtr mb, char *module, char { InstrPtr q = newInstruction(mb,ASSIGNsymbol); - setModuleId(q, (module) ? putName(module, strlen(module)) : NULL); - setFunctionId(q, (name) ? putName(name, strlen(name)) : NULL); + if (q == NULL) + return NULL; + setModuleId(q, putName(module, strlen(module))); + setFunctionId(q, putName(name, strlen(name))); setDestVar(q, newTmpVariable(mb, TYPE_any)); + if (getDestVar(q) < 0) { + freeInstruction(q); + return NULL; + } pushInstruction(mb, q); + if (mb->errors) { + freeInstruction(q); + return NULL; + } return q; } @@ -58,10 +77,20 @@ newStmt1(MalBlkPtr mb, str module, char { InstrPtr q = newInstruction(mb,ASSIGNsymbol); - setModuleId(q, module); - setFunctionId(q, (name) ? putName(name, strlen(name)) : NULL); + if (q == NULL) + return NULL; + setModuleId(q, putName(module, strlen(module))); + setFunctionId(q, putName(name, strlen(name))); setDestVar(q, newTmpVariable(mb, TYPE_any)); + if (getDestVar(q) < 0) { + freeInstruction(q); + return NULL; + } pushInstruction(mb, q); + if (mb->errors) { + freeInstruction(q); + return NULL; + } return q; } @@ -70,10 +99,20 @@ newStmt2(MalBlkPtr mb, str module, char { InstrPtr q = newInstruction(mb,ASSIGNsymbol); - setModuleId(q, module); - setFunctionId(q, name); + if (q == NULL) + return NULL; + setModuleId(q, putName(module, strlen(module))); + setFunctionId(q, putName(name, strlen(name))); setDestVar(q, newTmpVariable(mb, TYPE_any)); + if (getDestVar(q) < 0) { + freeInstruction(q); + return NULL; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list