Skip to content

Commit

Permalink
typescript: Suppress clang warning
Browse files Browse the repository at this point in the history
Clang warns this:

```
../parsers/typescript.c:740:18: warning: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior [-Wvarargs]
        va_start (args, skipUnparsed);
                        ^
../parsers/typescript.c:732:56: note: parameter of type 'bool' is declared here
static bool tryInSequence(tokenInfo *const token, bool skipUnparsed, ...)
                                                       ^
```

See also:
https://wiki.sei.cmu.edu/confluence/display/cplusplus/EXP58-CPP.+Pass+an+object+of+the+correct+type+to+va_start

It seems that passing `bool` to `va_start` has undefined behavior.
I think that the first argument after `skipUnparsed` is mandatory.
So, I added `parser` argument after `skipUnparsed`. Then, this causes
type mismatch between `parseComment()` function. So, I also updated the
function to match with `Parser` type.
  • Loading branch information
k-takata committed Oct 30, 2019
1 parent d01f4fa commit 6dbe3a4
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions parsers/typescript.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,40 +479,40 @@ CTAGS_INLINE void parseWordToken(const int c, tokenInfo *const token, const char
result->status = PARSER_FAILED;
}

CTAGS_INLINE void parseComment(const int c, tokenInfo *const token, commentState *state, parserResult *const result)
CTAGS_INLINE void parseComment(const int c, tokenInfo *const token, parserState *state, parserResult *const result)
{
if (state->parsed < 2)
if (state->comment.parsed < 2)
{
parseWordToken (c, token, "//", TOKEN_COMMENT_BLOCK, &state->parsed, result);
parseWordToken (c, token, "//", TOKEN_COMMENT_BLOCK, &state->comment.parsed, result);

if (result->status == PARSER_FAILED)
{
parseWordToken (c, token, "/*", TOKEN_COMMENT_BLOCK, &state->parsed, result);
parseWordToken (c, token, "/*", TOKEN_COMMENT_BLOCK, &state->comment.parsed, result);
if (result->status == PARSER_FINISHED)
{
result->status = PARSER_NEEDS_MORE_INPUT;
state->isBlock = true;
state->comment.isBlock = true;
}
}
else if (result->status == PARSER_FINISHED)
{
result->status = PARSER_NEEDS_MORE_INPUT;
state->isBlock = false;
state->comment.isBlock = false;
}

return;
}

state->parsed += 1;
state->comment.parsed += 1;

if (c == EOF) result->status = PARSER_FINISHED;
else if (state->isBlock)
else if (state->comment.isBlock)
{
parseWordToken (c, token, "*/", TOKEN_COMMENT_BLOCK, &state->blockParsed, result);
parseWordToken (c, token, "*/", TOKEN_COMMENT_BLOCK, &state->comment.blockParsed, result);

if (result->status == PARSER_FAILED)
{
state->blockParsed = c == '*' ? 1 : 0;
state->comment.blockParsed = c == '*' ? 1 : 0;
result->status = PARSER_NEEDS_MORE_INPUT;
}
}
Expand Down Expand Up @@ -729,17 +729,17 @@ CTAGS_INLINE bool tryParser(Parser parser, tokenInfo *const token, bool skipWhit
return result.status == PARSER_FINISHED;
}

static bool tryInSequence(tokenInfo *const token, bool skipUnparsed, ...)
static bool tryInSequence(tokenInfo *const token, bool skipUnparsed, Parser parser, ...)
{
Parser currentParser = NULL;
bool result = false;

tryParser (parseWhiteChars, token, false);

va_list args;
va_start (args, skipUnparsed);
va_start (args, parser);

currentParser = va_arg (args, Parser);
currentParser = parser;
while (! result && currentParser)
{
result = tryParser (currentParser, token, false);
Expand Down

0 comments on commit 6dbe3a4

Please sign in to comment.