From ebca7073359196a1f46a7db1b6900648f154ae27 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 9 Dec 2016 13:06:26 +0200 Subject: [PATCH] QC: Always set number of returned items qc_get_table_names() and qc_get_database_names() now always set the number items, also in case of error. That is, it is now always safe to start iterating using the number of items without first checking the returned pointer. --- query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc | 6 +----- query_classifier/qc_sqlite/qc_sqlite.c | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index fa900b4ec..6de18ce88 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -1342,11 +1342,7 @@ char** qc_get_table_names(GWBUF* querybuf, int* tblsize, bool fullnames) } /*< while(lex->current_select) */ retblock: - - if (tblsize) - { - *tblsize = i; - } + *tblsize = i; return tables; } diff --git a/query_classifier/qc_sqlite/qc_sqlite.c b/query_classifier/qc_sqlite/qc_sqlite.c index 910bd323c..91149d47c 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.c +++ b/query_classifier/qc_sqlite/qc_sqlite.c @@ -2971,6 +2971,8 @@ static char** qc_sqlite_get_table_names(GWBUF* query, int* tblsize, bool fullnam char** table_names = NULL; QC_SQLITE_INFO* info = get_query_info(query); + *tblsize = 0; + if (info) { if (qc_info_is_valid(info->status)) @@ -3054,6 +3056,8 @@ static char** qc_sqlite_get_database_names(GWBUF* query, int* sizep) char** database_names = NULL; QC_SQLITE_INFO* info = get_query_info(query); + *sizep = 0; + if (info) { if (qc_info_is_valid(info->status))