From ee52d7a5f2325315de5391696bef64336ad88dbc Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 15 Apr 2005 21:47:55 +0000 Subject: [PATCH] Fix bug in CCL parser that could caused uninialized values of token member ws_prefix_len in some cases. Removed ccl_token_simple function. --- include/yaz/ccl.h | 9 +------ src/ccltoken.c | 69 +++-------------------------------------------------- test/tstccl.c | 10 ++++---- 3 files changed, 10 insertions(+), 78 deletions(-) diff --git a/include/yaz/ccl.h b/include/yaz/ccl.h index b827ae2..d0a2b09 100644 --- a/include/yaz/ccl.h +++ b/include/yaz/ccl.h @@ -49,7 +49,7 @@ /* * CCL - header file * - * $Id: ccl.h,v 1.21 2005-03-15 16:32:52 adam Exp $ + * $Id: ccl.h,v 1.22 2005-04-15 21:47:55 adam Exp $ * * Old Europagate Log: * @@ -279,13 +279,6 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command); YAZ_EXPORT struct ccl_token *ccl_tokenize (const char *command); -/** - * Splits CCL command into tokens. This function is obsolete. Use - * ccl_parser_tokenize instead. - */ -YAZ_EXPORT -struct ccl_token *ccl_token_simple (const char *command); - /** * Deletes token list */ diff --git a/src/ccltoken.c b/src/ccltoken.c index c4f0a60..d7b0d5f 100644 --- a/src/ccltoken.c +++ b/src/ccltoken.c @@ -48,7 +48,7 @@ /* CCL - lexical analysis * Europagate, 1995 * - * $Id: ccltoken.c,v 1.6 2005-03-15 16:32:52 adam Exp $ + * $Id: ccltoken.c,v 1.7 2005-04-15 21:47:56 adam Exp $ * * Old Europagate Log: * @@ -137,68 +137,6 @@ static int token_cmp (CCL_parser cclp, const char *kw, struct ccl_token *token) } /* - * ccl_token_simple: tokenize CCL raw tokens - */ -struct ccl_token *ccl_token_simple (const char *command) -{ - const char *cp = command; - struct ccl_token *first = NULL; - struct ccl_token *last = NULL; - - while (1) - { - while (*cp && strchr (" \t\r\n", *cp)) - { - cp++; - continue; - } - if (!first) - { - first = last = (struct ccl_token *)xmalloc (sizeof (*first)); - ccl_assert (first); - last->prev = NULL; - } - else - { - last->next = (struct ccl_token *)xmalloc (sizeof(*first)); - ccl_assert (last->next); - last->next->prev = last; - last = last->next; - } - last->next = NULL; - last->name = cp; - last->len = 1; - switch (*cp++) - { - case '\0': - last->kind = CCL_TOK_EOL; - return first; - case '\"': - last->kind = CCL_TOK_TERM; - last->name = cp; - last->len = 0; - while (*cp && *cp != '\"') - { - cp++; - ++ last->len; - } - if (*cp == '\"') - cp++; - break; - default: - while (*cp && !strchr (" \t\n\r", *cp)) - { - cp++; - ++ last->len; - } - last->kind = CCL_TOK_TERM; - } - } - return first; -} - - -/* * ccl_tokenize: tokenize CCL command string. * return: CCL token list. */ @@ -213,10 +151,7 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) { const unsigned char *cp0 = cp; while (*cp && strchr (" \t\r\n", *cp)) - { cp++; - continue; - } if (!first) { first = last = (struct ccl_token *)xmalloc (sizeof (*first)); @@ -337,6 +272,8 @@ struct ccl_token *ccl_token_add (struct ccl_token *at) n->kind = CCL_TOK_TERM; n->name = 0; n->len = 0; + n->ws_prefix_buf = 0; + n->ws_prefix_len = 0; return n; } diff --git a/test/tstccl.c b/test/tstccl.c index bf5b487..c816601 100644 --- a/test/tstccl.c +++ b/test/tstccl.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tstccl.c,v 1.7 2005-03-15 16:32:53 adam Exp $ + * $Id: tstccl.c,v 1.8 2005-04-15 21:47:56 adam Exp $ */ /* CCL test */ @@ -93,9 +93,11 @@ void tst1(int pass, int *number_of_errors) for (i = 0; query_str[i].query; i++) { - struct ccl_token *token_list = - ccl_parser_tokenize(parser, query_str[i].query); - struct ccl_rpn_node *rpn = ccl_parser_find(parser, token_list); + struct ccl_token *token_list; + struct ccl_rpn_node *rpn; + + token_list = ccl_parser_tokenize(parser, query_str[i].query); + rpn = ccl_parser_find(parser, token_list); ccl_token_del (token_list); if (rpn) { -- 1.7.10.4