Static analyzer fixes.

This commit is contained in:
Jim Derry 2021-07-30 18:32:34 -04:00
parent bd751a8bcd
commit 5f98ccd606
7 changed files with 15 additions and 18 deletions

View file

@ -76,7 +76,8 @@ void TY_(freeFileSource)( TidyInputSource* inp, Bool closeIt )
if ( closeIt && fin && fin->fp )
fclose( fin->fp );
tidyBufFree( &fin->unget );
TidyFree( fin->unget.allocator, fin );
if (fin)
TidyFree( fin->unget.allocator, fin );
}
void TIDY_CALL TY_(filesink_putByte)( void* sinkData, byte bv )

View file

@ -4477,7 +4477,7 @@ void TY_(growStack)(Stack *stack)
{
uint new_capacity = stack->capacity * 2;
Node **firstNode = (Node **)TidyAlloc(stack->allocator, new_capacity);
Node **firstNode = (Node **)TidyAlloc(stack->allocator, new_capacity * sizeof(Node**));
memcpy( firstNode, stack->firstNode, sizeof(Node**) * (stack->top + 1) );
TidyFree(stack->allocator, stack->firstNode);

View file

@ -792,7 +792,7 @@ TidyMessageImpl *formatStandard(TidyDocImpl* doc, Node *element, Node *node, uin
case TAG_NOT_ALLOWED_IN:
/* Can we use `rpt` here? No; `element` has a value in every case. */
return TY_(tidyMessageCreateWithNode)(doc, node, code, level, nodedesc, element->element );
return TY_(tidyMessageCreateWithNode)(doc, node, code, level, nodedesc, element ? element->element : NULL );
case INSERTING_TAG:
case MISSING_STARTTAG:
@ -804,7 +804,7 @@ TidyMessageImpl *formatStandard(TidyDocImpl* doc, Node *element, Node *node, uin
case UNEXPECTED_ENDTAG_IN:
/* Can we use `rpt` here? No; `element` has a value in every case. */
return TY_(tidyMessageCreateWithNode)(doc, node, code, level, node->element, element->element );
return TY_(tidyMessageCreateWithNode)(doc, node, code, level, node->element, element ? element->element : NULL );
case BAD_CDATA_CONTENT:
case CONTENT_AFTER_BODY:
@ -848,16 +848,16 @@ TidyMessageImpl *formatStandard(TidyDocImpl* doc, Node *element, Node *node, uin
case MISSING_ENDTAG_FOR:
case MISSING_ENDTAG_OPTIONAL:
case PREVIOUS_LOCATION:
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, element->element );
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, element? element->element : NULL );
case MISSING_ENDTAG_BEFORE:
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, element->element, nodedesc );
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, element? element->element : NULL, nodedesc );
case COERCE_TO_ENDTAG:
case NON_MATCHING_ENDTAG:
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, node->element, node->element );
case TOO_MANY_ELEMENTS_IN:
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, node->element, element->element);
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, node->element, element ? element->element : NULL);
}
@ -1504,7 +1504,7 @@ uint TY_(getNextErrorCode)( TidyIterator* iter )
}
*iter = (TidyIterator)( itemIndex <= tidyErrorCodeListSize() ? itemIndex : (size_t)0 );
return item->value;
return item ? item->value : 0;
}

View file

@ -203,7 +203,6 @@ static TidyMessageImpl *tidyMessageCreateInitV( TidyDocImpl *doc,
i = TY_(tmbstrlen)(result->messageOutput);
if (i < sizeMessageBuf)
TY_(tmbsnprintf)(result->messageOutput + i, sizeMessageBuf - i, " (%s)", pc );
i = 0;
}
result->allowMessage = yes;

View file

@ -2345,7 +2345,7 @@ void* TY_(oldParseDefList)(TidyDocImpl* doc, Node *list, GetTokenMode mode)
* unless node has been blown away because the
* center was empty, as above.
*/
if (parent->last == node)
if (parent && parent->last == node)
{
list = TY_(InferredTag)(doc, TidyTag_DL);
TY_(InsertNodeAfterElement)(node, list);
@ -4225,14 +4225,14 @@ void* TY_(oldParseFrameSet)(TidyDocImpl* doc, Node *frameset, GetTokenMode ARG_U
TY_(Report)(doc, frameset, node, INSERTING_TAG);
}
if (node->type == StartTag && (node->tag->model & CM_FRAMES))
if (node->type == StartTag && (node->tag && node->tag->model & CM_FRAMES))
{
TY_(InsertNodeAtEnd)(frameset, node);
lexer->excludeBlocks = no;
ParseTag(doc, node, MixedContent);
continue;
}
else if (node->type == StartEndTag && (node->tag->model & CM_FRAMES))
else if (node->type == StartEndTag && (node->tag && node->tag->model & CM_FRAMES))
{
TY_(InsertNodeAtEnd)(frameset, node);
continue;
@ -4345,7 +4345,7 @@ Node* TY_(ParseHTML)( TidyDocImpl *doc, Node *html, GetTokenMode mode, Bool popS
}
/* We did not expect to find an html closing tag here! */
if (node->tag == html->tag && node->type == EndTag)
if (html && (node->tag == html->tag) && (node->type == EndTag))
{
TY_(Report)(doc, html, node, DISCARDING_UNEXPECTED);
TY_(FreeNode)( doc, node);
@ -5382,7 +5382,8 @@ Node* TY_(ParseNamespace)( TidyDocImpl* doc, Node *basenode, GetTokenMode mode,
if (outside == no)
{
/* EndTag for a node within the basenode subtree. Roll on... */
n->closed = yes;
if (n)
n->closed = yes;
TY_(FreeNode)(doc, node);
node = n;

View file

@ -1190,8 +1190,6 @@ static void PPrintAttribute( TidyDocImpl* doc, uint indent,
indent += xtra;
PCondFlushLineSmart( doc, indent );
}
else
indAttrs = no;
}
CheckWrapIndent( doc, indent );

View file

@ -590,7 +590,6 @@ void TY_(WriteChar)( uint c, StreamOut* out )
if ( !TY_(IsValidUTF16FromUCS4)(c) )
{
/* invalid UTF-16 value */
c = 0;
numChars = 0;
}
else if ( TY_(IsCombinedChar)(c) )
@ -599,7 +598,6 @@ void TY_(WriteChar)( uint c, StreamOut* out )
numChars = 2;
if ( !TY_(SplitSurrogatePair)(c, &theChars[0], &theChars[1]) )
{
c = 0;
numChars = 0;
}
}