From b98360a42f2aec08fb7799c23a4b7c7566fb66ec Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 30 Jun 2013 12:43:30 +0200 Subject: [PATCH] - Trying to get rid of some valgrind warnings modified: storage/connect/mycat.cc storage/connect/valblk.cpp storage/connect/value.cpp --- storage/connect/mycat.cc | 2 ++ storage/connect/valblk.cpp | 7 +++-- storage/connect/value.cpp | 64 ++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index e243a706f01..3dd203949b6 100644 --- a/storage/connect/mycat.cc +++ b/storage/connect/mycat.cc @@ -426,6 +426,8 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) PCOLDEF cdp, lcdp= NULL, tocols= NULL; PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO)); + memset(pcf, 0, sizeof(COLINFO)); + // Get a unique char identifier for type tc= (defp->Catfunc == FNC_NO) ? GetTypeID(type) : TAB_PRX; diff --git a/storage/connect/valblk.cpp b/storage/connect/valblk.cpp index 575d88a56fc..cee4571bc0d 100644 --- a/storage/connect/valblk.cpp +++ b/storage/connect/valblk.cpp @@ -654,8 +654,11 @@ void CHRBLK::SetValues(PVBLK pv, int k, int n) /***********************************************************************/ void CHRBLK::Move(int i, int j) { - memcpy(Chrp + j * Long, Chrp + i * Long, Long); - MoveNull(i, j); + if (i != j) { + memcpy(Chrp + j * Long, Chrp + i * Long, Long); + MoveNull(i, j); + } // endif i + } // end of Move /***********************************************************************/ diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index e60f3889ef5..196724ea6c0 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -578,19 +578,25 @@ void TYPVAL::SetValue_char(char *p, int n) template <> void TYPVAL::SetValue_char(char *p, int n) { - char *p2, buf[32]; + if (p) { + char *p2, buf[32]; - for (p2 = p + n; p < p2 && *p == ' '; p++) ; + for (p2 = p + n; p < p2 && *p == ' '; p++) ; - n = min(p2 - p, 31); - memcpy(buf, p, n); - buf[n] = '\0'; - Tval = atof(buf); + n = min(p2 - p, 31); + memcpy(buf, p, n); + buf[n] = '\0'; + Tval = atof(buf); - if (trace > 1) - htrc(" setting double: '%s' -> %lf\n", buf, Tval); + if (trace > 1) + htrc(" setting double: '%s' -> %lf\n", buf, Tval); + + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif p - Null = false; } // end of SetValue /***********************************************************************/ @@ -599,8 +605,14 @@ void TYPVAL::SetValue_char(char *p, int n) template void TYPVAL::SetValue_psz(PSZ s) { - Tval = GetTypedValue(s); - Null = false; + if (s) { + Tval = GetTypedValue(s); + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif p + } // end of SetValue template <> @@ -895,17 +907,23 @@ bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) /***********************************************************************/ void TYPVAL::SetValue_char(char *p, int n) { - n = min(n, Len); - strncpy(Strp, p, n); + if (p) { + n = min(n, Len); + strncpy(Strp, p, n); - for (p = Strp + n - 1; (*p == ' ' || *p == '\0') && p >= Strp; p--) ; + for (p = Strp + n - 1; (*p == ' ' || *p == '\0') && p >= Strp; p--) ; - *(++p) = '\0'; + *(++p) = '\0'; - if (trace > 1) - htrc(" Setting string to: '%s'\n", Strp); + if (trace > 1) + htrc(" Setting string to: '%s'\n", Strp); + + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif p - Null = false; } // end of SetValue_char /***********************************************************************/ @@ -913,8 +931,14 @@ void TYPVAL::SetValue_char(char *p, int n) /***********************************************************************/ void TYPVAL::SetValue_psz(PSZ s) { - strncpy(Strp, s, Len); - Null = false; + if (s) { + strncpy(Strp, s, Len); + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif s + } // end of SetValue_psz /***********************************************************************/