Explorar el Código

HPCC-22331 Clean up some coverity warnings

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday hace 6 años
padre
commit
355b4b0736

+ 35 - 37
ecl/hql/hqlexpr.cpp

@@ -3287,6 +3287,7 @@ IHqlExpression * ensureExprType(IHqlExpression * expr, ITypeInfo * type, node_op
         return LINK(expr);
 
     ITypeInfo * exprType = queryUnqualifiedType(qualifiedType);
+    assertex(exprType);
     if (exprType == queryUnqualifiedType(type))
         return LINK(expr);
 
@@ -3299,12 +3300,11 @@ IHqlExpression * ensureExprType(IHqlExpression * expr, ITypeInfo * type, node_op
         ITypeInfo * childType = type->queryChildType();
         if (!childType)
             return LINK(expr);
-        if (exprType)
-        {
-            ITypeInfo * exprChildType = exprType->queryChildType();
-            if (exprChildType && isSameBasicType(childType, exprChildType))
-                return LINK(expr);
-        }
+
+        ITypeInfo * exprChildType = exprType->queryChildType();
+        if (exprChildType && isSameBasicType(childType, exprChildType))
+            return LINK(expr);
+
         HqlExprArray values;
 
         if (expr->getOperator() == no_list)
@@ -3368,43 +3368,40 @@ IHqlExpression * ensureExprType(IHqlExpression * expr, ITypeInfo * type, node_op
     }
     else if (type->getStringLen() == UNKNOWN_LENGTH)
     {
-        if (exprType)
+        //Optimize away casts to unknown length if the rest of the type matches.
+        if (exprType->getTypeCode() == tc)
         {
-            //Optimize away casts to unknown length if the rest of the type matches.
-            if (exprType->getTypeCode() == tc)
+            //cast to STRING/DATA/VARSTRING/UNICODE/VARUNICODE means ensure that the expression has this base type.
+            if ((tc == type_data) || (tc == type_qstring))
             {
-                //cast to STRING/DATA/VARSTRING/UNICODE/VARUNICODE means ensure that the expression has this base type.
-                if ((tc == type_data) || (tc == type_qstring))
-                {
+                return LINK(expr);
+            }
+            else if (tc == type_unicode || tc == type_varunicode || tc == type_utf8)
+            {
+                if (type->queryLocale() == exprType->queryLocale())
                     return LINK(expr);
-                }
-                else if (tc == type_unicode || tc == type_varunicode || tc == type_utf8)
-                {
-                    if (type->queryLocale() == exprType->queryLocale())
-                        return LINK(expr);
-                }
-                else if (tc == type_string || tc == type_varstring)
-                {
-                    if ((type->queryCharset() == exprType->queryCharset()) &&
-                        (type->queryCollation() == exprType->queryCollation()))
-                        return LINK(expr);
-                }
-                else if (tc == type_decimal)
-                {
-                    if (type->isSigned() == exprType->isSigned())
-                        return LINK(expr);
-                }
             }
-
-            /*
-            The following might produce better code, but it generally makes things worse.....
-            if ((exprType->getSize() != UNKNOWN_LENGTH) && (isStringType(exprType) || isUnicodeType(exprType)))
+            else if (tc == type_string || tc == type_varstring)
             {
-                Owned<ITypeInfo> stretchedType = getStretchedType(exprType->getStringLen(), type);
-                return ensureExprType(expr, stretchedType, castOp);
+                if ((type->queryCharset() == exprType->queryCharset()) &&
+                    (type->queryCollation() == exprType->queryCollation()))
+                    return LINK(expr);
             }
-            */
+            else if (tc == type_decimal)
+            {
+                if (type->isSigned() == exprType->isSigned())
+                    return LINK(expr);
+            }
+        }
+
+        /*
+        The following might produce better code, but it generally makes things worse.....
+        if ((exprType->getSize() != UNKNOWN_LENGTH) && (isStringType(exprType) || isUnicodeType(exprType)))
+        {
+            Owned<ITypeInfo> stretchedType = getStretchedType(exprType->getStringLen(), type);
+            return ensureExprType(expr, stretchedType, castOp);
         }
+        */
     }
 
     node_operator op = expr->getOperator();
@@ -9921,7 +9918,8 @@ public:
     CHqlForwardScope(IHqlScope * _parentScope, HqlGramCtx * _parentCtx, HqlParseContext & parseCtx);
     ~CHqlForwardScope()
     {
-        assertex(!parentScope);
+        if (parentScope)
+            DBGLOG("Paranoia: CHqlForwardScope parentScope has not been cleared");
     }
     IMPLEMENT_IINTERFACE_USING(CHqlVirtualScope)
 

+ 3 - 3
ecl/hql/hqlexpr.ipp

@@ -506,10 +506,10 @@ protected:
 class CFileContents : public CInterfaceOf<IFileContents>
 {
 private:
-    bool delayedRead;
-    bool implicitlySigned;
+    bool delayedRead = false;
+    bool implicitlySigned = false;
     enum : byte { unchecked, unknown, dirty, clean } dirtyState = unchecked;
-    timestamp_type ts;
+    timestamp_type ts = 0;
     Linked<IFile> file;
     MemoryAttr fileContents;
     Linked<ISourcePath> sourcePath;

+ 4 - 2
ecl/hql/hqlgram2.cpp

@@ -968,12 +968,14 @@ IHqlExpression * HqlGram::processEmbedBody(const attribute & errpos, IHqlExpress
                 reportError(ERR_EMBEDPROJECT_INVALID, errpos, "PROJECTED attribute requires a string parameter");
             else
             {
-                IValue *projectedSearchValue = projectedSearch->queryValue();
+                Linked<IValue> projectedSearchValue = projectedSearch->queryValue();
                 if (!projectedSearchValue )
                 {
                     // To relax this we'd need to pass the value as a hidden parameter as we do for the other options and the embed text,
                     // But I really can't see it being useful
                     reportError(ERR_EMBEDPROJECT_INVALID, errpos, "PROJECTED attribute requires a constant string parameter");
+                    OwnedHqlExpr null = createBlankString();
+                    projectedSearchValue.set(null->queryValue());
                 }
                 IValue *queryText = embedText->queryValue();
                 if (queryText)
@@ -2751,7 +2753,7 @@ void HqlGram::addField(const attribute &errpos, IIdAtom * name, ITypeInfo *_type
     {
         if (fieldSize > MAX_SENSIBLE_FIELD_LENGTH)
             reportWarning(CategoryEfficiency, SeverityError, ERR_BAD_FIELD_SIZE, errpos.pos, "Field %s is larger than max sensible size", str(name));
-        else if (fieldSize > MAX_POSSIBLE_FIELD_LENGTH)
+        if (fieldSize > MAX_POSSIBLE_FIELD_LENGTH)
             reportError(ERR_BAD_FIELD_SIZE, errpos.pos, "Field %s is too large", str(name));
     }
 

+ 1 - 0
system/jhtree/ctfile.cpp

@@ -213,6 +213,7 @@ CNodeBase::CNodeBase()
     keyHdr = NULL;
     fpos = 0;
     keyLen = 0;
+    keyType = 0;
     keyCompareLen = 0;
     isVariable = false;
 }

+ 7 - 7
system/jhtree/hlzw.h

@@ -27,7 +27,7 @@ typedef unsigned short KEYRECSIZE_T;
 class KeyCompressor 
 {
 public:
-    KeyCompressor() : comp(NULL) {}
+    KeyCompressor() {}
     ~KeyCompressor();
     void open(void *blk,int blksize, bool isVariable, bool rowcompression);
     void openBlob(void *blk,int blksize);
@@ -38,13 +38,13 @@ public:
     virtual void close();
     unsigned getCurrentOffset() { return (curOffset+0xf) & 0xfffffff0; }
 protected:
-    bool isVariable;
-    bool isBlob;
-    unsigned curOffset;
-    void *bufp;
-    int bufl;
+    bool isVariable = false;
+    bool isBlob = false;
+    unsigned curOffset = 0;
+    void *bufp = nullptr;
+    int bufl = 0;
     void testwrite(const void *p,size32_t s);
-    ICompressor *comp;
+    ICompressor *comp = nullptr;
 };
 
 #endif

+ 1 - 2
system/jhtree/keybuild.cpp

@@ -89,12 +89,11 @@ protected:
     unsigned __int64 sequence;
     CRC32StartHT crcStartPosTable;
     CRC32EndHT crcEndPosTable;
-    bool doCrc;
+    bool doCrc = false;
 
 public:
     CKeyBuilderBase(IFileIOStream *_out, unsigned flags, unsigned rawSize, unsigned nodeSize, unsigned _keyedSize, unsigned __int64 _startSequence) : out(_out)
     {
-        doCrc = false;
         sequence = _startSequence;
         keyHdr.setown(new CKeyHdr());
         keyValueSize = rawSize;

+ 24 - 24
system/jhtree/keydiff.cpp

@@ -33,7 +33,7 @@
 class RowBuffer
 {
 public:
-    RowBuffer() : rowsize(0), thisrowsize(0), buffsize(0), buffer(0), fpos(0) {}
+    RowBuffer() {}
 
     ~RowBuffer() { free(buffer); }
 
@@ -203,13 +203,13 @@ public:
     }
 
 private:
-    size32_t rowsize;
-    bool isVar;
-    size32_t thisrowsize;
-    size32_t buffsize;
-    void * buffer;
-    char * row;
-    offset_t * fpos;
+    size32_t rowsize = 0;
+    bool isVar = false;
+    size32_t thisrowsize = 0;
+    size32_t buffsize = 0;
+    void * buffer = nullptr;
+    char * row = nullptr;
+    offset_t * fpos = nullptr;
 };
 
 class CKeyReader: public CInterface
@@ -339,8 +339,8 @@ private:
     bool variableWidth;
     bool quickCompressed;
     Owned<IKeyDiffProgressCallback> progressCallback;
-    offset_t progressFrequency;
-    offset_t progressCount;
+    offset_t progressFrequency = 0;
+    offset_t progressCount = 0;
 };
 
 class CKeyFileReader: extends IKeyFileRowReader, public CInterface
@@ -461,9 +461,9 @@ private:
     Owned<IFileIOStream> keyStream;
     Owned<IKeyBuilder> keyBuilder;
     CRC32 crc;
-    size32_t keyedsize;
-    size32_t rowsize;
-    unsigned __int64 reccount;
+    size32_t keyedsize = 0;
+    size32_t rowsize = 0;
+    unsigned __int64 reccount = 0;
 };
 
 class KeyDiffVersion
@@ -641,19 +641,19 @@ private:
 
 private:
     Owned<IFileIOStream> stream;
-    offset_t crcStreamPos;
-    offset_t namesStreamPos;
-    offset_t endStreamPos;
+    offset_t crcStreamPos = 0;
+    offset_t namesStreamPos = 0;
+    offset_t endStreamPos = 0;
     KeyDiffVersion version;
     KeyDiffVersion minPatchVersion;
-    unsigned oldCRC;
-    unsigned newCRC;
-    unsigned patchCRC;
+    unsigned oldCRC = 0;
+    unsigned newCRC = 0;
+    unsigned patchCRC = 0;
     StringBuffer oldIndex;
     StringBuffer newIndex;
-    bool tlkInfo;
+    bool tlkInfo = false;
     StringBuffer newTLK;
-    unsigned tlkCRC;
+    unsigned tlkCRC = 0;
     CRC32 crcHeadVer, crcHeadCRCs, crcHeadNames;
 };
 
@@ -1471,8 +1471,8 @@ private:
     StringAttr oldIndex;
     StringAttr newIndex;
     StringAttr newTLK;
-    bool overwrite;
-    bool ignoreTLK;
+    bool overwrite = false;
+    bool ignoreTLK = false;
     CReadableKeyDiff keydiff;
     Owned<CKeyReader> oldInput;
     Owned<CKeyWriter> newOutput;
@@ -1485,7 +1485,7 @@ private:
     Owned<CTLKGenerator> tlkGen;
     Owned<INodeSender> tlkSender;
     Owned<IKeyDiffProgressCallback> progressCallback;
-    offset_t progressFrequency;
+    offset_t progressFrequency = 0;
 };
 
 IKeyDiffGenerator * createKeyDiffGenerator(char const * oldIndex, char const * newIndex, char const * patch, char const * newTLK, bool overwrite, unsigned compmode)