From 425dc6d66f8c9786bb678527e4aa973da724d71b Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Tue, 10 Sep 2019 15:57:48 +0200 Subject: [PATCH 1/3] - Remove some incorrect compile flags Just keep the /MDd flag but only for Windows Debug REST compile modified: storage/connect/CMakeLists.txt - Add a trace to EvalColumns modified: storage/connect/connect.cc - Remove a file not belonging to CONNECT deleted: rest.h --- storage/connect/CMakeLists.txt | 9 +++++---- storage/connect/connect.cc | 5 ++++- storage/connect/rest.h | 33 --------------------------------- 3 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 storage/connect/rest.h diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index fd006e104c1..be5c7034c3b 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -68,10 +68,6 @@ ELSE(NOT UNIX) tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h) # Add exception handling to the CONNECT project) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") - SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") - SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD") - SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD") SET(IPHLPAPI_LIBRARY iphlpapi.lib) IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang)) # Connect does not work with clang-cl @@ -324,6 +320,11 @@ IF(CONNECT_WITH_REST) # If needed edit next line to set the path to libcpprest.so SET(REST_LIBRARY -lcpprest) MESSAGE (STATUS ${REST_LIBRARY}) + ELSE(NOT UNIX) +# Next line sets debug compile mode matching cpprest_2_10d.dll +# when it was binary installed (can be change later in Visual Studio) +# Comment it out if not needed depending on your cpprestsdk installation. + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") ENDIF(UNIX) SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h) add_definitions(-DREST_SUPPORT) diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index b1078de8eaa..461391d2896 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -16,7 +16,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /***********************************************************************/ -/* Author Olivier BERTRAND bertrandop@gmail.com 2004-2017 */ +/* Author Olivier BERTRAND bertrandop@gmail.com 2004-2019 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -389,6 +389,9 @@ RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool reset, bool mrr) try { for (colp = tdbp->GetColumns(); rc == RC_OK && colp; colp = colp->GetNext()) { + xtrc(2, "Going to read column %s of table %s\n", + colp->GetName(), tdbp->GetName()); + if (reset) colp->Reset(); diff --git a/storage/connect/rest.h b/storage/connect/rest.h deleted file mode 100644 index f1d77e0a279..00000000000 --- a/storage/connect/rest.h +++ /dev/null @@ -1,33 +0,0 @@ -/***********************************************************************/ -/* Definitions needed by the included files. */ -/***********************************************************************/ -#if !defined(MY_GLOBAL_H) -#define MY_GLOBAL_H -typedef unsigned int uint; -typedef unsigned int uint32; -typedef unsigned short ushort; -typedef unsigned long ulong; -typedef unsigned long DWORD; -typedef char *LPSTR; -typedef const char *LPCSTR; -typedef int BOOL; -#if defined(_WINDOWS) -typedef void *HANDLE; -#else -typedef int HANDLE; -#endif -typedef char *PSZ; -typedef const char *PCSZ; -typedef unsigned char BYTE; -typedef unsigned char uchar; -typedef long long longlong; -typedef unsigned long long ulonglong; -typedef char my_bool; -struct charset_info_st {}; -typedef const charset_info_st CHARSET_INFO; -#define FALSE 0 -#define TRUE 1 -#define Item char -#define MY_MAX(a,b) ((a>b)?(a):(b)) -#define MY_MIN(a,b) ((a Date: Wed, 16 Oct 2019 17:40:49 +0200 Subject: [PATCH 2/3] Some small changes. =================== - Fix unhandled throws, add some trace + typo modified: storage/connect/jdbconn.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp --- storage/connect/jdbconn.cpp | 11 +- storage/connect/tabodbc.cpp | 6 +- storage/connect/valblk.cpp | 4 +- storage/connect/value.cpp | 587 ++++++++++++++++++------------------ 4 files changed, 311 insertions(+), 297 deletions(-) diff --git a/storage/connect/jdbconn.cpp b/storage/connect/jdbconn.cpp index e0aca3333e6..2cb75e0adc1 100644 --- a/storage/connect/jdbconn.cpp +++ b/storage/connect/jdbconn.cpp @@ -1196,9 +1196,14 @@ int JDBConn::GetResultSize(PCSZ sql, PCOL colp) if ((rc = ExecuteQuery(sql)) != RC_OK) return -1; - if ((rc = Fetch()) > 0) - SetColumnValue(1, NULL, colp->GetValue()); - else + if ((rc = Fetch()) > 0) { + try { + SetColumnValue(1, NULL, colp->GetValue()); + } catch (...) { + return -4; + } // end catch + + } else return -2; if ((rc = Fetch()) != 0) diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index 0fa117c3d2f..ba5c65e2c94 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -605,8 +605,10 @@ bool TDBODBC::OpenDB(PGLOBAL g) Cnp->InitValue(g); if ((n = Ocp->GetResultSize(Query->GetStr(), Cnp)) < 0) { - strcpy(g->Message, "Cannot get result size"); - return true; + char* msg = PlugDup(g, g->Message); + + sprintf(g->Message, "Get result size: %s (rc=%d)", msg, n); + return true; } else if (n) { Ocp->m_Rows = n; diff --git a/storage/connect/valblk.cpp b/storage/connect/valblk.cpp index 73ca135691c..d6c4218265b 100644 --- a/storage/connect/valblk.cpp +++ b/storage/connect/valblk.cpp @@ -206,6 +206,7 @@ void VALBLK::ChkIndx(int n) { if (n < 0 || n >= Nval) { PGLOBAL& g = Global; + xtrc(1, "ChkIndx: n=%d Nval=%d\n", n, Nval); strcpy(g->Message, MSG(BAD_VALBLK_INDX)); throw Type; } // endif n @@ -216,7 +217,8 @@ void VALBLK::ChkTyp(PVAL v) { if (Check && (Type != v->GetType() || Unsigned != v->IsUnsigned())) { PGLOBAL& g = Global; - strcpy(g->Message, MSG(VALTYPE_NOMATCH)); + xtrc(1, "ChkTyp: Type=%d valType=%d\n", Type, v->GetType()); + strcpy(g->Message, MSG(VALTYPE_NOMATCH)); throw Type; } // endif Type diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index d9330a68a15..158495de26c 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -123,7 +123,7 @@ ulonglong CharToNumber(const char *p, int n, ulonglong maxval, case '+': p++; break; - } // endswitch *p + } // endswitch *p for (val = 0; p < p2 && (c = (uchar)(*p - '0')) < 10; p++) if (val > (maxval - c) / 10) { @@ -140,7 +140,7 @@ ulonglong CharToNumber(const char *p, int n, ulonglong maxval, /* GetTypeName: returns the PlugDB internal type name. */ /***********************************************************************/ PCSZ GetTypeName(int type) - { +{ PCSZ name; switch (type) { @@ -155,17 +155,17 @@ PCSZ GetTypeName(int type) case TYPE_BIN: name = "BINARY"; break; case TYPE_PCHAR: name = "PCHAR"; break; default: name = "UNKNOWN"; break; - } // endswitch type + } // endswitch type return name; - } // end of GetTypeName +} // end of GetTypeName /***********************************************************************/ /* GetTypeSize: returns the PlugDB internal type size. */ /***********************************************************************/ int GetTypeSize(int type, int len) { - switch (type) { + switch (type) { case TYPE_DECIM: case TYPE_BIN: case TYPE_STRING: len = len * sizeof(char); break; @@ -177,16 +177,16 @@ int GetTypeSize(int type, int len) case TYPE_TINY: len = sizeof(char); break; case TYPE_PCHAR: len = sizeof(char*); break; default: len = -1; - } // endswitch type + } // endswitch type return len; - } // end of GetTypeSize +} // end of GetTypeSize /***********************************************************************/ /* GetFormatType: returns the FORMAT character(s) according to type. */ /***********************************************************************/ const char *GetFormatType(int type) - { +{ const char *c = "X"; switch (type) { @@ -200,16 +200,16 @@ const char *GetFormatType(int type) case TYPE_DECIM: c = "M"; break; case TYPE_BIN: c = "B"; break; case TYPE_PCHAR: c = "P"; break; - } // endswitch type + } // endswitch type return c; - } // end of GetFormatType +} // end of GetFormatType /***********************************************************************/ /* GetFormatType: returns the FORMAT type according to character. */ /***********************************************************************/ int GetFormatType(char c) - { +{ int type = TYPE_ERROR; switch (c) { @@ -223,31 +223,31 @@ int GetFormatType(char c) case 'M': type = TYPE_DECIM; break; case 'B': type = TYPE_BIN; break; case 'P': type = TYPE_PCHAR; break; - } // endswitch type + } // endswitch type return type; - } // end of GetFormatType +} // end of GetFormatType /***********************************************************************/ /* IsTypeChar: returns true for character type(s). */ /***********************************************************************/ bool IsTypeChar(int type) - { +{ switch (type) { case TYPE_STRING: case TYPE_DECIM: case TYPE_BIN: return true; - } // endswitch type + } // endswitch type return false; - } // end of IsTypeChar +} // end of IsTypeChar /***********************************************************************/ /* IsTypeNum: returns true for numeric types. */ /***********************************************************************/ bool IsTypeNum(int type) - { +{ switch (type) { case TYPE_INT: case TYPE_BIGINT: @@ -258,16 +258,16 @@ bool IsTypeNum(int type) case TYPE_TINY: case TYPE_DECIM: return true; - } // endswitch type + } // endswitch type return false; - } // end of IsTypeNum +} // end of IsTypeNum /***********************************************************************/ /* GetFmt: returns the format to use with a typed value. */ /***********************************************************************/ const char *GetFmt(int type, bool un) - { +{ const char *fmt; switch (type) { @@ -278,10 +278,10 @@ const char *GetFmt(int type, bool un) case TYPE_DOUBLE: fmt = "%.*lf"; break; case TYPE_BIN: fmt = "%*x"; break; default: fmt = (un) ? "%u" : "%d"; break; - } // endswitch Type + } // endswitch Type return fmt; - } // end of GetFmt +} // end of GetFmt /***********************************************************************/ /* ConvertType: what this function does is to determine the type to */ @@ -293,7 +293,7 @@ const char *GetFmt(int type, bool un) /* IsType... functions so match does not prevent correct setting. */ /***********************************************************************/ int ConvertType(int target, int type, CONV kind, bool match) - { +{ switch (kind) { case CNV_CHAR: if (match && (!IsTypeChar(target) || !IsTypeChar(type))) @@ -326,15 +326,15 @@ int ConvertType(int target, int type, CONV kind, bool match) : (target == TYPE_STRING || type == TYPE_STRING) ? TYPE_STRING : (target == TYPE_TINY || type == TYPE_TINY) ? TYPE_TINY : TYPE_ERROR; - } // endswitch kind + } // endswitch kind - } // end of ConvertType +} // end of ConvertType /***********************************************************************/ /* AllocateConstant: allocates a constant Value. */ /***********************************************************************/ PVAL AllocateValue(PGLOBAL g, void *value, short type, short prec) - { +{ PVAL valp; if (trace(1)) @@ -362,18 +362,18 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type, short prec) default: sprintf(g->Message, MSG(BAD_VALUE_TYPE), type); return NULL; - } // endswitch Type + } // endswitch Type valp->SetGlobal(g); return valp; - } // end of AllocateValue +} // end of AllocateValue /***********************************************************************/ /* Allocate a variable Value according to type, length and precision. */ /***********************************************************************/ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec, bool uns, PCSZ fmt) - { +{ PVAL valp; switch (type) { @@ -423,18 +423,18 @@ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec, default: sprintf(g->Message, MSG(BAD_VALUE_TYPE), type); return NULL; - } // endswitch type + } // endswitch type valp->SetGlobal(g); return valp; - } // end of AllocateValue +} // end of AllocateValue /***********************************************************************/ /* Allocate a constant Value converted to newtype. */ /* Can also be used to copy a Value eventually converted. */ /***********************************************************************/ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns) - { +{ PSZ p, sp; bool un = (uns < 0) ? false : (uns > 0) ? true : valp->IsUnsigned(); PVAL vp; @@ -495,13 +495,13 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns) default: sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype); return NULL; - } // endswitch type + } // endswitch type vp->SetNullable(valp->GetNullable()); vp->SetNull(valp->IsNull()); vp->SetGlobal(g); return vp; - } // end of AllocateValue +} // end of AllocateValue /* -------------------------- Class VALUE ---------------------------- */ @@ -509,7 +509,7 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns) /* Class VALUE protected constructor. */ /***********************************************************************/ VALUE::VALUE(int type, bool un) : Type(type) - { +{ Null = false; Nullable = false; Unsigned = un; @@ -517,13 +517,13 @@ VALUE::VALUE(int type, bool un) : Type(type) Prec = 0; Fmt = GetFmt(Type, Unsigned); Xfmt = GetXfmt(); - } // end of VALUE constructor +} // end of VALUE constructor /***********************************************************************/ /* VALUE GetXfmt: returns the extended format to use with typed value. */ /***********************************************************************/ const char *VALUE::GetXfmt(void) - { +{ const char *fmt; switch (Type) { @@ -537,7 +537,7 @@ const char *VALUE::GetXfmt(void) } // endswitch Type return fmt; - } // end of GetFmt +} // end of GetXFmt /***********************************************************************/ /* Returns a BYTE indicating the comparison between two values. */ @@ -545,20 +545,20 @@ const char *VALUE::GetXfmt(void) /* More than 1 bit can be set only in the case of TYPE_LIST. */ /***********************************************************************/ BYTE VALUE::TestValue(PVAL vp) - { +{ int n = CompareValue(vp); return (n > 0) ? 0x04 : (n < 0) ? 0x02 : 0x01; - } // end of TestValue +} // end of TestValue /***********************************************************************/ /* Compute a function on a string. */ /***********************************************************************/ bool VALUE::Compute(PGLOBAL g, PVAL *, int, OPVAL) - { +{ strcpy(g->Message, "Compute not implemented for this value type"); return true; - } // end of Compute +} // end of Compute /***********************************************************************/ /* Make file output of an object value. */ @@ -600,11 +600,11 @@ void VALUE::Prints(PGLOBAL g, char *ps, uint z) template TYPVAL::TYPVAL(TYPE n, int type, int prec, bool un) : VALUE(type, un) - { +{ Tval = n; Clen = sizeof(TYPE); Prec = prec; - } // end of TYPVAL constructor +} // end of TYPVAL constructor /***********************************************************************/ /* Return unsigned max value for the type. */ @@ -641,19 +641,19 @@ ulonglong TYPVAL::MaxVal(void) {return ULONGLONG_MAX;} /***********************************************************************/ template int TYPVAL::GetValLen(void) - { +{ char c[32]; - return sprintf(c, Fmt, Tval); - } // end of GetValLen + return snprintf(c, 32, Fmt, Tval); +} // end of GetValLen template <> int TYPVAL::GetValLen(void) - { +{ char c[32]; - return sprintf(c, Fmt, Prec, Tval); - } // end of GetValLen + return snprintf(c, 32, Fmt, Prec, Tval); +} // end of GetValLen /***********************************************************************/ /* TYPVAL SetValue: copy the value of another Value object. */ @@ -661,7 +661,7 @@ int TYPVAL::GetValLen(void) /***********************************************************************/ template bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) - { +{ if (valp != this) { if (chktype && Type != valp->GetType()) return true; @@ -671,10 +671,10 @@ bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) else Reset(); - } // endif valp + } // endif valp return false; - } // end of SetValue +} // end of SetValue template <> short TYPVAL::GetTypedValue(PVAL valp) @@ -717,7 +717,7 @@ uchar TYPVAL::GetTypedValue(PVAL valp) /***********************************************************************/ template bool TYPVAL::SetValue_char(const char *p, int n) - { +{ bool rc, minus; ulonglong maxval = MaxVal(); ulonglong val = CharToNumber(p, n, maxval, Unsigned, &minus, &rc); @@ -731,15 +731,15 @@ bool TYPVAL::SetValue_char(const char *p, int n) char buf[64]; htrc(strcat(strcat(strcpy(buf, " setting %s to: "), Fmt), "\n"), GetTypeName(Type), Tval); - } // endif trace + } // endif trace Null = false; return rc; - } // end of SetValue +} // end of SetValue template <> bool TYPVAL::SetValue_char(const char *p, int n) - { +{ if (p && n > 0) { char buf[64]; @@ -760,14 +760,14 @@ bool TYPVAL::SetValue_char(const char *p, int n) } // endif p return false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* TYPVAL SetValue: fill a typed value from a string. */ /***********************************************************************/ template void TYPVAL::SetValue_psz(PCSZ s) - { +{ if (s) { SetValue_char(s, (int)strlen(s)); Null = false; @@ -776,17 +776,17 @@ void TYPVAL::SetValue_psz(PCSZ s) Null = Nullable; } // endif p - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* TYPVAL SetValue: set value with a TYPE extracted from a block. */ /***********************************************************************/ template void TYPVAL::SetValue_pvblk(PVBLK blk, int n) - { +{ Tval = GetTypedValue(blk, n); Null = false; - } // end of SetValue +} // end of SetValue template <> int TYPVAL::GetTypedValue(PVBLK blk, int n) @@ -852,7 +852,7 @@ void TYPVAL::SetBinValue(void *p) /***********************************************************************/ template bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) - { +{ // Test on length was removed here until a variable in column give the // real field length. For BIN files the field length logically cannot // be different from the variable length because no conversion is done. @@ -876,40 +876,41 @@ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) Null = false; return false; - } // end of GetBinValue +} // end of GetBinValue /***********************************************************************/ /* TYPVAL ShowValue: get string representation of a typed value. */ /***********************************************************************/ template int TYPVAL::ShowValue(char *buf, int len) - { - return snprintf(buf, len + 1, Xfmt, len, Tval); - } // end of ShowValue +{ + return snprintf(buf, len, Xfmt, len, Tval); +} // end of ShowValue template <> int TYPVAL::ShowValue(char *buf, int len) - { +{ // TODO: use a more appropriate format to avoid possible truncation - return snprintf(buf, len + 1, Xfmt, len, Prec, Tval); - } // end of ShowValue + return snprintf(buf, len, Xfmt, len, Prec, Tval); +} // end of ShowValue /***********************************************************************/ /* TYPVAL GetCharString: get string representation of a typed value. */ /***********************************************************************/ template char *TYPVAL::GetCharString(char *p) - { +{ sprintf(p, Fmt, Tval); return p; - } // end of GetCharString +} // end of GetCharString template <> char *TYPVAL::GetCharString(char *p) - { - sprintf(p, Fmt, Prec, Tval); +{ + // Most callers use a 32 long buffer + snprintf(p, 32, Fmt, Prec, Tval); return p; - } // end of GetCharString +} // end of GetCharString #if 0 /***********************************************************************/ @@ -917,50 +918,50 @@ char *TYPVAL::GetCharString(char *p) /***********************************************************************/ template char *TYPVAL::GetShortString(char *p, int n) - { +{ sprintf(p, "%*hd", n, (short)Tval); return p; - } // end of GetShortString +} // end of GetShortString /***********************************************************************/ /* TYPVAL GetIntString: get int representation of a typed value. */ /***********************************************************************/ template char *TYPVAL::GetIntString(char *p, int n) - { +{ sprintf(p, "%*d", n, (int)Tval); return p; - } // end of GetIntString +} // end of GetIntString /***********************************************************************/ /* TYPVAL GetBigintString: get big int representation of a TYPE value.*/ /***********************************************************************/ template char *TYPVAL::GetBigintString(char *p, int n) - { +{ sprintf(p, "%*lld", n, (longlong)Tval); return p; - } // end of GetBigintString +} // end of GetBigintString /***********************************************************************/ /* TYPVAL GetFloatString: get double representation of a typed value. */ /***********************************************************************/ template char *TYPVAL::GetFloatString(char *p, int n, int prec) - { +{ sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, (double)Tval); return p; - } // end of GetFloatString +} // end of GetFloatString /***********************************************************************/ /* TYPVAL GetTinyString: get char representation of a typed value. */ /***********************************************************************/ template char *TYPVAL::GetTinyString(char *p, int n) - { +{ sprintf(p, "%*d", n, (int)(char)Tval); return p; - } // end of GetIntString +} // end of GetIntString #endif // 0 /***********************************************************************/ @@ -968,7 +969,7 @@ char *TYPVAL::GetTinyString(char *p, int n) /***********************************************************************/ template bool TYPVAL::IsEqual(PVAL vp, bool chktype) - { +{ if (this == vp) return true; else if (chktype && Type != vp->GetType()) @@ -980,7 +981,7 @@ bool TYPVAL::IsEqual(PVAL vp, bool chktype) else return (Tval == GetTypedValue(vp)); - } // end of IsEqual +} // end of IsEqual /***********************************************************************/ /* Compare values and returns 1, 0 or -1 according to comparison. */ @@ -988,7 +989,7 @@ bool TYPVAL::IsEqual(PVAL vp, bool chktype) /***********************************************************************/ template int TYPVAL::CompareValue(PVAL vp) - { +{ //assert(vp->GetType() == Type); // Process filtering on numeric values. @@ -998,7 +999,7 @@ int TYPVAL::CompareValue(PVAL vp) // htrc(" Comparing: val=%d,%d\n", Tval, n); return (Tval > n) ? 1 : (Tval < n) ? (-1) : 0; - } // end of CompareValue +} // end of CompareValue /***********************************************************************/ /* Return max type value if b is true, else min type value. */ @@ -1044,7 +1045,7 @@ uchar TYPVAL::MinMaxVal(bool b) /***********************************************************************/ template TYPE TYPVAL::SafeAdd(TYPE n1, TYPE n2) - { +{ PGLOBAL& g = Global; TYPE n = n1 + n2; @@ -1059,20 +1060,20 @@ TYPE TYPVAL::SafeAdd(TYPE n1, TYPE n2) } // endif's n2 return n; - } // end of SafeAdd +} // end of SafeAdd template <> inline double TYPVAL::SafeAdd(double n1, double n2) - { +{ return n1 + n2; - } // end of SafeAdd +} // end of SafeAdd /***********************************************************************/ /* SafeMult: multiply values and test whether overflow occurred. */ /***********************************************************************/ template TYPE TYPVAL::SafeMult(TYPE n1, TYPE n2) - { +{ PGLOBAL& g = Global; double n = (double)n1 * (double)n2; @@ -1087,20 +1088,20 @@ TYPE TYPVAL::SafeMult(TYPE n1, TYPE n2) } // endif's n2 return (TYPE)n; - } // end of SafeMult +} // end of SafeMult template <> inline double TYPVAL::SafeMult(double n1, double n2) - { +{ return n1 * n2; - } // end of SafeMult +} // end of SafeMult /***********************************************************************/ /* Compute defined functions for the type. */ /***********************************************************************/ template bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) - { +{ bool rc = false; TYPE val[2]; @@ -1127,14 +1128,14 @@ bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) default: rc = Compall(g, vp, np, op); break; - } // endswitch op + } // endswitch op return rc; - } // end of Compute +} // end of Compute template <> bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) - { +{ bool rc = false; double val[2]; @@ -1152,17 +1153,17 @@ bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) break; default: rc = Compall(g, vp, np, op); - } // endswitch op + } // endswitch op return rc; - } // end of Compute +} // end of Compute /***********************************************************************/ /* Compute a function for all types. */ /***********************************************************************/ template bool TYPVAL::Compall(PGLOBAL g, PVAL *vp, int np, OPVAL op) - { +{ TYPE val[2]; for (int i = 0; i < np; i++) @@ -1191,10 +1192,10 @@ bool TYPVAL::Compall(PGLOBAL g, PVAL *vp, int np, OPVAL op) // sprintf(g->Message, MSG(BAD_EXP_OPER), op); strcpy(g->Message, "Function not supported"); return true; - } // endswitch op + } // endswitch op return false; - } // end of Compall +} // end of Compall /***********************************************************************/ /* FormatValue: This function set vp (a STRING value) to the string */ @@ -1203,26 +1204,28 @@ bool TYPVAL::Compall(PGLOBAL g, PVAL *vp, int np, OPVAL op) /***********************************************************************/ template bool TYPVAL::FormatValue(PVAL vp, PCSZ fmt) - { - char *buf = (char*)vp->GetTo_Val(); // Should be big enough +{ + // This function is wrong and should never be called + assert(false); + char *buf = (char*)vp->GetTo_Val(); // Not big enough int n = sprintf(buf, fmt, Tval); return (n > vp->GetValLen()); - } // end of FormatValue +} // end of FormatValue /***********************************************************************/ /* TYPVAL SetFormat function (used to set SELECT output format). */ /***********************************************************************/ template bool TYPVAL::SetConstFormat(PGLOBAL g, FORMAT& fmt) - { +{ char c[32]; fmt.Type[0] = *GetFormatType(Type); fmt.Length = sprintf(c, Fmt, Tval); fmt.Prec = Prec; return false; - } // end of SetConstFormat +} // end of SetConstFormat /* -------------------------- Class STRING --------------------------- */ @@ -1230,19 +1233,19 @@ bool TYPVAL::SetConstFormat(PGLOBAL g, FORMAT& fmt) /* STRING public constructor from a constant string. */ /***********************************************************************/ TYPVAL::TYPVAL(PSZ s, short c) : VALUE(TYPE_STRING) - { +{ Strp = s; Len = strlen(s); Clen = Len; Ci = (c == 1); - } // end of STRING constructor +} // end of STRING constructor /***********************************************************************/ /* STRING public constructor from char. */ /***********************************************************************/ TYPVAL::TYPVAL(PGLOBAL g, PSZ s, int n, int c) : VALUE(TYPE_STRING) - { +{ Len = (g) ? n : (s) ? strlen(s) : 0; if (!s) { @@ -1260,89 +1263,89 @@ TYPVAL::TYPVAL(PGLOBAL g, PSZ s, int n, int c) Clen = Len; Ci = (c != 0); - } // end of STRING constructor +} // end of STRING constructor /***********************************************************************/ /* Get the tiny value represented by the Strp string. */ /***********************************************************************/ char TYPVAL::GetTinyValue(void) - { +{ bool m; ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX8, false, &m); return (m && val < INT_MAX8) ? (char)(-(signed)val) : (char)val; - } // end of GetTinyValue +} // end of GetTinyValue /***********************************************************************/ /* Get the unsigned tiny value represented by the Strp string. */ /***********************************************************************/ uchar TYPVAL::GetUTinyValue(void) - { +{ return (uchar)CharToNumber(Strp, strlen(Strp), UINT_MAX8, true); - } // end of GetUTinyValue +} // end of GetUTinyValue /***********************************************************************/ /* Get the short value represented by the Strp string. */ /***********************************************************************/ short TYPVAL::GetShortValue(void) - { +{ bool m; ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX16, false, &m); return (m && val < INT_MAX16) ? (short)(-(signed)val) : (short)val; - } // end of GetShortValue +} // end of GetShortValue /***********************************************************************/ /* Get the unsigned short value represented by the Strp string. */ /***********************************************************************/ ushort TYPVAL::GetUShortValue(void) - { +{ return (ushort)CharToNumber(Strp, strlen(Strp), UINT_MAX16, true); - } // end of GetUshortValue +} // end of GetUshortValue /***********************************************************************/ /* Get the integer value represented by the Strp string. */ /***********************************************************************/ int TYPVAL::GetIntValue(void) - { +{ bool m; ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX32, false, &m); return (m && val < INT_MAX32) ? (int)(-(signed)val) : (int)val; - } // end of GetIntValue +} // end of GetIntValue /***********************************************************************/ /* Get the unsigned integer value represented by the Strp string. */ /***********************************************************************/ uint TYPVAL::GetUIntValue(void) - { +{ return (uint)CharToNumber(Strp, strlen(Strp), UINT_MAX32, true); - } // end of GetUintValue +} // end of GetUintValue /***********************************************************************/ /* Get the big integer value represented by the Strp string. */ /***********************************************************************/ longlong TYPVAL::GetBigintValue(void) - { +{ bool m; ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX64, false, &m); return (m && val < INT_MAX64) ? (-(signed)val) : (longlong)val; - } // end of GetBigintValue +} // end of GetBigintValue /***********************************************************************/ /* Get the unsigned big integer value represented by the Strp string. */ /***********************************************************************/ ulonglong TYPVAL::GetUBigintValue(void) - { +{ return CharToNumber(Strp, strlen(Strp), ULONGLONG_MAX, true); - } // end of GetUBigintValue +} // end of GetUBigintValue /***********************************************************************/ /* STRING SetValue: copy the value of another Value object. */ /***********************************************************************/ bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) - { +{ if (valp != this) { if (chktype && (valp->GetType() != Type || valp->GetSize() > Len)) return true; @@ -1354,16 +1357,16 @@ bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) else Reset(); - } // endif valp + } // endif valp return false; - } // end of SetValue_pval +} // end of SetValue_pval /***********************************************************************/ /* STRING SetValue: fill string with chars extracted from a line. */ /***********************************************************************/ bool TYPVAL::SetValue_char(const char *cp, int n) - { +{ bool rc = false; if (!cp || n == 0) { @@ -1389,16 +1392,16 @@ bool TYPVAL::SetValue_char(const char *cp, int n) Reset(); Null = false; - } // endif p + } // endif cp return rc; - } // end of SetValue_char +} // end of SetValue_char /***********************************************************************/ /* STRING SetValue: fill string with another string. */ /***********************************************************************/ void TYPVAL::SetValue_psz(PCSZ s) - { +{ if (!s) { Reset(); Null = Nullable; @@ -1407,26 +1410,26 @@ void TYPVAL::SetValue_psz(PCSZ s) Null = false; } // endif s - } // end of SetValue_psz +} // end of SetValue_psz /***********************************************************************/ /* STRING SetValue: fill string with a string extracted from a block. */ /***********************************************************************/ void TYPVAL::SetValue_pvblk(PVBLK blk, int n) - { +{ // STRBLK's can return a NULL pointer PSZ vp = blk->GetCharString(Strp, n); if (vp != Strp) SetValue_psz(vp); - } // end of SetValue_pvblk +} // end of SetValue_pvblk /***********************************************************************/ /* STRING SetValue: get the character representation of an integer. */ /***********************************************************************/ void TYPVAL::SetValue(int n) - { +{ char buf[16]; PGLOBAL& g = Global; int k = sprintf(buf, "%d", n); @@ -1438,13 +1441,13 @@ void TYPVAL::SetValue(int n) SetValue_psz(buf); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of an uint. */ /***********************************************************************/ void TYPVAL::SetValue(uint n) - { +{ char buf[16]; PGLOBAL& g = Global; int k = sprintf(buf, "%u", n); @@ -1456,31 +1459,31 @@ void TYPVAL::SetValue(uint n) SetValue_psz(buf); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of a short int. */ /***********************************************************************/ void TYPVAL::SetValue(short i) - { +{ SetValue((int)i); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of a ushort int. */ /***********************************************************************/ void TYPVAL::SetValue(ushort i) - { +{ SetValue((uint)i); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of a big integer.*/ /***********************************************************************/ void TYPVAL::SetValue(longlong n) - { +{ char buf[24]; PGLOBAL& g = Global; int k = sprintf(buf, "%lld", n); @@ -1492,13 +1495,13 @@ void TYPVAL::SetValue(longlong n) SetValue_psz(buf); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of a big integer.*/ /***********************************************************************/ void TYPVAL::SetValue(ulonglong n) - { +{ char buf[24]; PGLOBAL& g = Global; int k = sprintf(buf, "%llu", n); @@ -1510,13 +1513,13 @@ void TYPVAL::SetValue(ulonglong n) SetValue_psz(buf); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of a double. */ /***********************************************************************/ void TYPVAL::SetValue(double f) - { +{ char *p, buf[64]; PGLOBAL& g = Global; int k = sprintf(buf, "%lf", f); @@ -1535,33 +1538,33 @@ void TYPVAL::SetValue(double f) SetValue_psz(buf); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of a tiny int. */ /***********************************************************************/ void TYPVAL::SetValue(char c) - { +{ SetValue((int)c); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetValue: get the character representation of a tiny int. */ /***********************************************************************/ void TYPVAL::SetValue(uchar c) - { +{ SetValue((uint)c); Null = false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* STRING SetBinValue: fill string with chars extracted from a line. */ /***********************************************************************/ void TYPVAL::SetBinValue(void *p) - { +{ SetValue_char((const char *)p, Len); - } // end of SetBinValue +} // end of SetBinValue /***********************************************************************/ /* GetBinValue: fill a buffer with the internal binary value. */ @@ -1570,7 +1573,7 @@ void TYPVAL::SetBinValue(void *p) /* Currently used by WriteColumn of binary files. */ /***********************************************************************/ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) - { +{ int len = (Null) ? 0 : strlen(Strp); if (len > buflen) @@ -1581,7 +1584,7 @@ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) } // endif go return false; - } // end of GetBinValue +} // end of GetBinValue /***********************************************************************/ /* STRING ShowValue: get string representation of a char value. */ @@ -1591,7 +1594,7 @@ int TYPVAL::ShowValue(char *buf, int buflen) int len = (Null) ? 0 : strlen(Strp); if (buf && buf != Strp) { - memset(buf, ' ', buflen + 1); + memset(buf, ' ', (size_t)buflen + 1); memcpy(buf, Strp, MY_MIN(len, buflen)); } // endif buf @@ -1602,15 +1605,15 @@ int TYPVAL::ShowValue(char *buf, int buflen) /* STRING GetCharString: get string representation of a char value. */ /***********************************************************************/ char *TYPVAL::GetCharString(char *) - { +{ return Strp; - } // end of GetCharString +} // end of GetCharString /***********************************************************************/ /* STRING compare value with another Value. */ /***********************************************************************/ bool TYPVAL::IsEqual(PVAL vp, bool chktype) - { +{ if (this == vp) return true; else if (chktype && Type != vp->GetType()) @@ -1625,14 +1628,14 @@ bool TYPVAL::IsEqual(PVAL vp, bool chktype) else // (!Ci) return !strcmp(Strp, vp->GetCharString(buf)); - } // end of IsEqual +} // end of IsEqual /***********************************************************************/ /* Compare values and returns 1, 0 or -1 according to comparison. */ /* This function is used for evaluation of numeric filters. */ /***********************************************************************/ int TYPVAL::CompareValue(PVAL vp) - { +{ int n; //assert(vp->GetType() == Type); @@ -1651,13 +1654,13 @@ int TYPVAL::CompareValue(PVAL vp) #endif // __WIN__ return (n > 0) ? 1 : (n < 0) ? -1 : 0; - } // end of CompareValue +} // end of CompareValue /***********************************************************************/ /* Compute a function on a string. */ /***********************************************************************/ bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) - { +{ char *p[2], val[2][32]; int i; @@ -1704,7 +1707,7 @@ bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) Null = false; return false; - } // end of Compute +} // end of Compute /***********************************************************************/ /* FormatValue: This function set vp (a STRING value) to the string */ @@ -1712,23 +1715,23 @@ bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) /* This function assumes that the format matches the value type. */ /***********************************************************************/ bool TYPVAL::FormatValue(PVAL vp, PCSZ fmt) - { +{ char *buf = (char*)vp->GetTo_Val(); // Should be big enough int n = sprintf(buf, fmt, Strp); return (n > vp->GetValLen()); - } // end of FormatValue +} // end of FormatValue /***********************************************************************/ /* STRING SetFormat function (used to set SELECT output format). */ /***********************************************************************/ bool TYPVAL::SetConstFormat(PGLOBAL, FORMAT& fmt) - { +{ fmt.Type[0] = 'C'; fmt.Length = Len; fmt.Prec = 0; return false; - } // end of SetConstFormat +} // end of SetConstFormat /***********************************************************************/ /* Make string output of an object value. */ @@ -1748,38 +1751,38 @@ void TYPVAL::Prints(PGLOBAL g, char *ps, uint z) /* DECIMAL public constructor from a constant string. */ /***********************************************************************/ DECVAL::DECVAL(PSZ s) : TYPVAL(s) - { +{ if (s) { char *p = strchr(Strp, '.'); Prec = (p) ? (int)(Len - (p - Strp)) : 0; - } // endif s + } // endif s Type = TYPE_DECIM; - } // end of DECVAL constructor +} // end of DECVAL constructor /***********************************************************************/ /* DECIMAL public constructor from char. */ /***********************************************************************/ DECVAL::DECVAL(PGLOBAL g, PSZ s, int n, int prec, bool uns) : TYPVAL(g, s, n + (prec ? 1 : 0) + (uns ? 0 : 1), 0) - { +{ Prec = prec; Unsigned = uns; Type = TYPE_DECIM; - } // end of DECVAL constructor +} // end of DECVAL constructor /***********************************************************************/ /* DECIMAL: Check whether the numerica value is equal to 0. */ /***********************************************************************/ bool DECVAL::IsZero(void) - { +{ for (int i = 0; Strp[i]; i++) if (!strchr("0 +-.", Strp[i])) return false; return true; - } // end of IsZero +} // end of IsZero /***********************************************************************/ /* DECIMAL: Reset value to zero. */ @@ -1797,7 +1800,7 @@ void DECVAL::Reset(void) Strp[i++] = '0'; } while (i < Prec + 2); - } // endif Prec + } // endif Prec Strp[i] = 0; } // end of Reset @@ -1806,9 +1809,9 @@ void DECVAL::Reset(void) /* DECIMAL ShowValue: get string representation right justified. */ /***********************************************************************/ int DECVAL::ShowValue(char *buf, int len) - { +{ return snprintf(buf, len + 1, Xfmt, len, Strp); - } // end of ShowValue +} // end of ShowValue /***********************************************************************/ /* GetBinValue: fill a buffer with the internal binary value. */ @@ -1817,7 +1820,7 @@ int DECVAL::ShowValue(char *buf, int len) /* Currently used by WriteColumn of binary files. */ /***********************************************************************/ bool DECVAL::GetBinValue(void *buf, int buflen, bool go) - { +{ int len = (Null) ? 0 : strlen(Strp); if (len > buflen) @@ -1825,16 +1828,16 @@ bool DECVAL::GetBinValue(void *buf, int buflen, bool go) else if (go) { memset(buf, ' ', buflen - len); memcpy((char*)buf + buflen - len, Strp, len); - } // endif go + } // endif go return false; - } // end of GetBinValue +} // end of GetBinValue /***********************************************************************/ /* DECIMAL compare value with another Value. */ /***********************************************************************/ bool DECVAL::IsEqual(PVAL vp, bool chktype) - { +{ if (this == vp) return true; else if (chktype && Type != vp->GetType()) @@ -1845,14 +1848,14 @@ bool DECVAL::IsEqual(PVAL vp, bool chktype) char buf[64]; return !strcmp(Strp, vp->GetCharString(buf)); - } // end of IsEqual +} // end of IsEqual /***********************************************************************/ /* Compare values and returns 1, 0 or -1 according to comparison. */ /* This function is used for evaluation of numeric filters. */ /***********************************************************************/ int DECVAL::CompareValue(PVAL vp) - { +{ //assert(vp->GetType() == Type); // Process filtering on numeric values. @@ -1862,7 +1865,7 @@ int DECVAL::CompareValue(PVAL vp) // htrc(" Comparing: val=%d,%d\n", f, n); return (f > n) ? 1 : (f < n) ? (-1) : 0; - } // end of CompareValue +} // end of CompareValue /* -------------------------- Class BINVAL --------------------------- */ @@ -1870,7 +1873,7 @@ int DECVAL::CompareValue(PVAL vp) /* BINVAL public constructor from bytes. */ /***********************************************************************/ BINVAL::BINVAL(PGLOBAL g, void *p, int cl, int n) : VALUE(TYPE_BIN) - { +{ assert(g); Len = n; Clen = cl; @@ -1881,19 +1884,19 @@ BINVAL::BINVAL(PGLOBAL g, void *p, int cl, int n) : VALUE(TYPE_BIN) memcpy(Binp, p, MY_MIN(Len,Clen)); Chrp = NULL; - } // end of BINVAL constructor +} // end of BINVAL constructor /***********************************************************************/ /* BINVAL: Check whether the hexadecimal value is equal to 0. */ /***********************************************************************/ bool BINVAL::IsZero(void) - { +{ for (int i = 0; i < Len; i++) if (((char*)Binp)[i] != 0) return false; return true; - } // end of IsZero +} // end of IsZero /***********************************************************************/ /* BINVAL: Reset value to zero. */ @@ -1908,77 +1911,77 @@ void BINVAL::Reset(void) /* Get the tiny value pointed by Binp. */ /***********************************************************************/ char BINVAL::GetTinyValue(void) - { +{ return *(char*)Binp; - } // end of GetTinyValue +} // end of GetTinyValue /***********************************************************************/ /* Get the unsigned tiny value pointed by Binp. */ /***********************************************************************/ uchar BINVAL::GetUTinyValue(void) - { +{ return *(uchar*)Binp; - } // end of GetUTinyValue +} // end of GetUTinyValue /***********************************************************************/ /* Get the short value pointed by Binp. */ /***********************************************************************/ short BINVAL::GetShortValue(void) - { +{ if (Len >= 2) return *(short*)Binp; else return (short)GetTinyValue(); - } // end of GetShortValue +} // end of GetShortValue /***********************************************************************/ /* Get the unsigned short value pointed by Binp. */ /***********************************************************************/ ushort BINVAL::GetUShortValue(void) - { +{ return (ushort)GetShortValue(); - } // end of GetUshortValue +} // end of GetUshortValue /***********************************************************************/ /* Get the integer value pointed by Binp. */ /***********************************************************************/ int BINVAL::GetIntValue(void) - { +{ if (Len >= 4) return *(int*)Binp; else return (int)GetShortValue(); - } // end of GetIntValue +} // end of GetIntValue /***********************************************************************/ /* Get the unsigned integer value pointed by Binp. */ /***********************************************************************/ uint BINVAL::GetUIntValue(void) - { +{ return (uint)GetIntValue(); - } // end of GetUintValue +} // end of GetUintValue /***********************************************************************/ /* Get the big integer value pointed by Binp. */ /***********************************************************************/ longlong BINVAL::GetBigintValue(void) - { +{ if (Len >= 8) return *(longlong*)Binp; else return (longlong)GetIntValue(); - } // end of GetBigintValue +} // end of GetBigintValue /***********************************************************************/ /* Get the unsigned big integer value pointed by Binp. */ /***********************************************************************/ ulonglong BINVAL::GetUBigintValue(void) - { +{ return (ulonglong)GetBigintValue(); - } // end of GetUBigintValue +} // end of GetUBigintValue /***********************************************************************/ /* Get the double value pointed by Binp. */ @@ -1998,7 +2001,7 @@ double BINVAL::GetFloatValue(void) /* BINVAL SetValue: copy the value of another Value object. */ /***********************************************************************/ bool BINVAL::SetValue_pval(PVAL valp, bool chktype) - { +{ bool rc = false; if (valp != this) { @@ -2018,16 +2021,16 @@ bool BINVAL::SetValue_pval(PVAL valp, bool chktype) } else Reset(); - } // endif valp + } // endif valp return rc; - } // end of SetValue_pval +} // end of SetValue_pval /***********************************************************************/ /* BINVAL SetValue: fill value with chars extracted from a line. */ /***********************************************************************/ bool BINVAL::SetValue_char(const char *p, int n) - { +{ bool rc; if (p && n > 0) { @@ -2047,13 +2050,13 @@ bool BINVAL::SetValue_char(const char *p, int n) } // endif p return rc; - } // end of SetValue_char +} // end of SetValue_char /***********************************************************************/ /* BINVAL SetValue: fill value with another string. */ /***********************************************************************/ void BINVAL::SetValue_psz(PCSZ s) - { +{ if (s) { int len = Len; @@ -2068,13 +2071,13 @@ void BINVAL::SetValue_psz(PCSZ s) Null = Nullable; } // endif s - } // end of SetValue_psz +} // end of SetValue_psz /***********************************************************************/ /* BINVAL SetValue: fill value with bytes extracted from a block. */ /***********************************************************************/ void BINVAL::SetValue_pvblk(PVBLK blk, int n) - { +{ // STRBLK's can return a NULL pointer void *vp = blk->GetValPtrEx(n); @@ -2097,13 +2100,13 @@ void BINVAL::SetValue_pvblk(PVBLK blk, int n) Null = false; } // endif vp - } // end of SetValue_pvblk +} // end of SetValue_pvblk /***********************************************************************/ /* BINVAL SetValue: get the binary representation of an integer. */ /***********************************************************************/ void BINVAL::SetValue(int n) - { +{ if (Clen >= 4) { if (Len > 4) memset(Binp, 0, Len); @@ -2113,13 +2116,13 @@ void BINVAL::SetValue(int n) } else SetValue((short)n); - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the binary representation of an uint. */ /***********************************************************************/ void BINVAL::SetValue(uint n) - { +{ if (Clen >= 4) { if (Len > 4) memset(Binp, 0, Len); @@ -2129,13 +2132,13 @@ void BINVAL::SetValue(uint n) } else SetValue((ushort)n); - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the binary representation of a short int. */ /***********************************************************************/ void BINVAL::SetValue(short i) - { +{ if (Clen >= 2) { if (Len > 2) memset(Binp, 0, Len); @@ -2145,13 +2148,13 @@ void BINVAL::SetValue(short i) } else SetValue((char)i); - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the binary representation of a ushort int. */ /***********************************************************************/ void BINVAL::SetValue(ushort i) - { +{ if (Clen >= 2) { if (Len > 2) memset(Binp, 0, Len); @@ -2161,13 +2164,13 @@ void BINVAL::SetValue(ushort i) } else SetValue((uchar)i); - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the binary representation of a big integer. */ /***********************************************************************/ void BINVAL::SetValue(longlong n) - { +{ if (Clen >= 8) { if (Len > 8) memset(Binp, 0, Len); @@ -2177,13 +2180,13 @@ void BINVAL::SetValue(longlong n) } else SetValue((int)n); - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the binary representation of a big integer. */ /***********************************************************************/ void BINVAL::SetValue(ulonglong n) - { +{ if (Clen >= 8) { if (Len > 8) memset(Binp, 0, Len); @@ -2192,13 +2195,14 @@ void BINVAL::SetValue(ulonglong n) Len = 8; } else SetValue((uint)n); - } // end of SetValue + +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the binary representation of a double. */ /***********************************************************************/ void BINVAL::SetValue(double n) - { +{ if (Len > 8) memset(Binp, 0, Len); @@ -2211,40 +2215,40 @@ void BINVAL::SetValue(double n) } else Len = 0; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the character binary of a tiny int. */ /***********************************************************************/ void BINVAL::SetValue(char c) - { +{ if (Len > 1) memset(Binp, 0, Len); *((char*)Binp) = c; Len = 1; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetValue: get the binary representation of a tiny int. */ /***********************************************************************/ void BINVAL::SetValue(uchar c) - { +{ if (Len > 1) memset(Binp, 0, Len); *((uchar*)Binp) = c; Len = 1; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* BINVAL SetBinValue: fill string with bytes extracted from a line. */ /***********************************************************************/ void BINVAL::SetBinValue(void *p) - { +{ memcpy(Binp, p, Clen); Len = Clen; - } // end of SetBinValue +} // end of SetBinValue /***********************************************************************/ /* GetBinValue: fill a buffer with the internal binary value. */ @@ -2253,7 +2257,7 @@ void BINVAL::SetBinValue(void *p) /* Currently used by WriteColumn of binary files. */ /***********************************************************************/ bool BINVAL::GetBinValue(void *buf, int buflen, bool go) - { +{ if (Len > buflen) return true; else if (go) { @@ -2262,7 +2266,7 @@ bool BINVAL::GetBinValue(void *buf, int buflen, bool go) } // endif go return false; - } // end of GetBinValue +} // end of GetBinValue /***********************************************************************/ /* BINVAL ShowValue: get string representation of a binary value. */ @@ -2278,19 +2282,19 @@ int BINVAL::ShowValue(char *buf, int len) /* BINVAL GetCharString: get string representation of a binary value. */ /***********************************************************************/ char *BINVAL::GetCharString(char *) - { +{ if (!Chrp) Chrp = (char*)PlugSubAlloc(Global, NULL, Clen * 2 + 1); sprintf(Chrp, GetXfmt(), Len, Binp); return Chrp; - } // end of GetCharString +} // end of GetCharString /***********************************************************************/ /* BINVAL compare value with another Value. */ /***********************************************************************/ bool BINVAL::IsEqual(PVAL vp, bool chktype) - { +{ if (this == vp) return true; else if (chktype && Type != vp->GetType()) @@ -2308,7 +2312,7 @@ bool BINVAL::IsEqual(PVAL vp, bool chktype) return false; return true; - } // end of IsEqual +} // end of IsEqual /***********************************************************************/ /* FormatValue: This function set vp (a STRING value) to the string */ @@ -2316,23 +2320,23 @@ bool BINVAL::IsEqual(PVAL vp, bool chktype) /* This function assumes that the format matches the value type. */ /***********************************************************************/ bool BINVAL::FormatValue(PVAL vp, PCSZ fmt) - { +{ char *buf = (char*)vp->GetTo_Val(); // Should be big enough int n = sprintf(buf, fmt, Len, Binp); return (n > vp->GetValLen()); - } // end of FormatValue +} // end of FormatValue /***********************************************************************/ /* BINVAL SetFormat function (used to set SELECT output format). */ /***********************************************************************/ bool BINVAL::SetConstFormat(PGLOBAL, FORMAT& fmt) - { +{ fmt.Type[0] = 'B'; fmt.Length = Clen; fmt.Prec = 0; return false; - } // end of SetConstFormat +} // end of SetConstFormat /* -------------------------- Class DTVAL ---------------------------- */ @@ -2341,7 +2345,7 @@ bool BINVAL::SetConstFormat(PGLOBAL, FORMAT& fmt) /***********************************************************************/ DTVAL::DTVAL(PGLOBAL g, int n, int prec, PCSZ fmt) : TYPVAL((int)0, TYPE_DATE) - { +{ if (!fmt) { Pdtp = NULL; Sdate = NULL; @@ -2351,37 +2355,37 @@ DTVAL::DTVAL(PGLOBAL g, int n, int prec, PCSZ fmt) SetFormat(g, fmt, n, prec); //Type = TYPE_DATE; - } // end of DTVAL constructor +} // end of DTVAL constructor /***********************************************************************/ /* DTVAL public constructor from int. */ /***********************************************************************/ DTVAL::DTVAL(int n) : TYPVAL(n, TYPE_DATE) - { +{ Pdtp = NULL; Len = 19; //Type = TYPE_DATE; Sdate = NULL; DefYear = 0; - } // end of DTVAL constructor +} // end of DTVAL constructor /***********************************************************************/ /* Set format so formatted dates can be converted on input/output. */ /***********************************************************************/ bool DTVAL::SetFormat(PGLOBAL g, PCSZ fmt, int len, int year) - { +{ Pdtp = MakeDateFormat(g, fmt, true, true, (year > 9999) ? 1 : 0); Sdate = (char*)PlugSubAlloc(g, NULL, len + 1); DefYear = (int)((year > 9999) ? (year - 10000) : year); Len = len; return false; - } // end of SetFormat +} // end of SetFormat /***********************************************************************/ /* Set format from the format of another date value. */ /***********************************************************************/ bool DTVAL::SetFormat(PGLOBAL g, PVAL valp) - { +{ DTVAL *vp; if (valp->GetType() != TYPE_DATE) { @@ -2395,14 +2399,14 @@ bool DTVAL::SetFormat(PGLOBAL g, PVAL valp) Sdate = (char*)PlugSubAlloc(g, NULL, Len + 1); DefYear = vp->DefYear; return false; - } // end of SetFormat +} // end of SetFormat /***********************************************************************/ /* We need TimeShift because the mktime C function does a correction */ /* for local time zone that we want to override for DB operations. */ /***********************************************************************/ void DTVAL::SetTimeShift(void) - { +{ struct tm dtm; memset(&dtm, 0, sizeof(dtm)); dtm.tm_mday=2; @@ -2414,7 +2418,7 @@ void DTVAL::SetTimeShift(void) if (trace(1)) htrc("DTVAL Shift=%d\n", Shift); - } // end of SetTimeShift +} // end of SetTimeShift // Added by Alexander Barkov static void TIME_to_localtime(struct tm *tm, const MYSQL_TIME *ltime) @@ -2444,7 +2448,7 @@ static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm) /* extend the range of valid dates by accepting negative time values. */ /***********************************************************************/ struct tm *DTVAL::GetGmTime(struct tm *tm_buffer) - { +{ struct tm *datm; time_t t = (time_t)Tval; @@ -2463,7 +2467,7 @@ struct tm *DTVAL::GetGmTime(struct tm *tm_buffer) datm = gmtime_mysql(&t, tm_buffer); return datm; - } // end of GetGmTime +} // end of GetGmTime // Added by Alexander Barkov static time_t mktime_mysql(struct tm *ptm) @@ -2482,7 +2486,7 @@ static time_t mktime_mysql(struct tm *ptm) /* range of valid dates by accepting to set negative time values. */ /***********************************************************************/ bool DTVAL::MakeTime(struct tm *ptm) - { +{ int n, y = ptm->tm_year; time_t t = mktime_mysql(ptm); @@ -2498,7 +2502,7 @@ bool DTVAL::MakeTime(struct tm *ptm) for (n = 0; t == -1 && n < 20; n++) { ptm->tm_year += 4; t = mktime_mysql(ptm); - } // endfor t + } // endfor t if (t == -1) return true; @@ -2506,20 +2510,21 @@ bool DTVAL::MakeTime(struct tm *ptm) if ((t -= (n * FOURYEARS)) > 2000000000) return true; - } + } // endif t + Tval= (int) t; if (trace(2)) htrc("MakeTime Ival=%d\n", Tval); return false; - } // end of MakeTime +} // end of MakeTime /***********************************************************************/ /* Make a time_t datetime from its components (YY, MM, DD, hh, mm, ss) */ /***********************************************************************/ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) - { +{ int i, m; int n; bool rc = false; @@ -2589,9 +2594,9 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) case 3: datm.tm_hour = n; break; case 4: datm.tm_min = n; break; case 5: datm.tm_sec = n; break; - } // endswitch i + } // endswitch i - } // endfor i + } // endfor i if (trace(2)) htrc("MakeDate datm=(%d,%d,%d,%d,%d,%d)\n", @@ -2607,14 +2612,14 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) Tval = 0; return rc; - } // end of MakeDate +} // end of MakeDate /***********************************************************************/ /* DTVAL SetValue: copy the value of another Value object. */ /* This function allows conversion if chktype is false. */ /***********************************************************************/ bool DTVAL::SetValue_pval(PVAL valp, bool chktype) - { +{ if (valp != this) { if (chktype && Type != valp->GetType()) return true; @@ -2636,16 +2641,16 @@ bool DTVAL::SetValue_pval(PVAL valp, bool chktype) } else Reset(); - } // endif valp + } // endif valp return false; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* SetValue: convert chars extracted from a line to date value. */ /***********************************************************************/ bool DTVAL::SetValue_char(const char *p, int n) - { +{ bool rc= 0; if (Pdtp) { @@ -2661,7 +2666,7 @@ bool DTVAL::SetValue_char(const char *p, int n) n = Len; memcpy(Sdate, p, n); - } // endif n + } // endif n Sdate[n] = '\0'; @@ -2678,13 +2683,13 @@ bool DTVAL::SetValue_char(const char *p, int n) } // endif Pdtp return rc; - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* SetValue: convert a char string to date value. */ /***********************************************************************/ void DTVAL::SetValue_psz(PCSZ p) - { +{ if (Pdtp) { int ndv; int dval[6]; @@ -2704,13 +2709,13 @@ void DTVAL::SetValue_psz(PCSZ p) Null = (Nullable && Tval == 0); } // endif Pdtp - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* DTVAL SetValue: set value with a value extracted from a block. */ /***********************************************************************/ void DTVAL::SetValue_pvblk(PVBLK blk, int n) - { +{ if (Pdtp && !::IsTypeNum(blk->GetType())) { int ndv; int dval[6]; @@ -2720,13 +2725,13 @@ void DTVAL::SetValue_pvblk(PVBLK blk, int n) } else Tval = blk->GetIntValue(n); - } // end of SetValue +} // end of SetValue /***********************************************************************/ /* DTVAL GetCharString: get string representation of a date value. */ /***********************************************************************/ char *DTVAL::GetCharString(char *p) - { +{ if (Pdtp) { size_t n = 0; struct tm tm, *ptm= GetGmTime(&tm); @@ -2745,7 +2750,7 @@ char *DTVAL::GetCharString(char *p) //Null = false; ?????????????? return p; - } // end of GetCharString +} // end of GetCharString /***********************************************************************/ /* DTVAL ShowValue: get string representation of a date value. */ @@ -2783,7 +2788,7 @@ int DTVAL::ShowValue(char *buf, int len) /* Returns a member of the struct tm representation of the date. */ /***********************************************************************/ bool DTVAL::GetTmMember(OPVAL op, int& mval) - { +{ bool rc = false; struct tm tm, *ptm = GetGmTime(&tm); @@ -2796,10 +2801,10 @@ bool DTVAL::GetTmMember(OPVAL op, int& mval) case OP_QUART: mval = ptm->tm_mon / 3 + 1; break; default: rc = true; - } // endswitch op + } // endswitch op return rc; - } // end of GetTmMember +} // end of GetTmMember /***********************************************************************/ /* Calculates the week number of the year for the internal date value.*/ @@ -2810,7 +2815,7 @@ bool DTVAL::GetTmMember(OPVAL op, int& mval) /* the week that contains the January 4th. */ /***********************************************************************/ bool DTVAL::WeekNum(PGLOBAL g, int& nval) - { +{ // w is the start of the week SUN=0, MON=1, etc. int m, n, w = nval % 7; struct tm tm, *ptm = GetGmTime(&tm); @@ -2827,7 +2832,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval) // Everything should be Ok return false; - } // end of WeekNum +} // end of WeekNum #endif // 0 /***********************************************************************/ @@ -2836,7 +2841,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval) /* This function assumes that the format matches the value type. */ /***********************************************************************/ bool DTVAL::FormatValue(PVAL vp, PCSZ fmt) - { +{ char *buf = (char*)vp->GetTo_Val(); // Should be big enough struct tm tm, *ptm = GetGmTime(&tm); @@ -2853,6 +2858,6 @@ bool DTVAL::FormatValue(PVAL vp, PCSZ fmt) } else return true; - } // end of FormatValue +} // end of FormatValue /* -------------------------- End of Value --------------------------- */ From a00b713130626a6e91864fdee3f2b264cbe82ac6 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Wed, 16 Oct 2019 22:12:47 +0200 Subject: [PATCH 3/3] Fix wrong second parameter in snprintf --- storage/connect/value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 158495de26c..df75722d0e8 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -884,14 +884,14 @@ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) template int TYPVAL::ShowValue(char *buf, int len) { - return snprintf(buf, len, Xfmt, len, Tval); + return snprintf(buf, len + 1, Xfmt, len, Tval); } // end of ShowValue template <> int TYPVAL::ShowValue(char *buf, int len) { // TODO: use a more appropriate format to avoid possible truncation - return snprintf(buf, len, Xfmt, len, Prec, Tval); + return snprintf(buf, len + 1, Xfmt, len, Prec, Tval); } // end of ShowValue /***********************************************************************/