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
@ -198,9 +198,22 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
|
|||||||
|
|
||||||
#include <mysql/plugin.h>
|
#include <mysql/plugin.h>
|
||||||
|
|
||||||
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
|
#ifdef __cplusplus
|
||||||
#define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1))
|
#include <type_traits>
|
||||||
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
|
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
|
#define LEX_STRING_WITH_LEN(X) (X).str, (X).length
|
||||||
|
|
||||||
typedef struct st_mysql_const_lex_string LEX_CSTRING;
|
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)
|
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
|
// Ensure exclusive access to debug_sync_global.ds_signal
|
||||||
mysql_mutex_lock(&debug_sync_global.ds_mutex);
|
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;
|
void *client_extra;
|
||||||
THD *thd;
|
THD *thd;
|
||||||
|
|
||||||
toku_txn_get_client_id(txn, &client_id, &client_extra);
|
if (debug_sync_service)
|
||||||
thd = reinterpret_cast<THD *>(client_extra);
|
{
|
||||||
DEBUG_SYNC(thd, sync_point_name);
|
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)
|
#else // defined(ENABLED_DEBUG_SYNC)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user