[geany/geany] 69a15c: javascript: Stop using longjmp() and friends
Colomban Wendling
git-noreply at xxxxx
Tue Dec 2 14:02:13 UTC 2014
Branch: refs/heads/master
Author: Colomban Wendling <ban at herbesfolles.org>
Committer: Colomban Wendling <ban at herbesfolles.org>
Date: Tue, 02 Dec 2014 14:02:13 UTC
Commit: 69a15cf2c1c8def91ffd7bc51ca8a1bfd2df563d
https://github.com/geany/geany/commit/69a15cf2c1c8def91ffd7bc51ca8a1bfd2df563d
Log Message:
-----------
javascript: Stop using longjmp() and friends
Fixes some memory leaks with malformed or partial files.
Modified Paths:
--------------
tagmanager/ctags/js.c
Modified: tagmanager/ctags/js.c
77 lines changed, 28 insertions(+), 49 deletions(-)
===================================================================
@@ -19,7 +19,6 @@
#include "general.h" /* must always come first */
#include <ctype.h> /* to define isalpha () */
#include <string.h>
-#include <setjmp.h>
#include <mio/mio.h>
#ifdef DEBUG
#include <stdio.h>
@@ -41,8 +40,6 @@
* DATA DECLARATIONS
*/
-typedef enum eException { ExceptionNone, ExceptionEOF } exception_t;
-
/*
* Tracks class and function names already created
*/
@@ -85,6 +82,7 @@ typedef struct sKeywordDesc {
typedef enum eTokenType {
TOKEN_UNDEFINED,
+ TOKEN_EOF,
TOKEN_CHARACTER,
TOKEN_CLOSE_PAREN,
TOKEN_SEMICOLON,
@@ -126,8 +124,6 @@ static tokenType LastTokenType;
static langType Lang_js;
-static jmp_buf Exception;
-
typedef enum {
JSTAG_FUNCTION,
JSTAG_CLASS,
@@ -458,7 +454,7 @@ static void readTokenFull (tokenInfo *const token, boolean include_newlines, vSt
switch (c)
{
- case EOF: longjmp (Exception, (int)ExceptionEOF); break;
+ case EOF: token->type = TOKEN_EOF; break;
case '(': token->type = TOKEN_OPEN_PAREN; break;
case ')': token->type = TOKEN_CLOSE_PAREN; break;
case ';': token->type = TOKEN_SEMICOLON; break;
@@ -669,32 +665,18 @@ static void skipArgumentList (tokenInfo *const token, boolean include_newlines,
{
int nest_level = 0;
- /*
- * Other databases can have arguments with fully declared
- * datatypes:
- * ( name varchar(30), text binary(10) )
- * So we must check for nested open and closing parantheses
- */
-
if (isType (token, TOKEN_OPEN_PAREN)) /* arguments? */
{
nest_level++;
if (repr)
vStringPut (repr, '(');
- while (! (isType (token, TOKEN_CLOSE_PAREN) && (nest_level == 0)))
+ while (nest_level > 0 && ! isType (token, TOKEN_EOF))
{
readTokenFull (token, FALSE, repr);
if (isType (token, TOKEN_OPEN_PAREN))
- {
nest_level++;
- }
- if (isType (token, TOKEN_CLOSE_PAREN))
- {
- if (nest_level > 0)
- {
- nest_level--;
- }
- }
+ else if (isType (token, TOKEN_CLOSE_PAREN))
+ nest_level--;
}
readTokenFull (token, include_newlines, NULL);
}
@@ -713,20 +695,13 @@ static void skipArrayList (tokenInfo *const token, boolean include_newlines)
if (isType (token, TOKEN_OPEN_SQUARE)) /* arguments? */
{
nest_level++;
- while (! (isType (token, TOKEN_CLOSE_SQUARE) && (nest_level == 0)))
+ while (nest_level > 0 && ! isType (token, TOKEN_EOF))
{
readToken (token);
if (isType (token, TOKEN_OPEN_SQUARE))
- {
nest_level++;
- }
- if (isType (token, TOKEN_CLOSE_SQUARE))
- {
- if (nest_level > 0)
- {
- nest_level--;
- }
- }
+ else if (isType (token, TOKEN_CLOSE_SQUARE))
+ nest_level--;
}
readTokenFull (token, include_newlines, NULL);
}
@@ -762,8 +737,9 @@ static boolean findCmdTerm (tokenInfo *const token, boolean include_newlines)
* Read until we find either a semicolon or closing brace.
* Any nested braces will be handled within.
*/
- while (! ( isType (token, TOKEN_SEMICOLON) ||
- isType (token, TOKEN_CLOSE_CURLY) ) )
+ while (! isType (token, TOKEN_SEMICOLON) &&
+ ! isType (token, TOKEN_CLOSE_CURLY) &&
+ ! isType (token, TOKEN_EOF))
{
/* Handle nested blocks */
if ( isType (token, TOKEN_OPEN_CURLY))
@@ -1132,7 +1108,8 @@ static boolean parseBlock (tokenInfo *const token, tokenInfo *const orig_parent)
* If we find a statement without a terminator consider the
* block finished, otherwise the stack will be off by one.
*/
- } while (! isType (token, TOKEN_CLOSE_CURLY) && read_next_token );
+ } while (! isType (token, TOKEN_EOF) &&
+ ! isType (token, TOKEN_CLOSE_CURLY) && read_next_token);
}
deleteToken (parent);
@@ -1209,7 +1186,8 @@ static boolean parseMethods (tokenInfo *const token, tokenInfo *const class)
/* skip whatever is the value */
while (! isType (token, TOKEN_COMMA) &&
- ! isType (token, TOKEN_CLOSE_CURLY))
+ ! isType (token, TOKEN_CLOSE_CURLY) &&
+ ! isType (token, TOKEN_EOF))
{
if (isType (token, TOKEN_OPEN_CURLY))
{
@@ -1329,7 +1307,8 @@ static boolean parseStatement (tokenInfo *const token, tokenInfo *const parent,
while (! isType (token, TOKEN_CLOSE_CURLY) &&
! isType (token, TOKEN_SEMICOLON) &&
- ! isType (token, TOKEN_EQUAL_SIGN) )
+ ! isType (token, TOKEN_EQUAL_SIGN) &&
+ ! isType (token, TOKEN_EOF))
{
if (isType (token, TOKEN_OPEN_CURLY))
parseBlock (token, parent);
@@ -1403,9 +1382,10 @@ static boolean parseStatement (tokenInfo *const token, tokenInfo *const parent,
readToken (method_body_token);
vStringCopy (method_body_token->scope, token->scope);
- while (! ( isType (method_body_token, TOKEN_SEMICOLON) ||
- isType (method_body_token, TOKEN_CLOSE_CURLY) ||
- isType (method_body_token, TOKEN_OPEN_CURLY)) )
+ while (! isType (method_body_token, TOKEN_SEMICOLON) &&
+ ! isType (method_body_token, TOKEN_CLOSE_CURLY) &&
+ ! isType (method_body_token, TOKEN_OPEN_CURLY) &&
+ ! isType (method_body_token, TOKEN_EOF))
{
if ( isType (method_body_token, TOKEN_OPEN_PAREN) )
skipArgumentList(method_body_token, FALSE,
@@ -1728,7 +1708,7 @@ static boolean parseStatement (tokenInfo *const token, tokenInfo *const parent,
if (parenDepth > 0)
{
- while (parenDepth > 0)
+ while (parenDepth > 0 && ! isType (token, TOKEN_EOF))
{
if (isType (token, TOKEN_OPEN_PAREN))
parenDepth++;
@@ -1795,7 +1775,8 @@ static void parseUI5 (tokenInfo *const token)
if (isType (token, TOKEN_PERIOD))
{
readToken (token);
- while (! isType (token, TOKEN_OPEN_PAREN) )
+ while (! isType (token, TOKEN_OPEN_PAREN) &&
+ ! isType (token, TOKEN_EOF))
{
readToken (token);
}
@@ -1813,7 +1794,8 @@ static void parseUI5 (tokenInfo *const token)
do
{
parseMethods (token, name);
- } while (! isType (token, TOKEN_CLOSE_CURLY) );
+ } while (! isType (token, TOKEN_CLOSE_CURLY) &&
+ ! isType (token, TOKEN_EOF));
}
deleteToken (name);
@@ -1884,7 +1866,7 @@ static void parseJsFile (tokenInfo *const token)
parseUI5 (token);
else
parseLine (token, token, FALSE);
- } while (TRUE);
+ } while (! isType (token, TOKEN_EOF));
}
static void initialize (const langType language)
@@ -1897,15 +1879,12 @@ static void initialize (const langType language)
static void findJsTags (void)
{
tokenInfo *const token = newToken ();
- exception_t exception;
ClassNames = stringListNew ();
FunctionNames = stringListNew ();
LastTokenType = TOKEN_UNDEFINED;
- exception = (exception_t) (setjmp (Exception));
- while (exception == ExceptionNone)
- parseJsFile (token);
+ parseJsFile (token);
stringListDelete (ClassNames);
stringListDelete (FunctionNames);
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list