Navigation Menu

Skip to content

Commit

Permalink
Add missing empty array check
Browse files Browse the repository at this point in the history
The following commands might enter long loop:

  * pgroonga_snippet_html
  * pgroonga_highlight_html
  * pgroonga_command
  • Loading branch information
kou committed Oct 7, 2017
1 parent 98df502 commit af2d78b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/pgrn-keywords.c
Expand Up @@ -30,7 +30,10 @@ PGrnKeywordsUpdateTable(ArrayType *keywords, grn_obj *keywordsTable)

GRN_BULK_REWIND(&keywordIDs);

n = ARR_DIMS(keywords)[0];
if (ARR_NDIM(keywords) == 0)
n = 0;
else
n = ARR_DIMS(keywords)[0];
for (i = 1; i <= n; i++)
{
Datum keywordDatum;
Expand Down
3 changes: 3 additions & 0 deletions src/pgrn-query-expand.c
Expand Up @@ -120,6 +120,9 @@ func_query_expander_postgresql(grn_ctx *ctx,
int i, n;

synonymsArray = DatumGetArrayTypeP(synonymsDatum);
if (ARR_NDIM(synonymsArray) == 0)
continue;

n = ARR_DIMS(synonymsArray)[0];
if (n == 0)
continue;
Expand Down
5 changes: 4 additions & 1 deletion src/pgrn-snippet-html.c
Expand Up @@ -42,7 +42,10 @@ PGrnSnipCreate(ArrayType *keywords)
{
int i, n;

n = ARR_DIMS(keywords)[0];
if (ARR_NDIM(keywords) == 0)
n = 0;
else
n = ARR_DIMS(keywords)[0];
for (i = 1; i <= n; i++)
{
Datum keywordDatum;
Expand Down
8 changes: 4 additions & 4 deletions src/pgroonga.c
Expand Up @@ -1370,10 +1370,10 @@ pgroonga_command(PG_FUNCTION_ARGS)
ArrayType *arguments = PG_GETARG_ARRAYTYPE_P(1);
int i, n;

n = ARR_DIMS(arguments)[0];
if ((n % 2) != 0)
{
}
if (ARR_NDIM(arguments) == 0)
n = 0;
else
n = ARR_DIMS(arguments)[0];

grn_obj_reinit(ctx, command, GRN_DB_TEXT, 0);
GRN_TEXT_PUT(ctx,
Expand Down

0 comments on commit af2d78b

Please sign in to comment.