Kaynağa Gözat

Merge pull request #10893 from rpastrana/HPCC-18886-coverityWssql

HPCC-18886 Coverity issues in wssql component

Reviewed-By: Michael Gardner <michael.gardner@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 7 yıl önce
ebeveyn
işleme
bbbeea6651

+ 10 - 10
esp/services/ws_sql/SQL2ECL/ECLEngine.cpp

@@ -75,7 +75,7 @@ void ECLEngine::generateIndexSetupAndFetch(HPCCFilePtr file, SQLTable * table, i
 
     if (indexname.length()>0)
     {
-        HPCCFilePtr indexfile = dynamic_cast<HPCCFile *>(selectsqlobj->queryHPCCFileCache()->getHpccFileByName(indexname));
+        HPCCFilePtr indexfile = selectsqlobj->queryHPCCFileCache()->getHpccFileByName(indexname);
         if (indexfile && file)
         {
             StringBuffer idxsetupstr;
@@ -205,7 +205,7 @@ void ECLEngine::generateSelectECL(HPCCSQLTreeWalker * selectsqlobj, StringBuffer
         SQLTable table = tables->item(tableidx);
         const char * tname = table.getName();
 
-        HPCCFilePtr file = dynamic_cast<HPCCFile *>(selectsqlobj->queryHPCCFileCache()->getHpccFileByName(tname));
+        HPCCFilePtr file = selectsqlobj->queryHPCCFileCache()->getHpccFileByName(tname);
         if (file)
         {
             translator->setProp(tname, "LEFT");
@@ -500,7 +500,7 @@ void ECLEngine::generateSelectStruct(HPCCSQLTreeWalker * selectsqlobj, IProperti
         }
         else if (col->getExpType() == Function_ExpressionType)
         {
-            SQLFunctionExpression * funcexp = dynamic_cast<SQLFunctionExpression *>(col);
+            SQLFunctionExpression * funcexp = static_cast<SQLFunctionExpression *>(col);
             IArrayOf<ISQLExpression> * funccols = funcexp->getParams();
 
             ECLFunctionDefCfg func = ECLFunctions::getEclFuntionDef(funcexp->getName());
@@ -634,13 +634,13 @@ bool containsPayload(const HPCCFile * indexfiletotest, const HPCCSQLTreeWalker *
             ISQLExpression * exp = &selectlist->item(j);
             if (exp->getExpType() == FieldValue_ExpressionType)
             {
-                SQLFieldValueExpression * currentselectcol = dynamic_cast<SQLFieldValueExpression *>(exp);
+                SQLFieldValueExpression * currentselectcol = static_cast<SQLFieldValueExpression *>(exp);
                 if (!indexfiletotest->containsField(currentselectcol->queryField(), true))
                     return false;
             }
             else if (exp->getExpType() == Function_ExpressionType)
             {
-                SQLFunctionExpression * currentfunccol = dynamic_cast<SQLFunctionExpression *>(exp);
+                SQLFunctionExpression * currentfunccol = static_cast<SQLFunctionExpression *>(exp);
 
                 IArrayOf<ISQLExpression> * funcparams = currentfunccol->getParams();
                 ForEachItemIn(paramidx, *funcparams)
@@ -648,7 +648,7 @@ bool containsPayload(const HPCCFile * indexfiletotest, const HPCCSQLTreeWalker *
                     ISQLExpression * param = &(funcparams->item(paramidx));
                     if (param->getExpType() == FieldValue_ExpressionType)
                     {
-                        SQLFieldValueExpression * currentselectcol = dynamic_cast<SQLFieldValueExpression *>(param);
+                        SQLFieldValueExpression * currentselectcol = static_cast<SQLFieldValueExpression *>(param);
                         if (!indexfiletotest->containsField(currentselectcol->queryField(), true))
                             return false;
                     }
@@ -801,7 +801,7 @@ void ECLEngine::findAppropriateIndex(StringArray * relindexes, HPCCSQLTreeWalker
         if (!selectsqlobj->queryHPCCFileCache()->isHpccFileCached(indexname))
             selectsqlobj->queryHPCCFileCache()->cacheHpccFileByName(indexname);
 
-        HPCCFilePtr indexfile = dynamic_cast<HPCCFile *>(selectsqlobj->queryHPCCFileCache()->getHpccFileByName(indexname));
+        HPCCFilePtr indexfile = selectsqlobj->queryHPCCFileCache()->getHpccFileByName(indexname);
 
         if (indexfile)
         {
@@ -815,13 +815,13 @@ void ECLEngine::findAppropriateIndex(StringArray * relindexes, HPCCSQLTreeWalker
                     ISQLExpression * exp = &expectedretcolumns->item(j);
                     if (exp->getExpType() == FieldValue_ExpressionType)
                     {
-                        SQLFieldValueExpression * fieldexp = dynamic_cast<SQLFieldValueExpression *>(exp);
+                        SQLFieldValueExpression * fieldexp = static_cast<SQLFieldValueExpression *>(exp);
                         if (indexfile->containsField(fieldexp->queryField(), true))
                             commonparamscount++;
                     }
                     else if (exp->getExpType() == Function_ExpressionType)
                     {
-                        SQLFunctionExpression * currentfunccol = dynamic_cast<SQLFunctionExpression *>(exp);
+                        SQLFunctionExpression * currentfunccol = static_cast<SQLFunctionExpression *>(exp);
 
                         IArrayOf<ISQLExpression> * funcparams = currentfunccol->getParams();
                         ForEachItemIn(paramidx, *funcparams)
@@ -829,7 +829,7 @@ void ECLEngine::findAppropriateIndex(StringArray * relindexes, HPCCSQLTreeWalker
                             ISQLExpression * param = &(funcparams->item(paramidx));
                             if (param->getExpType() == FieldValue_ExpressionType)
                             {
-                                SQLFieldValueExpression * currentselectcol = dynamic_cast<SQLFieldValueExpression *>(param);
+                                SQLFieldValueExpression * currentselectcol = static_cast<SQLFieldValueExpression *>(param);
                                 if (indexfile->containsField(currentselectcol->queryField(), true))
                                     commonparamscount++;
                             }

+ 3 - 8
esp/services/ws_sql/SQL2ECL/HPCCFile.cpp

@@ -24,14 +24,9 @@ HPCCFile * HPCCFile::createHPCCFile()
     return new HPCCFile();
 }
 
-HPCCFile::HPCCFile()
-{
-    iskeyfile=false;
-    issuperfile=false;
-    keyedCount = -1;
-    nonKeyedCount = -1;
-    hasNestedColumns = false;
-}
+HPCCFile::HPCCFile() : formatEnum(HPCCFileFormatUnknown), iskeyfile(false), issuperfile(false), keyedCount(-1),
+                       nonKeyedCount(-1), hasNestedColumns(false)
+{}
 
 HPCCFile::~HPCCFile()
 {

+ 46 - 27
esp/services/ws_sql/SQL2ECL/HPCCSQLTreeWalker.cpp

@@ -32,12 +32,6 @@ void trimSingleQuotes(StringBuffer & quotedString)
     }
 }
 
-HPCCSQLTreeWalker::HPCCSQLTreeWalker()
-{
-    sqlType = SQLTypeUnknown;
-    parameterizeStaticValues = true;
-}
-
 void HPCCSQLTreeWalker::limitTreeWalker(pANTLR3_BASE_TREE limitAST)
 {
     char *  limit = NULL;
@@ -182,7 +176,6 @@ void HPCCSQLTreeWalker::fromTreeWalker(pANTLR3_BASE_TREE fromsqlAST)
 ISQLExpression * HPCCSQLTreeWalker::expressionTreeWalker(pANTLR3_BASE_TREE exprAST, pANTLR3_BASE_TREE parent)
 {
     Owned<ISQLExpression>  tmpexp;
-    ANTLR3_UINT32 exptype = exprAST->getType(exprAST);
 
     if ( exprAST != NULL )
     {
@@ -190,6 +183,7 @@ ISQLExpression * HPCCSQLTreeWalker::expressionTreeWalker(pANTLR3_BASE_TREE exprA
         Owned<ISQLExpression>  rightexp;
 
         bool checkForAlias = false;
+        ANTLR3_UINT32 exptype = exprAST->getType(exprAST);
         switch (exptype)
         {
             case TOKEN_LISTEXP:
@@ -236,7 +230,7 @@ ISQLExpression * HPCCSQLTreeWalker::expressionTreeWalker(pANTLR3_BASE_TREE exprA
                         ForEachItemIn(tableidx, tableList)
                         {
                             const char * tablename = tableList.item(tableidx).getName();
-                            HPCCFilePtr file = dynamic_cast<HPCCFilePtr>(tmpHPCCFileCache->getHpccFileByName(tablename));
+                            HPCCFilePtr file = tmpHPCCFileCache->getHpccFileByName(tablename);
                             if (file)
                             {
                                 IArrayOf<HPCCColumnMetaData> * cols = file->getColumns();
@@ -896,8 +890,9 @@ void HPCCSQLTreeWalker::callStatementTreeWalker(pANTLR3_BASE_TREE callsqlAST)
                             //The first set of single quotes are stripped here.
                             if (tokenType == TEXT_STRING)
                             {
-                                SQLValueExpression * valexp = dynamic_cast<SQLValueExpression *>(exp.get());
-                                valexp->trimTextQuotes();
+                                SQLValueExpression * valexp = static_cast<SQLValueExpression *>(exp.get());
+                                if (valexp)
+                                    valexp->trimTextQuotes();
                             }
                             paramList.append(*exp.getLink());
                         }
@@ -1000,10 +995,20 @@ void HPCCSQLTreeWalker::selectStatementTreeWalker(pANTLR3_BASE_TREE selectsqlAST
                     {
                         Owned<ISQLExpression> exp = expressionTreeWalker((pANTLR3_BASE_TREE)(ithchild->getChild(ithchild, i)),NULL);
 
-                        if (exp.get())
-                            groupbyList.append(*exp.getLink());
+                        if (!exp)
+                            throw MakeStringException(-1, "Error in order by list.");
+
+                        if (exp->getExpType() == FieldValue_ExpressionType)
+                        {
+                            SQLFieldValueExpression * fielvalexp = static_cast<SQLFieldValueExpression *>(exp.getLink());
+                            groupbyList.append(*fielvalexp);
+                        }
                         else
-                            throw MakeStringException(-1, "Error in group by list");
+                        {
+                            StringBuffer fieldvalue;
+                            exp->toString(fieldvalue, true);
+                            throw MakeStringException(-1, "Encountered invalid entry '%s' in 'GROUP BY' clause", fieldvalue.str());
+                        }
                     }
                     break;
                 }
@@ -1017,10 +1022,20 @@ void HPCCSQLTreeWalker::selectStatementTreeWalker(pANTLR3_BASE_TREE selectsqlAST
                     {
                         Owned<ISQLExpression> exp = expressionTreeWalker((pANTLR3_BASE_TREE)(ithchild->getChild(ithchild, i)),NULL);
 
-                        if (exp.get())
-                            orderbyList.append(*exp.getLink());
-                        else
+                        if (!exp)
                             throw MakeStringException(-1, "Error in order by list.");
+
+                        if (exp->getExpType() == FieldValue_ExpressionType)
+                        {
+                            SQLFieldValueExpression * fielvalexp = static_cast<SQLFieldValueExpression *>(exp.getLink());
+                            orderbyList.append(*fielvalexp);
+                        }
+                        else
+                        {
+                            StringBuffer fieldvalue;
+                            exp->toString(fieldvalue, true);
+                            throw MakeStringException(-1, "Encountered invalid entry '%s' in 'ORDER BY' clause", fieldvalue.str());
+                        }
                     }
                     break;
                 }
@@ -1092,15 +1107,18 @@ void HPCCSQLTreeWalker::assignParameterIndexes()
     parameterizedCount = paramIndex - 1;
 }
 
-HPCCSQLTreeWalker::HPCCSQLTreeWalker(pANTLR3_BASE_TREE ast, IEspContext &context, bool attemptParameterization)
+HPCCSQLTreeWalker::HPCCSQLTreeWalker() :  sqlType(SQLTypeUnknown), parameterizeStaticValues(true), limit(-1)
+                                         ,offset(-1), selectDistinct(false)
+                                         ,overwrite(true), sourceDataType(""), parameterizedCount(-1)
+{
+    normalizedSQL.clear();
+}
+
+HPCCSQLTreeWalker::HPCCSQLTreeWalker(pANTLR3_BASE_TREE ast, IEspContext &context, bool attemptParameterization) :
+                            limit(-1), offset(-1), selectDistinct(false), overwrite(true), sourceDataType("FLAT")
 {
     parameterizeStaticValues = attemptParameterization;
     normalizedSQL.clear();
-    setLimit(-1);
-    setOffset(-1);
-    selectDistinct = false;
-    overwrite = true;
-    sourceDataType.set("FLAT");
 
     StringBuffer username;
     StringBuffer password;
@@ -1166,7 +1184,7 @@ void HPCCSQLTreeWalker::expandWildCardColumn()
                 {
                     SQLTable tab = (SQLTable)tableList.item(tableidx);
 
-                    HPCCFilePtr file = dynamic_cast<HPCCFilePtr>(tmpHPCCFileCache->getHpccFileByName(tab.getName()));
+                    HPCCFilePtr file = tmpHPCCFileCache->getHpccFileByName(tab.getName());
                     if (file)
                     {
                         IArrayOf<HPCCColumnMetaData> * cols = file->getColumns();
@@ -1190,7 +1208,7 @@ void HPCCSQLTreeWalker::expandWildCardColumn()
             else
             {
                 const char * tablename = ((SQLFieldsExpression * )currexp)->getTable();
-                HPCCFilePtr file =  dynamic_cast<HPCCFilePtr>(tmpHPCCFileCache->getHpccFileByName(tablename));
+                HPCCFilePtr file = tmpHPCCFileCache->getHpccFileByName(tablename);
                 if (file)
                 {
                     IArrayOf<HPCCColumnMetaData> * cols = file->getColumns();
@@ -1211,6 +1229,7 @@ void HPCCSQLTreeWalker::expandWildCardColumn()
             }
             break; //only one select all ??
         }
+
         if (replaced && currexp)
             currexp->Release();
     }
@@ -1237,7 +1256,7 @@ ISQLExpression * HPCCSQLTreeWalker::getHavingClause()
     return havingClause.get();
 }
 
-void HPCCSQLTreeWalker::verifyAndDisambiguateNameFromList(IArrayOf<ISQLExpression> * explist)
+void HPCCSQLTreeWalker::verifyAndDisambiguateNameFromList(IArrayOf<SQLFieldValueExpression> * explist)
 {
     if (explist)
     {
@@ -1245,7 +1264,7 @@ void HPCCSQLTreeWalker::verifyAndDisambiguateNameFromList(IArrayOf<ISQLExpressio
         for (int i = 0; i < bycount; i++)
         {
             bool found = false;
-            ISQLExpression * coltoverify =  &explist->item(i);
+            SQLFieldValueExpression * coltoverify =  &explist->item(i);
 
             //we're trying to verify the list (groupby or sortby) contains only coloumns which appear in the select list
             ForEachItemIn(sellistidx, selectList)
@@ -1308,7 +1327,7 @@ void HPCCSQLTreeWalker::verifyColumn(SQLFieldValueExpression * col)
 
         if (selcolname && *selcolname)
         {
-            HPCCFilePtr file = dynamic_cast<HPCCFilePtr>(tmpHPCCFileCache->getHpccFileByName(selcolparent));
+            HPCCFilePtr file = tmpHPCCFileCache->getHpccFileByName(selcolparent);
             if (file)
             {
                 if (selcolname && *selcolname)

+ 13 - 16
esp/services/ws_sql/SQL2ECL/HPCCSQLTreeWalker.hpp

@@ -59,8 +59,8 @@ public:
 private:
     SQLQueryType sqlType;
     IArrayOf<ISQLExpression> selectList;
-    IArrayOf<ISQLExpression> groupbyList;
-    IArrayOf<ISQLExpression> orderbyList;
+    IArrayOf<SQLFieldValueExpression> groupbyList;
+    IArrayOf<SQLFieldValueExpression> orderbyList;
     IArrayOf<SQLTable>       tableList;
 
     int limit;
@@ -96,7 +96,7 @@ private:
     void processAllColumns(HpccFiles *  availableFiles);
     void verifyColumn(SQLFieldValueExpression * col );
     void verifyColAndDisambiguateName();
-    void verifyAndDisambiguateNameFromList(IArrayOf<ISQLExpression> * explist);
+    void verifyAndDisambiguateNameFromList(IArrayOf<SQLFieldValueExpression> * explist);
     void assignParameterIndexes();
     int parameterizedCount;
 
@@ -223,15 +223,13 @@ public:
 
     void getOrderByString(char delimiter, StringBuffer & str)
     {
-        int orderbycount = orderbyList.length();
-        for (int i = 0; i < orderbycount; i++)
+        ForEachItemIn(orderbyindex, orderbyList)
         {
-            ISQLExpression* ordercol = &orderbyList.item(i);
-            SQLFieldValueExpression* colexp = dynamic_cast<SQLFieldValueExpression*>(ordercol);
-            str.append(colexp->isAscending() ? "" : "-");
-            str.append(colexp->getNameOrAlias());
-            if (i != orderbycount - 1)
+            SQLFieldValueExpression * colexp =  &orderbyList.item(orderbyindex);
+            if (orderbyindex != 0)
                 str.append(delimiter);
+
+            str.append(colexp->getName());
         }
     }
 
@@ -242,14 +240,13 @@ public:
 
     void getGroupByString(char delimiter, StringBuffer & str)
     {
-        int groupbycount = groupbyList.length();
-        for (int i = 0; i < groupbycount; i++)
+        ForEachItemIn(groupbyindex, groupbyList)
         {
-            ISQLExpression * ordercol =  &groupbyList.item(i);
-            SQLFieldValueExpression * colexp = dynamic_cast<SQLFieldValueExpression *>(ordercol);
-            str.append(colexp->getName());
-            if (i != groupbycount - 1)
+            SQLFieldValueExpression * colexp =  &groupbyList.item(groupbyindex);
+            if (groupbyindex != 0)
                 str.append(delimiter);
+
+            str.append(colexp->getName());
         }
     }
 

+ 7 - 1
esp/services/ws_sql/SQL2ECL/SQLColumn.cpp

@@ -17,7 +17,7 @@ limitations under the License.
 
 #include "SQLColumn.hpp"
 
-SQLColumn::SQLColumn() {}
+SQLColumn::SQLColumn() : position(-1), ascending(true) {}
 SQLColumn::SQLColumn(const char * parentname, const char * columnname, const char * alias, int position)
 {
     this->parenttable.clear();
@@ -34,6 +34,12 @@ SQLColumn::SQLColumn(const char * parentname, const char * columnname, const cha
     this->position = position;
 
     setAscending(true);
+    StringBuffer columnName;
+    StringBuffer tableName;
+    int index;
+    int decimalDigits;
+    StringBuffer columnType;
+    bool keyedField;
 }
 
 

+ 2 - 5
esp/services/ws_sql/SQL2ECL/SQLColumn.hpp

@@ -121,7 +121,6 @@ private:
     StringBuffer columnName;
     StringBuffer tableName;
     int index;
-    int columnChars;
     int decimalDigits;
     StringBuffer columnType;
     bool keyedField;
@@ -134,16 +133,14 @@ public:
         return new HPCCColumnMetaData(name);
     }
 
-    HPCCColumnMetaData()
+    HPCCColumnMetaData() : keyedField(false), decimalDigits(0), index(-1)
     {
         columnName.clear();
-        keyedField = false;
     }
 
-    HPCCColumnMetaData(const char * colname)
+    HPCCColumnMetaData(const char * colname) : keyedField(false), decimalDigits(0), index(-1)
     {
         columnName.set(colname);
-        keyedField = false;
     }
 
     virtual ~HPCCColumnMetaData()

+ 37 - 37
esp/services/ws_sql/SQL2ECL/SQLExpression.cpp

@@ -205,7 +205,7 @@ SQLFieldValueExpression::~SQLFieldValueExpression()
 
 /***********************SQLUnaryExpression START**************************************************************************/
 
-SQLUnaryExpression::SQLUnaryExpression()
+SQLUnaryExpression::SQLUnaryExpression() : operand1(nullptr), op(-1)
 {}
 
 SQLUnaryExpression::~SQLUnaryExpression()
@@ -218,23 +218,23 @@ SQLUnaryExpression::~SQLUnaryExpression()
 
 void SQLUnaryExpression::getExpressionFromColumnName(const char * colname, StringBuffer & str)
 {
-        switch (op)
-        {
-            case ISNOTNULL:
-                str.append(" TRUE ");
-                break;
-            case ISNULL:
-                str.append(" FALSE ");
-                break;
-            case NOT_SYM:
-            case NEGATION:
-                str.append(" NOT ");
-                operand1->getExpressionFromColumnName(colname, str);
-                break;
-            default:
-                break;
+    switch (op)
+    {
+        case ISNOTNULL:
+            str.append(" TRUE ");
+            break;
+        case ISNULL:
+            str.append(" FALSE ");
+            break;
+        case NOT_SYM:
+        case NEGATION:
+            str.append(" NOT ");
+            operand1->getExpressionFromColumnName(colname, str);
+            break;
+        default:
+            break;
         }
-    }
+}
 
 SQLUnaryExpression::SQLUnaryExpression(ISQLExpression* operand1, int opname)
 {
@@ -455,17 +455,17 @@ bool SQLBinaryExpression::containsEqualityCondition(ISQLExpression* operand, IPr
         case Unary_ExpressionType:
         {
             SQLUnaryExpression * unary = dynamic_cast<SQLUnaryExpression *>(operand);
-            return unary->containsEqualityCondition(map, first, second);
+            return unary ? unary->containsEqualityCondition(map, first, second) : false;
         }
         case Binary_ExpressionType:
         {
             SQLBinaryExpression * binary = dynamic_cast<SQLBinaryExpression *>(operand);
-            return binary->isEqualityCondition(map, first, second);
+            return binary ? binary->isEqualityCondition(map, first, second) : false;
         }
         case Parenthesis_ExpressionType:
         {
             SQLParenthesisExpression * paren = dynamic_cast<SQLParenthesisExpression *>(operand);
-            return containsEqualityCondition(paren, map, first, second);
+            return paren ? containsEqualityCondition(paren, map, first, second) : false;
         }
         default:
             return false;
@@ -498,26 +498,28 @@ bool SQLBinaryExpression::isEqualityCondition(IProperties * map, const char * fi
     if (operand1->getExpType() == FieldValue_ExpressionType)
     {
         SQLFieldValueExpression * op1field = dynamic_cast<SQLFieldValueExpression *>(operand1);
-        map->getProp(op1field->getParentTableName(), operand1Translate);
+        if (op1field)
+            map->getProp(op1field->getParentTableName(), operand1Translate);
     }
 
     if (operand2->getExpType() == FieldValue_ExpressionType)
     {
         SQLFieldValueExpression * op2field = dynamic_cast<SQLFieldValueExpression *>(operand2);
-        map->getProp(op2field->getParentTableName(), operand2Translate);
+        if (op2field)
+            map->getProp(op2field->getParentTableName(), operand2Translate);
     }
 
     if (operand1Translate.length()<=0 || operand2Translate.length() <= 0)
         return false;
 
     return (
-                strcmp(operand1Translate.str(), operand2Translate.str()) != 0 &&
-                (
-                        (strcmp(operand1Translate.str(), first)==0 || strcmp(operand2Translate.str(), first)==0)
-                        &&
-                        (strcmp(operand1Translate.str(), second)==0 || strcmp(operand2Translate.str(), second)==0)
-                )
-            );
+               strcmp(operand1Translate.str(), operand2Translate.str()) != 0 &&
+               (
+                   (strcmp(operand1Translate.str(), first)==0 || strcmp(operand2Translate.str(), first)==0)
+                   &&
+                   (strcmp(operand1Translate.str(), second)==0 || strcmp(operand2Translate.str(), second)==0)
+               )
+           );
 }
 void SQLBinaryExpression::toECLStringTranslateSource(
             StringBuffer & eclStr,
@@ -533,7 +535,7 @@ void SQLBinaryExpression::toECLStringTranslateSource(
     operand1->toECLStringTranslateSource(translation1, map, ignoreMisTranslations, forHaving, false, false);
     operand2->toECLStringTranslateSource(translation2, map, ignoreMisTranslations, forHaving, false, false);
 
-    if (translation1.length()>0 && translation2.length()>0)
+    if (translation1.length() != 0 && translation2.length() != 0)
     {
         if ( op == LIKE_SYM || op == NOT_LIKE)
         {
@@ -550,14 +552,12 @@ void SQLBinaryExpression::toECLStringTranslateSource(
             eclStr.append(getOpStr());
             eclStr.append(translation2);
         }
-
-    }
-    else if (translation1.length() == 0 && translation2.length() == 0)
-    {
-        return;
     }
     else if (ignoreMisTranslations)
     {
+        if (translation1.length() == 0 && translation2.length() == 0)
+             return;
+
         /*
         * If operand1 or operand2 could not be translated using the translation map,
         * and ignoreMisTranslations = true, we're going to attempt to return an valid
@@ -574,7 +574,7 @@ void SQLBinaryExpression::toECLStringTranslateSource(
         {
             StringBuffer convert( op == OR_SYM ? "FALSE" : "TRUE");
 
-            if (translation1.length()>0)
+            if (translation1.length() != 0)
             {
                 WARNLOG("Operand 1 of binary expression could not be translated.");
                 eclStr.append(translation1);
@@ -702,7 +702,7 @@ int SQLParameterPlaceHolderExpression::setParameterizedNames(int currentindex)
     return ++currentindex;
 }
 
-SQLParameterPlaceHolderExpression::SQLParameterPlaceHolderExpression()
+SQLParameterPlaceHolderExpression::SQLParameterPlaceHolderExpression() : index(-1)
 {
 }
 

+ 11 - 11
esp/services/ws_sql/ws_sqlService.cpp

@@ -365,7 +365,7 @@ void myDisplayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer,pANTLR3_UINT8
     pANTLR3_COMMON_TREE     theCommonTree;
 
     ex      =       recognizer->state->exception;
-    ttext   =       NULL;
+    ttext   =       nullptr;
 
     errorMessage.append("Error while parsing");
     if (ex)
@@ -379,14 +379,14 @@ void myDisplayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer,pANTLR3_UINT8
                 parser      = (pANTLR3_PARSER) (recognizer->super);
                 is          = parser->tstream->istream;
                 theToken    = (pANTLR3_COMMON_TOKEN)(ex->token);
-                ttext       = theToken->toString(theToken);
 
-                if  (theToken != NULL)
+                if  (theToken)
                 {
+                    ttext = theToken->toString(theToken);
                     if (theToken->type == ANTLR3_TOKEN_EOF)
                         errorMessage.append(", at <EOF>");
                     else
-                        errorMessage.appendf("\n    Near %s\n    ", ttext == NULL ? (pANTLR3_UINT8)"<no text for the token>" : ttext->chars);
+                        errorMessage.appendf("\n    Near %s\n    ", ttext == nullptr ? (pANTLR3_UINT8)"<no text for the token>" : ttext->chars);
                 }
                 break;
             }
@@ -395,14 +395,14 @@ void myDisplayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer,pANTLR3_UINT8
                 tparser     = (pANTLR3_TREE_PARSER) (recognizer->super);
                 is          = tparser->ctnstream->tnstream->istream;
                 theBaseTree = (pANTLR3_BASE_TREE)(ex->token);
-                ttext       = theBaseTree->toStringTree(theBaseTree);
 
-                if  (theBaseTree != NULL)
+                if  (theBaseTree)
                 {
+                    ttext = theBaseTree->toStringTree(theBaseTree);
                     theCommonTree   = (pANTLR3_COMMON_TREE)     theBaseTree->super;
 
-                    if  (theCommonTree != NULL)
-                        theToken   = (pANTLR3_COMMON_TOKEN)    theBaseTree->getToken(theBaseTree);
+                    if  (theCommonTree != nullptr)
+                        theToken = (pANTLR3_COMMON_TOKEN)    theBaseTree->getToken(theBaseTree);
 
                     errorMessage.appendf( ", at offset %d", theBaseTree->getCharPositionInLine(theBaseTree));
                     errorMessage.appendf( ", near %s", ttext->chars);
@@ -425,7 +425,7 @@ void myDisplayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer,pANTLR3_UINT8
                 // correct stream. Then we can see that the token we are looking at
                 // is just something that should not be there and throw this exception.
                 //
-                if  (tokenNames == NULL)
+                if  (tokenNames == nullptr)
                 {
                     errorMessage.appendf( " : Extraneous input...");
                 }
@@ -445,7 +445,7 @@ void myDisplayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer,pANTLR3_UINT8
                 // token. Perhaps a missing ';' at line end or a missing ',' in an
                 // expression list, and such like.
                 //
-                if  (tokenNames == NULL)
+                if  (tokenNames == nullptr)
                 {
                     errorMessage.appendf( " : Missing token (%d)...\n", ex->expecting);
                 }
@@ -1088,7 +1088,7 @@ void CwssqlEx::createWUXMLParams(StringBuffer & xmlparams, const IArrayOf <ISQLE
         ISQLExpression * exp = &parameterlist->item(expindex);
         if (exp->getExpType() == Value_ExpressionType)
         {
-            SQLValueExpression * currentvalplaceholder = dynamic_cast<SQLValueExpression *>(exp);
+            SQLValueExpression * currentvalplaceholder = static_cast<SQLValueExpression *>(exp);
             currentvalplaceholder->trimTextQuotes();
             xmlparams.appendf("<%s>", currentvalplaceholder->getPlaceHolderName());
             encodeXML(currentvalplaceholder->getValue(), xmlparams);