Check and remove high stack usage

I checked all stack overflow potential problems found with
gcc -Wstack-usage=16384
and
clang -Wframe-larger-than=16384 -no-inline

Fixes:
Added '#pragma clang diagnostic ignored "-Wframe-larger-than="'
  to a lot of function to where stack usage large but resonable.
- Added stack check warnings to BUILD scrips when using clang and debug.

Function changed to use malloc instead allocating things on stack:
- read_bootstrap_query() now allocates line_buffer (20000 bytes) with
  malloc() instead of using stack. This has a small performance impact
  but this is not releant for bootstrap.
- mroonga grn_select() used 65856 bytes on stack. Changed it to use
  malloc().
- Wsrep_schema::replay_transaction() and
  Wsrep_schema::recover_sr_transactions().
- Connect zipOpen3()

Not fixed:
- mroonga/vendor/groonga/lib/expr.c grn_proc_call() uses
  43712 byte on stack.  However this is not easy to fix as the stack
  used is caused by a lot of code generated by defines.
- Most changes in mroonga/groonga where only adding of pragmas to disable
  stack warnings.
- rocksdb/options/options_helper.cc uses 20288 of stack space.
  (no reason to fix except to get rid of the compiler warning)
- Causes using alloca() where the allocation size is resonable.
- An issue in libmariadb (reported to connectors).
This commit is contained in:
Monty 2024-04-19 13:10:58 +03:00
parent 07faba08b9
commit 0ccdf54b64
32 changed files with 296 additions and 109 deletions

View file

@ -267,6 +267,12 @@ if test `$CC -v 2>&1 | tail -1 | sed 's/ .*$//'` = 'gcc' ; then
fi
fi
if test `$CC -v 2>&1 | head -1 | sed 's/ .*$//'` = 'clang' ; then
dbug_cflags="$dbug_cflags -Wframe-larger-than=16384 -fno-inline"
c_warnings="$c_warnings -Wframe-larger-than=16384"
cxx_warnings="$cxx_warnings -Wframe-larger-than=16384"
fi
# If ccache (a compiler cache which reduces build time)
# (http://samba.org/ccache) is installed, use it.

View file

@ -896,6 +896,7 @@ static int disable_binlog()
return run_query("SET SQL_LOG_BIN=0", 0);
}
static int handle_request_for_tables(char *tables, size_t length,
my_bool view, my_bool dont_quote)
{
@ -1027,7 +1028,10 @@ static void insert_table_name(DYNAMIC_ARRAY *arr, char *in, size_t dblen)
insert_dynamic(arr, (uchar*) buf);
}
static void print_result()
/* Ok as mysqlcheck is not multi threaded */
PRAGMA_DISABLE_CHECK_STACK_FRAME
static void __attribute__((noinline)) print_result()
{
MYSQL_RES *res;
MYSQL_ROW row;
@ -1118,6 +1122,7 @@ static void print_result()
mysql_free_result(res);
DBUG_VOID_RETURN;
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
static int dbConnect(char *host, char *user, char *passwd)

View file

@ -1649,6 +1649,9 @@ drop_primary_key_list(void)
return 0;
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
static int
create_schema(MYSQL *mysql, const char *db, statement *stmt,
option_string *engine_stmt)
@ -1744,6 +1747,7 @@ limit_not_met:
DBUG_RETURN(0);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
static int
drop_schema(MYSQL *mysql, const char *db)

View file

@ -78,7 +78,7 @@ static my_bool non_blocking_api_enabled= 0;
#define MAX_DELIMITER_LENGTH 16
#define DEFAULT_MAX_CONN 64
#define DIE_BUFF_SIZE 256*1024
#define DIE_BUFF_SIZE 15*1024
#define RESULT_STRING_INIT_MEM 2048
#define RESULT_STRING_INCREMENT_MEM 2048

View file

@ -244,6 +244,9 @@ xb_fil_cur_open(
return(XB_FIL_CUR_SUCCESS);
}
/* Stack usage 131224 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
static bool page_is_corrupted(const byte *page, ulint page_no,
const xb_fil_cur_t *cursor,
const fil_space_t *space)
@ -347,6 +350,7 @@ static bool page_is_corrupted(const byte *page, ulint page_no,
return buf_page_is_corrupted(true, page, space->flags);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/** Reads and verifies the next block of pages from the source
file. Positions the cursor after the last read non-corrupted page.

View file

@ -70,5 +70,19 @@
# endif /* GNUC >= 3.1 */
#endif
/* Define pragmas to disable warnings for stack frame checking */
#if defined(__clang__)
#define PRAGMA_DISABLE_CHECK_STACK_FRAME \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wframe-larger-than=\"")
#define PRAGMA_REENABLE_CHECK_STACK_FRAME \
_Pragma("clang diagnostic pop")
#else
#define PRAGMA_DISABLE_CHECK_STACK_FRAME
#define PRAGMA_REENABLE_CHECK_STACK_FRAME
#endif
#endif /* _my_attribute_h */

View file

@ -33,26 +33,35 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
fgets_input_t input, fgets_fn_t fgets_fn,
int preserve_delimiter, int *error)
{
char line_buffer[MAX_BOOTSTRAP_LINE_SIZE];
char *line_buffer;
const char *line;
size_t len;
size_t query_len= 0;
int fgets_error= 0;
int exit_code= 0;
*error= 0;
line_buffer= (char*) malloc(MAX_BOOTSTRAP_LINE_SIZE);
*query_length= 0;
for ( ; ; )
{
line= (*fgets_fn)(line_buffer, sizeof(line_buffer), input, &fgets_error);
line= (*fgets_fn)(line_buffer, MAX_BOOTSTRAP_LINE_SIZE, input, &fgets_error);
if (error)
*error= fgets_error;
if (fgets_error != 0)
return READ_BOOTSTRAP_ERROR;
{
exit_code= READ_BOOTSTRAP_ERROR;
break;
}
if (line == NULL)
return (query_len == 0) ? READ_BOOTSTRAP_EOF : READ_BOOTSTRAP_ERROR;
{
exit_code= (query_len == 0) ? READ_BOOTSTRAP_EOF : READ_BOOTSTRAP_ERROR;
break;
}
len= strlen(line);
@ -98,7 +107,8 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
if (!p || !p[1])
{
/* Invalid DELIMITER specifier */
return READ_BOOTSTRAP_ERROR;
exit_code= READ_BOOTSTRAP_ERROR;
break;
}
delimiter.assign(p+1);
if (preserve_delimiter)
@ -106,7 +116,8 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
memcpy(query,line,len);
query[len]=0;
*query_length = (int)len;
return READ_BOOTSTRAP_SUCCESS;
exit_code= READ_BOOTSTRAP_SUCCESS;
break;
}
continue;
}
@ -125,7 +136,8 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
}
query[query_len]= '\0';
*query_length= (int)query_len;
return READ_BOOTSTRAP_QUERY_SIZE;
exit_code= READ_BOOTSTRAP_QUERY_SIZE;
break;
}
if (query_len != 0)
@ -152,8 +164,11 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
}
query[query_len]= 0;
*query_length= (int)query_len;
return READ_BOOTSTRAP_SUCCESS;
exit_code= READ_BOOTSTRAP_SUCCESS;
break;
}
}
free(line_buffer);
return exit_code;
}

