mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 02:05:57 +01:00
ensure that STRING_WITH_LEN is only used with string literals
This is allowed: STRING_WITH_LEN("string literal") This is not: char *str = "pointer to string"; ... STRING_WITH_LEN(str) .. In C++ this is also allowed: const char str[] = "string literal"; ... STRING_WITH_LEN(str) ...
This commit is contained in:
parent
6a10468ed3
commit
0a6343909f
3 changed files with 23 additions and 7 deletions
|
@ -198,9 +198,22 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
|
|||
|
||||
#include <mysql/plugin.h>
|
||||
|
||||
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
|
||||
#define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1))
|
||||
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
|
||||
#ifdef __cplusplus
|
||||
#include <type_traits>
|
||||
template<typename T> inline const char *_swl_check(T s)
|
||||
{
|
||||
static_assert(std::is_same<T, const char (&)[sizeof(T)]>::value
|
||||
|| std::is_same<T, const char [sizeof(T)]>::value,
|
||||
"Wrong argument for STRING_WITH_LEN()");
|
||||
return s;
|
||||
}
|
||||
#define STRING_WITH_LEN(X) _swl_check<decltype(X)>(X), ((size_t) (sizeof(X) - 1))
|
||||
#else
|
||||
#define STRING_WITH_LEN(X) (X ""), ((size_t) (sizeof(X) - 1))
|
||||
#endif
|
||||
|
||||
#define USTRING_WITH_LEN(X) (uchar*) STRING_WITH_LEN(X)
|
||||
#define C_STRING_WITH_LEN(X) (char *) STRING_WITH_LEN(X)
|
||||
#define LEX_STRING_WITH_LEN(X) (X).str, (X).length
|
||||
|
||||
typedef struct st_mysql_const_lex_string LEX_CSTRING;
|
||||
|
|
|
@ -1292,7 +1292,7 @@ uchar *debug_sync_value_ptr(THD *thd)
|
|||
|
||||
if (opt_debug_sync_timeout)
|
||||
{
|
||||
static char on[]= "ON - current signal: '";
|
||||
static const char on[]= "ON - current signal: '";
|
||||
|
||||
// Ensure exclusive access to debug_sync_global.ds_signal
|
||||
mysql_mutex_lock(&debug_sync_global.ds_mutex);
|
||||
|
|
|
@ -64,9 +64,12 @@ inline void toku_debug_sync(struct tokutxn *txn, const char *sync_point_name) {
|
|||
void *client_extra;
|
||||
THD *thd;
|
||||
|
||||
toku_txn_get_client_id(txn, &client_id, &client_extra);
|
||||
thd = reinterpret_cast<THD *>(client_extra);
|
||||
DEBUG_SYNC(thd, sync_point_name);
|
||||
if (debug_sync_service)
|
||||
{
|
||||
toku_txn_get_client_id(txn, &client_id, &client_extra);
|
||||
thd = reinterpret_cast<THD *>(client_extra);
|
||||
debug_sync_service(thd, sync_point_name, strlen(sync_point_name));
|
||||
}
|
||||
}
|
||||
|
||||
#else // defined(ENABLED_DEBUG_SYNC)
|
||||
|
|
Loading…
Add table
Reference in a new issue