View file

@ -2786,6 +2786,9 @@ int collect_statistics_for_table(THD *thd, TABLE *table)
After having been updated the statistical system tables are closed.
*/
/* Stack usage 20248 from clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int update_statistics_for_table(THD *thd, TABLE *table)
{
TABLE_LIST tables[STATISTICS_TABLES];
@ -2870,6 +2873,7 @@ int update_statistics_for_table(THD *thd, TABLE *table)
new_trans.restore_old_transaction();
DBUG_RETURN(rc);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/**
@ -3282,6 +3286,9 @@ end:
The function is called when executing the statement DROP TABLE 'tab'.
*/
/* Stack size 20248 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int delete_statistics_for_table(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *tab)
{
@ -3350,6 +3357,7 @@ int delete_statistics_for_table(THD *thd, const LEX_CSTRING *db,
new_trans.restore_old_transaction();
DBUG_RETURN(rc);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/**
@ -3894,6 +3902,9 @@ int rename_indexes_in_stat_table(THD *thd, TABLE *tab,
The function is called when executing any statement that renames a table
*/
/* Stack size 20968 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int rename_table_in_stat_tables(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *tab,
const LEX_CSTRING *new_db,
@ -3971,6 +3982,7 @@ int rename_table_in_stat_tables(THD *thd, const LEX_CSTRING *db,
new_trans.restore_old_transaction();
DBUG_RETURN(rc);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/**

View file

@ -80,6 +80,9 @@
#pragma GCC diagnostic ignored "-Wunused-label" /* yyexhaustedlab: */
#endif
/* Stack size 28200 with clang for MYSQLparse() and ORAparse() */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int yylex(void *yylval, void *yythd);
#define yyoverflow(A,B,C,D,E,F) \

View file

@ -1252,15 +1252,21 @@ int Wsrep_schema::replay_transaction(THD* orig_thd,
DBUG_ENTER("Wsrep_schema::replay_transaction");
DBUG_ASSERT(!fragments.empty());
THD thd(next_thread_id(), true);
thd.thread_stack= (orig_thd ? orig_thd->thread_stack :
(char*) &thd);
wsrep_assign_from_threadvars(&thd);
THD *thd= new THD(next_thread_id(), true);
if (!thd)
{
WSREP_WARN("Could not open allocate memory for THD");
DBUG_RETURN(1);
}
Wsrep_schema_impl::wsrep_off wsrep_off(&thd);
Wsrep_schema_impl::binlog_off binlog_off(&thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(&thd);
Wsrep_schema_impl::thd_context_switch thd_context_switch(orig_thd, &thd);
thd->thread_stack= (orig_thd ? orig_thd->thread_stack :
(char*) &thd);
wsrep_assign_from_threadvars(thd);
Wsrep_schema_impl::wsrep_off wsrep_off(thd);
Wsrep_schema_impl::binlog_off binlog_off(thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
Wsrep_schema_impl::thd_context_switch thd_context_switch(orig_thd, thd);
int ret= 1;
int error;
@ -1272,11 +1278,12 @@ int Wsrep_schema::replay_transaction(THD* orig_thd,
for (std::vector<wsrep::seqno>::const_iterator i= fragments.begin();
i != fragments.end(); ++i)
{
Wsrep_schema_impl::init_stmt(&thd);
if ((error= Wsrep_schema_impl::open_for_read(&thd, sr_table_str.c_str(), &frag_table_l)))
Wsrep_schema_impl::init_stmt(thd);
if ((error= Wsrep_schema_impl::open_for_read(thd, sr_table_str.c_str(), &frag_table_l)))
{
WSREP_WARN("Could not open SR table for read: %d", error);
Wsrep_schema_impl::finish_stmt(&thd);
Wsrep_schema_impl::finish_stmt(thd);
my_free(thd);
DBUG_RETURN(1);
}
frag_table= frag_table_l.table;
@ -1308,7 +1315,7 @@ int Wsrep_schema::replay_transaction(THD* orig_thd,
frag_table->field[4]->val_str(&buf);
{
Wsrep_schema_impl::thd_context_switch thd_context_switch(&thd, orig_thd);
Wsrep_schema_impl::thd_context_switch thd_context_switch(thd, orig_thd);
ret= wsrep_apply_events(orig_thd, rli, buf.ptr(), buf.length());
if (ret)
@ -1319,17 +1326,18 @@ int Wsrep_schema::replay_transaction(THD* orig_thd,
}
Wsrep_schema_impl::end_index_scan(frag_table);
Wsrep_schema_impl::finish_stmt(&thd);
Wsrep_schema_impl::finish_stmt(thd);
Wsrep_schema_impl::init_stmt(&thd);
Wsrep_schema_impl::init_stmt(thd);
if ((error= Wsrep_schema_impl::open_for_write(&thd,
if ((error= Wsrep_schema_impl::open_for_write(thd,
sr_table_str.c_str(),
&frag_table_l)))
{
WSREP_WARN("Could not open SR table for write: %d", error);
Wsrep_schema_impl::finish_stmt(&thd);
DBUG_RETURN(1);
Wsrep_schema_impl::finish_stmt(thd);
ret= 1;
break;
}
frag_table= frag_table_l.table;
@ -1355,60 +1363,68 @@ int Wsrep_schema::replay_transaction(THD* orig_thd,
break;
}
Wsrep_schema_impl::end_index_scan(frag_table);
Wsrep_schema_impl::finish_stmt(&thd);
Wsrep_schema_impl::finish_stmt(thd);
my_free(key);
key= NULL;
}
if (key)
my_free(key);
delete thd;
DBUG_RETURN(ret);
}
int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
{
DBUG_ENTER("Wsrep_schema::recover_sr_transactions");
THD storage_thd(next_thread_id(), true);
storage_thd.thread_stack= (orig_thd ? orig_thd->thread_stack :
THD *storage_thd= new THD(next_thread_id(), true);
if (!storage_thd)
{
WSREP_WARN("Could not open allocate memory for THD");
DBUG_RETURN(1);
}
storage_thd->thread_stack= (orig_thd ? orig_thd->thread_stack :
(char*) &storage_thd);
wsrep_assign_from_threadvars(&storage_thd);
wsrep_assign_from_threadvars(storage_thd);
TABLE* frag_table= 0;
TABLE_LIST frag_table_l;
TABLE* cluster_table= 0;
TABLE_LIST cluster_table_l;
Wsrep_storage_service storage_service(&storage_thd);
Wsrep_schema_impl::binlog_off binlog_off(&storage_thd);
Wsrep_schema_impl::wsrep_off wsrep_off(&storage_thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(&storage_thd);
Wsrep_storage_service storage_service(storage_thd);
Wsrep_schema_impl::binlog_off binlog_off(storage_thd);
Wsrep_schema_impl::wsrep_off wsrep_off(storage_thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(storage_thd);
Wsrep_schema_impl::thd_context_switch thd_context_switch(orig_thd,
&storage_thd);
storage_thd);
Wsrep_server_state& server_state(Wsrep_server_state::instance());
int ret= 1;
int error;
wsrep::id cluster_id;
Wsrep_schema_impl::init_stmt(&storage_thd);
storage_thd.wsrep_skip_locking= FALSE;
if (Wsrep_schema_impl::open_for_read(&storage_thd, cluster_table_str.c_str(),
Wsrep_schema_impl::init_stmt(storage_thd);
storage_thd->wsrep_skip_locking= FALSE;
if (Wsrep_schema_impl::open_for_read(storage_thd, cluster_table_str.c_str(),
&cluster_table_l))
{
Wsrep_schema_impl::finish_stmt(&storage_thd);
Wsrep_schema_impl::finish_stmt(storage_thd);
DBUG_RETURN(1);
}
cluster_table= cluster_table_l.table;
if (Wsrep_schema_impl::init_for_scan(cluster_table))
{
Wsrep_schema_impl::finish_stmt(&storage_thd);
Wsrep_schema_impl::finish_stmt(storage_thd);
DBUG_RETURN(1);
}
if ((error= Wsrep_schema_impl::next_record(cluster_table)))
{
Wsrep_schema_impl::end_scan(cluster_table);
Wsrep_schema_impl::finish_stmt(&storage_thd);
trans_commit(&storage_thd);
Wsrep_schema_impl::finish_stmt(storage_thd);
trans_commit(storage_thd);
if (error == HA_ERR_END_OF_FILE)
{
WSREP_INFO("Cluster table is empty, not recovering transactions");
@ -1423,20 +1439,20 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
Wsrep_schema_impl::scan(cluster_table, 0, cluster_id);
Wsrep_schema_impl::end_scan(cluster_table);
Wsrep_schema_impl::finish_stmt(&storage_thd);
Wsrep_schema_impl::finish_stmt(storage_thd);
std::ostringstream os;
os << cluster_id;
WSREP_INFO("Recovered cluster id %s", os.str().c_str());
storage_thd.wsrep_skip_locking= TRUE;
Wsrep_schema_impl::init_stmt(&storage_thd);
storage_thd->wsrep_skip_locking= TRUE;
Wsrep_schema_impl::init_stmt(storage_thd);
/*
Open the table for reading and writing so that fragments without
valid seqno can be deleted.
*/
if (Wsrep_schema_impl::open_for_write(&storage_thd, sr_table_str.c_str(),
if (Wsrep_schema_impl::open_for_write(storage_thd, sr_table_str.c_str(),
&frag_table_l))
{
WSREP_ERROR("Failed to open SR table for write");
@ -1492,7 +1508,7 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
transaction_id)))
{
DBUG_ASSERT(wsrep::starts_transaction(flags));
applier = wsrep_create_streaming_applier(&storage_thd, "recovery");
applier = wsrep_create_streaming_applier(storage_thd, "recovery");
server_state.start_streaming_applier(server_id, transaction_id,
applier);
applier->start_transaction(wsrep::ws_handle(transaction_id, 0),
@ -1520,9 +1536,10 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
}
}
Wsrep_schema_impl::end_scan(frag_table);
Wsrep_schema_impl::finish_stmt(&storage_thd);
trans_commit(&storage_thd);
storage_thd.set_mysys_var(0);
Wsrep_schema_impl::finish_stmt(storage_thd);
trans_commit(storage_thd);
storage_thd->set_mysys_var(0);
out:
delete storage_thd;
DBUG_RETURN(ret);
}

View file

@ -267,6 +267,9 @@ ha_archive::ha_archive(handlerton *hton, TABLE_SHARE *table_arg)
archive_reader_open= FALSE;
}
/* Stack size 50264 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int archive_discover(handlerton *hton, THD* thd, TABLE_SHARE *share)
{
DBUG_ENTER("archive_discover");
@ -308,6 +311,7 @@ ret:
my_free(frm_ptr);
DBUG_RETURN(my_errno);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/**
@brief Read version 1 meta file (5.0 compatibility routine).
@ -478,6 +482,10 @@ int ha_archive::read_data_header(azio_stream *file_to_read)
See ha_example.cc for a longer description.
*/
/* Stack size 49608 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
Archive_share *ha_archive::get_share(const char *table_name, int *rc)
{
Archive_share *tmp_share;
@ -540,6 +548,7 @@ err:
DBUG_RETURN(tmp_share);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
int Archive_share::init_archive_writer()
@ -761,6 +770,9 @@ int ha_archive::frm_compare(azio_stream *s)
of creation.
*/
/* Stack size 49608 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int ha_archive::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info)
{
@ -876,6 +888,7 @@ error:
/* Return error number, if we got one */
DBUG_RETURN(error ? error : -1);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/*
This is where the actual row is written out.
@ -1494,6 +1507,10 @@ int ha_archive::repair(THD* thd, HA_CHECK_OPT* check_opt)
The table can become fragmented if data was inserted, read, and then
inserted again. What we do is open up the file and recompress it completely.
*/
/* Stack size 50152 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
{
int rc= 0;
@ -1619,6 +1636,7 @@ error:
DBUG_RETURN(rc);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/*
Below is an example of how to setup row level locking.

View file

@ -6448,6 +6448,9 @@ char *ha_connect::GetDBfromName(const char *name)
ha_create_table() in handle.cc
*/
/* Stack size 25608 in clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int ha_connect::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info)
{
@ -6989,6 +6992,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
table= st;
DBUG_RETURN(rc);
} // end of create
PRAGMA_REENABLE_CHECK_STACK_FRAME
/**
Used to check whether a file based outward table can be populated by
@ -6996,6 +7000,10 @@ int ha_connect::create(const char *name, TABLE *table_arg,
- file does not exist or is void
- user has file privilege
*/
/* Stack size 16664 in clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
bool ha_connect::FileExists(const char *fn, bool bf)
{
if (!fn || !*fn)
@ -7046,6 +7054,7 @@ bool ha_connect::FileExists(const char *fn, bool bf)
return true;
} // end of FileExists
PRAGMA_REENABLE_CHECK_STACK_FRAME
// Called by SameString and NoFieldOptionChange
bool ha_connect::CheckString(PCSZ str1, PCSZ str2)

View file

@ -125,8 +125,11 @@ PTDB TDBMUL::Duplicate(PGLOBAL g)
/* have a LRECL that is the sum of the lengths of all components. */
/* This is why we use a big filename array to take care of that. */
/***********************************************************************/
PRAGMA_DISABLE_CHECK_STACK_FRAME
bool TDBMUL::InitFileNames(PGLOBAL g)
{
{
#define PFNZ 4096
#define FNSZ (_MAX_DRIVE+_MAX_DIR+_MAX_FNAME+_MAX_EXT)
PTDBDIR dirp;
@ -241,6 +244,7 @@ bool TDBMUL::InitFileNames(PGLOBAL g)
NumFiles = n;
return false;
} // end of InitFileNames
PRAGMA_REENABLE_CHECK_STACK_FRAME
/***********************************************************************/
/* The table column list is the sub-table column list. */

View file

@ -814,71 +814,66 @@ local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
/************************************************************/
extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) {
zip64_internal ziinit;
zip64_internal* zi;
int err=ZIP_OK;
ziinit.z_filefunc.zseek32_file = NULL;
ziinit.z_filefunc.ztell32_file = NULL;
if (pzlib_filefunc64_32_def==NULL)
fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
else
ziinit.z_filefunc = *pzlib_filefunc64_32_def;
if (!(zi = (zip64_internal*)ALLOC(sizeof(zip64_internal))))
return NULL;
ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
zi->z_filefunc.zseek32_file = NULL;
zi->z_filefunc.ztell32_file = NULL;
if (pzlib_filefunc64_32_def==NULL)
fill_fopen64_filefunc(&zi->z_filefunc.zfile_func64);
else
zi->z_filefunc = *pzlib_filefunc64_32_def;
zi->filestream = ZOPEN64(zi->z_filefunc,
pathname,
(append == APPEND_STATUS_CREATE) ?
(ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
(ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
if (ziinit.filestream == NULL)
return NULL;
if (append == APPEND_STATUS_CREATEAFTER)
ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
ziinit.in_opened_file_inzip = 0;
ziinit.ci.stream_initialised = 0;
ziinit.number_entry = 0;
ziinit.add_position_when_writing_offset = 0;
init_linkedlist(&(ziinit.central_dir));
zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
if (zi==NULL)
if (zi->filestream == NULL)
{
ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
free(zi);
return NULL;
}
if (append == APPEND_STATUS_CREATEAFTER)
ZSEEK64(zi->z_filefunc,zi->filestream,0,SEEK_END);
zi->begin_pos = ZTELL64(zi->z_filefunc,zi->filestream);
zi->in_opened_file_inzip = 0;
zi->ci.stream_initialised = 0;
zi->number_entry = 0;
zi->add_position_when_writing_offset = 0;
init_linkedlist(&(zi->central_dir));
/* now we add file in a zipfile */
# ifndef NO_ADDFILEINEXISTINGZIP
ziinit.globalcomment = NULL;
zi->globalcomment = NULL;
if (append == APPEND_STATUS_ADDINZIP)
{
// Read and Cache Central Directory Records
err = LoadCentralDirectoryRecord(&ziinit);
err = LoadCentralDirectoryRecord(zi);
}
if (globalcomment)
{
*globalcomment = ziinit.globalcomment;
*globalcomment = zi->globalcomment;
}
# endif /* !NO_ADDFILEINEXISTINGZIP*/
if (err != ZIP_OK)
{
# ifndef NO_ADDFILEINEXISTINGZIP
free(ziinit.globalcomment);
free(zi->globalcomment);
# endif /* !NO_ADDFILEINEXISTINGZIP*/
free(zi);
return NULL;
}
else
{
*zi = ziinit;
return (zipFile)zi;
}
}
@ -1027,7 +1022,6 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
int err = ZIP_OK;
# ifdef NOCRYPT
(crcForCrypting);
if (password != NULL)
return ZIP_PARAMERROR;
# endif

View file

@ -431,6 +431,10 @@ row_quiesce_write_header(
/*********************************************************************//**
Write the table meta data after quiesce.
@return DB_SUCCESS or error code */
/* Stack size 20904 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
static MY_ATTRIBUTE((nonnull, warn_unused_result))
dberr_t
row_quiesce_write_cfg(
@ -488,6 +492,7 @@ row_quiesce_write_cfg(
return(err);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/*********************************************************************//**
Check whether a table has an FTS index defined on it.

View file

@ -3605,6 +3605,9 @@ static my_bool translog_is_LSN_chunk(uchar type)
@retval 1 Error
*/
/* Stack size 26120 from clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
my_bool translog_init_with_table(const char *directory,
uint32 log_file_max_size,
uint32 server_version,
@ -4238,6 +4241,7 @@ err:
ma_message_no_user(0, "log initialization failed");
DBUG_RETURN(1);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/*

View file

@ -1558,6 +1558,9 @@ uint _ma_state_info_write(MARIA_SHARE *share, uint pWrite)
@retval 1 Error
*/
/* Stack size 26376 from clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
uint _ma_state_info_write_sub(File file, MARIA_STATE_INFO *state, uint pWrite)
{
uchar buff[MARIA_STATE_INFO_SIZE + MARIA_STATE_EXTRA_SIZE];
@ -1632,6 +1635,7 @@ uint _ma_state_info_write_sub(File file, MARIA_STATE_INFO *state, uint pWrite)
MYF(MY_NABP));
DBUG_RETURN(res != 0);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
static uchar *_ma_state_info_read(uchar *ptr, MARIA_STATE_INFO *state, myf flag)

View file

@ -1163,11 +1163,12 @@ end:
/*
The record may come from REPAIR, ALTER TABLE ENABLE KEYS, OPTIMIZE.
*/
prototype_redo_exec_hook(REDO_REPAIR_TABLE)
{
int error= 1;
MARIA_HA *info;
HA_CHECK param;
HA_CHECK *param;
char *name;
my_bool quick_repair;
DBUG_ENTER("exec_REDO_LOGREC_REDO_REPAIR_TABLE");
@ -1199,35 +1200,39 @@ prototype_redo_exec_hook(REDO_REPAIR_TABLE)
*/
tprint(tracef, " repairing...\n");
maria_chk_init(&param);
param.isam_file_name= name= info->s->open_file_name.str;
param.testflag= uint8korr(rec->header + FILEID_STORE_SIZE);
param.tmpdir= maria_tmpdir;
param.max_trid= max_long_trid;
if (!(param= my_malloc(PSI_INSTRUMENT_ME, sizeof(*param), MYF(MY_WME))))
DBUG_RETURN(0);
maria_chk_init(param);
param->isam_file_name= name= info->s->open_file_name.str;
param->testflag= uint8korr(rec->header + FILEID_STORE_SIZE);
param->tmpdir= maria_tmpdir;
param->max_trid= max_long_trid;
DBUG_ASSERT(maria_tmpdir);
info->s->state.key_map= uint8korr(rec->header + FILEID_STORE_SIZE + 8);
quick_repair= MY_TEST(param.testflag & T_QUICK);
quick_repair= MY_TEST(param->testflag & T_QUICK);
if (param.testflag & T_REP_PARALLEL)
if (param->testflag & T_REP_PARALLEL)
{
if (maria_repair_parallel(&param, info, name, quick_repair))
if (maria_repair_parallel(param, info, name, quick_repair))
goto end;
}
else if (param.testflag & T_REP_BY_SORT)
else if (param->testflag & T_REP_BY_SORT)
{
if (maria_repair_by_sort(&param, info, name, quick_repair))
if (maria_repair_by_sort(param, info, name, quick_repair))
goto end;
}
else if (maria_repair(&param, info, name, quick_repair))
else if (maria_repair(param, info, name, quick_repair))
goto end;
if (_ma_update_state_lsns(info->s, rec->lsn, trnman_get_min_safe_trid(),
TRUE, !(param.testflag & T_NO_CREATE_RENAME_LSN)))
TRUE, !(param->testflag & T_NO_CREATE_RENAME_LSN)))
goto end;
error= 0;
end:
my_free(param);
DBUG_RETURN(error);
}
@ -2579,6 +2584,8 @@ prototype_undo_exec_hook(UNDO_BULK_INSERT)
return error;
}
/* Stack size 18776 in clang. Ok as this is during recover */
PRAGMA_DISABLE_CHECK_STACK_FRAME
static int run_redo_phase(LSN lsn, LSN lsn_end, enum maria_apply_log_way apply)
{
@ -2822,6 +2829,7 @@ err:
translog_free_record_header(&rec);
DBUG_RETURN(1);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/**

View file

@ -143,6 +143,8 @@ static my_bool read_and_check_content(TRANSLOG_HEADER_BUFFER *rec,
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
int main(int argc __attribute__((unused)), char *argv[])
{
uint32 i;
@ -664,5 +666,6 @@ err:
my_end(0);
return(MY_TEST(exit_status()));
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
#include "../ma_check_standalone.h"

View file

@ -200,6 +200,7 @@ endif()
include_directories(
BEFORE
${CMAKE_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/lib

View file

@ -38,6 +38,7 @@
#include "grn_util.h"
#include "grn_cache.h"
#include "grn_window_functions.h"
#include <my_attribute.h>
#include <string.h>
#include <math.h>
@ -1060,6 +1061,8 @@ grn_table_create_validate(grn_ctx *ctx, const char *name, unsigned int name_size
return ctx->rc;
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
static grn_obj *
grn_table_create_with_max_n_subrecs(grn_ctx *ctx, const char *name,
unsigned int name_size, const char *path,
@ -1238,6 +1241,7 @@ grn_table_create_with_max_n_subrecs(grn_ctx *ctx, const char *name,
}
return res;
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
grn_obj *
grn_table_create(grn_ctx *ctx, const char *name, unsigned int name_size,
@ -4776,6 +4780,9 @@ _grn_table_key(grn_ctx *ctx, grn_obj *table, grn_id id, uint32_t *key_size)
/* column */
PRAGMA_DISABLE_CHECK_STACK_FRAME
grn_obj *
grn_column_create(grn_ctx *ctx, grn_obj *table,
const char *name, unsigned int name_size,
@ -4978,6 +4985,7 @@ exit :
if (!res && id) { grn_obj_delete_by_id(ctx, db, id, GRN_TRUE); }
GRN_API_RETURN(res);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
grn_obj *
grn_column_open(grn_ctx *ctx, grn_obj *table,
@ -8540,6 +8548,8 @@ grn_obj_spec_save(grn_ctx *ctx, grn_db_obj *obj)
grn_obj_close(ctx, &v);
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
inline static void
grn_obj_set_info_source_invalid_lexicon_error(grn_ctx *ctx,
const char *message,
@ -8590,6 +8600,8 @@ grn_obj_set_info_source_invalid_lexicon_error(grn_ctx *ctx,
source_name_size, source_name);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
inline static grn_rc
grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
{
@ -8597,7 +8609,7 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
grn_obj *lexicon = NULL;
grn_id lexicon_domain_id;
grn_obj *lexicon_domain = NULL;
grn_bool lexicon_domain_is_table;
grn_bool lexicon_domain_is_table __attribute__((unused));
grn_bool lexicon_have_tokenizer;
grn_id *source_ids;
int i, n_source_ids;
@ -9330,7 +9342,7 @@ remove_reference_tables(grn_ctx *ctx, grn_obj *table, grn_obj *db)
grn_bool is_close_opened_object_mode = GRN_FALSE;
grn_id table_id;
char table_name[GRN_TABLE_MAX_KEY_SIZE];
int table_name_size;
int table_name_size __attribute__((unused));
grn_table_cursor *cursor;
if (grn_thread_get_limit() == 1) {
@ -10317,12 +10329,10 @@ grn_db_spec_unpack(grn_ctx *ctx,
const char *error_message_tag)
{
grn_obj *db;
grn_db *db_raw;
grn_rc rc;
uint32_t spec_size;
db = ctx->impl->db;
db_raw = (grn_db *)db;
rc = grn_vector_decode(ctx,
decoded_spec,

View file

@ -20,6 +20,9 @@
#include "grn_ctx_impl.h"
#include "grn_db.h"
#include "grn_util.h"
#include <my_attribute.h>
PRAGMA_DISABLE_CHECK_STACK_FRAME
static void
grn_loader_save_error(grn_ctx *ctx, grn_loader *loader)
@ -1228,3 +1231,5 @@ grn_load(grn_ctx *ctx, grn_content_type input_type,
}
GRN_API_RETURN(ctx->rc);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME

View file

@ -20,6 +20,7 @@
#include "grn_db.h"
#include "grn_str.h"
#include "grn_normalizer.h"
#include <my_attribute.h>
#include <string.h>
@ -31,6 +32,8 @@
# include <onigmo.h>
#endif
PRAGMA_DISABLE_CHECK_STACK_FRAME
static const char *operator_names[] = {
"push",
"pop",
@ -1360,3 +1363,5 @@ grn_operator_exec_regexp(grn_ctx *ctx, grn_obj *target, grn_obj *pattern)
}
GRN_API_RETURN(matched);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME

View file

@ -18,6 +18,7 @@
#include "../grn_proc.h"
#include "../grn_db.h"
#include <my_attribute.h>
#include <groonga/plugin.h>
@ -73,6 +74,8 @@ command_object_list_dump_flags(grn_ctx *ctx, grn_obj_spec *spec)
GRN_OBJ_FIN(ctx, &flags);
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
static grn_obj *
command_object_list(grn_ctx *ctx,
int nargs,
@ -401,6 +404,7 @@ command_object_list(grn_ctx *ctx,
return NULL;
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
void
grn_proc_init_object_list(grn_ctx *ctx)

View file

@ -17,9 +17,8 @@
*/
#include "../grn_proc.h"
#include "../grn_db.h"
#include <my_attribute.h>
#include <groonga/plugin.h>
typedef struct {
@ -572,6 +571,8 @@ command_schema_table_output_token_filters(grn_ctx *ctx, grn_obj *table)
GRN_OBJ_FIN(ctx, &token_filters);
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
static void
command_schema_table_command_collect_arguments(grn_ctx *ctx,
grn_obj *table,
@ -692,6 +693,7 @@ command_schema_table_command_collect_arguments(grn_ctx *ctx,
#undef ADD_OBJECT_NAME
#undef ADD
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
static void
command_schema_table_output_command(grn_ctx *ctx, grn_obj *table)
@ -875,6 +877,8 @@ command_schema_output_indexes(grn_ctx *ctx, grn_obj *object)
}
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
static void
command_schema_column_command_collect_arguments(grn_ctx *ctx,
grn_obj *table,
@ -973,6 +977,7 @@ command_schema_column_command_collect_arguments(grn_ctx *ctx,
#undef ADD_OBJECT_NAME
#undef ADD
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
static void
command_schema_column_output_command(grn_ctx *ctx,

View file

@ -24,6 +24,7 @@
#include "../grn_util.h"
#include "../grn_cache.h"
#include "../grn_ii.h"
#include <my_attribute.h>
#include "../grn_ts.h"
@ -2912,7 +2913,7 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
uint32_t nhits;
grn_obj *outbuf = ctx->impl->output.buf;
grn_content_type output_type = ctx->impl->output.type;
char cache_key[GRN_CACHE_MAX_KEY_SIZE];
char *cache_key_buffer= 0;
uint32_t cache_key_size;
long long int threshold, original_threshold = 0;
grn_cache *cache_obj = grn_cache_current_get(ctx);
@ -2985,8 +2986,9 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
} GRN_HASH_EACH_END(ctx, cursor);
}
#undef DRILLDOWN_CACHE_SIZE
if (cache_key_size <= GRN_CACHE_MAX_KEY_SIZE) {
char *cp = cache_key;
if (cache_key_size <= GRN_CACHE_MAX_KEY_SIZE &&
(cache_key_buffer= (char*) malloc(cache_key_size+1))) {
char *cp = cache_key_buffer;
#define PUT_CACHE_KEY(string) \
if ((string).value) \
@ -3066,11 +3068,12 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
{
grn_rc rc;
rc = grn_cache_fetch(ctx, cache_obj, cache_key, cache_key_size, outbuf);
rc = grn_cache_fetch(ctx, cache_obj, cache_key_buffer, cache_key_size, outbuf);
if (rc == GRN_SUCCESS) {
GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_CACHE,
":", "cache(%" GRN_FMT_LLD ")",
(long long int)GRN_TEXT_LEN(outbuf));
free(cache_key_buffer);
return ctx->rc;
}
}
@ -3119,7 +3122,7 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
data->cache.length != 2 ||
data->cache.value[0] != 'n' ||
data->cache.value[1] != 'o')) {
grn_cache_update(ctx, cache_obj, cache_key, cache_key_size, outbuf);
grn_cache_update(ctx, cache_obj, cache_key_buffer, cache_key_size, outbuf);
}
goto exit;
}
@ -3186,7 +3189,7 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
data->cache.length != 2 ||
data->cache.value[0] != 'n' ||
data->cache.value[1] != 'o')) {
grn_cache_update(ctx, cache_obj, cache_key, cache_key_size, outbuf);
grn_cache_update(ctx, cache_obj, cache_key_buffer, cache_key_size, outbuf);
}
if (data->taintable > 0) {
grn_db_touch(ctx, DB_OBJ(data->tables.target)->db);
@ -3200,6 +3203,7 @@ exit :
/* GRN_LOG(ctx, GRN_LOG_NONE, "%d", ctx->seqno); */
free(cache_key_buffer);
return ctx->rc;
}
@ -3424,6 +3428,9 @@ grn_select_data_fill_drilldown_columns(grn_ctx *ctx,
strlen(prefix));
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
static grn_bool
grn_select_data_fill_drilldowns(grn_ctx *ctx,
grn_user_data *user_data,
@ -3562,6 +3569,7 @@ grn_select_data_fill_drilldowns(grn_ctx *ctx,
return succeeded;
}
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
static grn_obj *
command_select(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)

View file

@ -86,6 +86,8 @@ void test_no_instruments()
cleanup_instruments();
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
void test_no_instances()
{
int rc;
@ -245,6 +247,7 @@ void test_no_instances()
cleanup_file_hash();
cleanup_instruments();
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
void test_with_instances()
{

View file

@ -11421,6 +11421,9 @@ int spider_db_udf_ping_table_append_select(
DBUG_RETURN(0);
}
/* Stack size 33032 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
int spider_db_udf_ping_table_mon_next(
THD *thd,
SPIDER_TABLE_MON *table_mon,
@ -11567,6 +11570,7 @@ int spider_db_udf_ping_table_mon_next(
delete res;
DBUG_RETURN(error_num);
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
int spider_db_udf_copy_key_row(
spider_string *str,

View file

@ -358,6 +358,7 @@ handle_option(const struct my_option *opt, const char *arg,
return 0;
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
int
main(int argc, char *argv[])
@ -433,3 +434,4 @@ main(int argc, char *argv[])
return 0;
}
PRAGMA_REENABLE_CHECK_STACK_FRAME

View file

@ -568,6 +568,9 @@ static int my_process_result(MYSQL *mysql_arg)
#define MAX_RES_FIELDS 50
#define MAX_FIELD_DATA_SIZE 255
/* Stack usage 18888 with clang */
PRAGMA_DISABLE_CHECK_STACK_FRAME
static int my_process_stmt_result(MYSQL_STMT *stmt)
{
int field_count;
@ -656,6 +659,7 @@ static int my_process_stmt_result(MYSQL_STMT *stmt)
mysql_free_result(result);
return row_count;
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
/* Prepare statement, execute, and process result set for given query */

View file

@ -123,6 +123,8 @@ error6:
return TRUE;
}
PRAGMA_DISABLE_CHECK_STACK_FRAME
my_bool test_compare_operators(MY_BITMAP *map, uint bitsize)
{
uint i, j, test_bit1, test_bit2, test_bit3,test_bit4;
@ -228,6 +230,8 @@ error5:
test_bit1);
return TRUE;
}
PRAGMA_REENABLE_CHECK_STACK_FRAME
my_bool test_count_bits_set(MY_BITMAP *map, uint bitsize)
{

View file

@ -96,6 +96,8 @@ void sql_print_error(const char *format, ...)
/*** end of encryption tweaks and stubs ****************************/
PRAGMA_DISABLE_CHECK_STACK_FRAME
static IO_CACHE info;
#define CACHE_SIZE 16384
@ -472,3 +474,4 @@ int main(int argc __attribute__((unused)),char *argv[])
return exit_status();
}
PRAGMA_REENABLE_CHECK_STACK_FRAME