src, tools: add check for left leaning pointers

This commit adds a rule to cpplint to check that pointers in the code
base lean to the left and not right, and also fixes the violations
reported.

PR-URL: https://github.com/nodejs/node/pull/21010
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Daniel Bevenius 2018-05-16 11:50:48 +02:00
parent 75e9165988
commit cbc3dd997e
23 changed files with 114 additions and 87 deletions

View File

@ -633,7 +633,7 @@ class QueryWrap : public AsyncWrap {
wrap->env()->CloseHandle(handle, CaresAsyncClose);
}
static void Callback(void *arg, int status, int timeouts,
static void Callback(void* arg, int status, int timeouts,
unsigned char* answer_buf, int answer_len) {
QueryWrap* wrap = static_cast<QueryWrap*>(arg);
@ -661,7 +661,7 @@ class QueryWrap : public AsyncWrap {
uv_async_send(async_handle);
}
static void Callback(void *arg, int status, int timeouts,
static void Callback(void* arg, int status, int timeouts,
struct hostent* host) {
QueryWrap* wrap = static_cast<QueryWrap*>(arg);

View File

@ -349,7 +349,7 @@ inline uv_idle_t* Environment::immediate_idle_handle() {
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
HandleCleanupCb cb,
void *arg) {
void* arg) {
handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg});
}

View File

@ -615,7 +615,7 @@ class Environment {
// Register clean-up cb to be called on environment destruction.
inline void RegisterHandleCleanup(uv_handle_t* handle,
HandleCleanupCb cb,
void *arg);
void* arg);
template <typename T, typename OnCloseCallback>
inline void CloseHandle(T* handle, OnCloseCallback callback);

View File

@ -22,9 +22,9 @@ using v8::Value;
Local<Value> ErrnoException(Isolate* isolate,
int errorno,
const char *syscall,
const char *msg,
const char *path) {
const char* syscall,
const char* msg,
const char* path) {
Environment* env = Environment::GetCurrent(isolate);
Local<Value> e;
@ -143,8 +143,8 @@ Local<Value> UVException(Isolate* isolate,
#ifdef _WIN32
// Does about the same as strerror(),
// but supports all windows error messages
static const char *winapi_strerror(const int errorno, bool* must_free) {
char *errmsg = nullptr;
static const char* winapi_strerror(const int errorno, bool* must_free) {
char* errmsg = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, errorno,

View File

@ -320,7 +320,7 @@ static struct {
}
#if HAVE_INSPECTOR
bool StartInspector(Environment *env, const char* script_path,
bool StartInspector(Environment* env, const char* script_path,
const DebugOptions& options) {
// Inspector agent can't fail to start, but if it was configured to listen
// right away on the websocket port and fails to bind/etc, this will return
@ -328,7 +328,7 @@ static struct {
return env->inspector_agent()->Start(platform_, script_path, options);
}
bool InspectorStarted(Environment *env) {
bool InspectorStarted(Environment* env) {
return env->inspector_agent()->IsStarted();
}
#endif // HAVE_INSPECTOR
@ -357,7 +357,7 @@ static struct {
void Dispose() {}
void DrainVMTasks(Isolate* isolate) {}
void CancelVMTasks(Isolate* isolate) {}
bool StartInspector(Environment *env, const char* script_path,
bool StartInspector(Environment* env, const char* script_path,
const DebugOptions& options) {
env->ThrowError("Node compiled with NODE_USE_V8_PLATFORM=0");
return true;
@ -379,7 +379,7 @@ static struct {
#endif // !NODE_USE_V8_PLATFORM
#if !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR
bool InspectorStarted(Environment *env) {
bool InspectorStarted(Environment* env) {
return false;
}
#endif // !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR
@ -424,7 +424,7 @@ static void PrintErrorString(const char* format, ...) {
va_end(ap);
}
const char *signo_string(int signo) {
const char* signo_string(int signo) {
#define SIGNO_CASE(e) case e: return #e;
switch (signo) {
#ifdef SIGHUP
@ -2442,7 +2442,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
Local<Array> envarr = Array::New(isolate);
WCHAR* p = environment;
while (*p) {
WCHAR *s;
WCHAR* s;
if (*p == L'=') {
// If the key starts with '=' it is a hidden environment variable.
p += wcslen(p) + 1;

View File

@ -208,7 +208,7 @@ NODE_EXTERN extern bool force_fips_crypto;
# endif
#endif
NODE_EXTERN int Start(int argc, char *argv[]);
NODE_EXTERN int Start(int argc, char* argv[]);
NODE_EXTERN void Init(int* argc,
const char** argv,
int* exec_argc,
@ -455,14 +455,14 @@ NODE_DEPRECATED("Use DecodeWrite(isolate, ...)",
NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(
v8::Isolate* isolate,
int errorno,
const char *syscall = nullptr,
const char *msg = "",
const char *path = nullptr);
const char* syscall = nullptr,
const char* msg = "",
const char* path = nullptr);
NODE_DEPRECATED("Use WinapiErrnoException(isolate, ...)",
inline v8::Local<v8::Value> WinapiErrnoException(int errorno,
const char *syscall = nullptr, const char *msg = "",
const char *path = nullptr) {
const char* syscall = nullptr, const char* msg = "",
const char* path = nullptr) {
return WinapiErrnoException(v8::Isolate::GetCurrent(),
errorno,
syscall,
@ -471,7 +471,7 @@ NODE_DEPRECATED("Use WinapiErrnoException(isolate, ...)",
})
#endif
const char *signo_string(int errorno);
const char* signo_string(int errorno);
typedef void (*addon_register_func)(

View File

@ -10,16 +10,16 @@
// JSVM API types are all opaque pointers for ABI stability
// typedef undefined structs instead of void* for compile time type safety
typedef struct napi_env__ *napi_env;
typedef struct napi_value__ *napi_value;
typedef struct napi_ref__ *napi_ref;
typedef struct napi_handle_scope__ *napi_handle_scope;
typedef struct napi_escapable_handle_scope__ *napi_escapable_handle_scope;
typedef struct napi_callback_scope__ *napi_callback_scope;
typedef struct napi_callback_info__ *napi_callback_info;
typedef struct napi_async_context__ *napi_async_context;
typedef struct napi_async_work__ *napi_async_work;
typedef struct napi_deferred__ *napi_deferred;
typedef struct napi_env__* napi_env;
typedef struct napi_value__* napi_value;
typedef struct napi_ref__* napi_ref;
typedef struct napi_handle_scope__* napi_handle_scope;
typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
typedef struct napi_callback_scope__* napi_callback_scope;
typedef struct napi_callback_info__* napi_callback_info;
typedef struct napi_async_context__* napi_async_context;
typedef struct napi_async_work__* napi_async_work;
typedef struct napi_deferred__* napi_deferred;
typedef enum {
napi_default = 0,

View File

@ -3985,8 +3985,8 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
dh_.reset(DH_new());
BIGNUM *bn_p = BN_bin2bn(reinterpret_cast<const unsigned char*>(p), p_len, 0);
BIGNUM *bn_g = BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, 0);
BIGNUM* bn_p = BN_bin2bn(reinterpret_cast<const unsigned char*>(p), p_len, 0);
BIGNUM* bn_g = BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, 0);
if (!DH_set0_pqg(dh_.get(), bn_p, nullptr, bn_g)) {
BN_free(bn_p);
BN_free(bn_g);

View File

@ -368,12 +368,12 @@ class CipherBase : public BaseObject {
const char* iv,
int iv_len,
unsigned int auth_tag_len);
bool InitAuthenticated(const char *cipher_type, int iv_len,
bool InitAuthenticated(const char* cipher_type, int iv_len,
unsigned int auth_tag_len);
bool CheckCCMMessageLength(int message_len);
UpdateResult Update(const char* data, int len, unsigned char** out,
int* out_len);
bool Final(unsigned char** out, int *out_len);
bool Final(unsigned char** out, int* out_len);
bool SetAutoPadding(bool auto_padding);
bool IsAuthenticatedMode() const;
@ -492,7 +492,7 @@ class Sign : public SignBase {
int key_pem_len,
const char* passphrase,
unsigned char* sig,
unsigned int *sig_len,
unsigned int* sig_len,
int padding,
int saltlen);
@ -532,10 +532,10 @@ class Verify : public SignBase {
class PublicKeyCipher {
public:
typedef int (*EVP_PKEY_cipher_init_t)(EVP_PKEY_CTX *ctx);
typedef int (*EVP_PKEY_cipher_t)(EVP_PKEY_CTX *ctx,
unsigned char *out, size_t *outlen,
const unsigned char *in, size_t inlen);
typedef int (*EVP_PKEY_cipher_init_t)(EVP_PKEY_CTX* ctx);
typedef int (*EVP_PKEY_cipher_t)(EVP_PKEY_CTX* ctx,
unsigned char* out, size_t* outlen,
const unsigned char* in, size_t inlen);
enum Operation {
kPublic,

View File

@ -194,7 +194,7 @@ void DTRACE_HTTP_SERVER_RESPONSE(const FunctionCallbackInfo<Value>& args) {
void DTRACE_HTTP_CLIENT_REQUEST(const FunctionCallbackInfo<Value>& args) {
node_dtrace_http_client_request_t req;
char *header;
char* header;
if (!NODE_HTTP_CLIENT_REQUEST_ENABLED())
return;
@ -259,7 +259,7 @@ void InitDTrace(Environment* env, Local<Object> target) {
HandleScope scope(env->isolate());
static struct {
const char *name;
const char* name;
void (*func)(const FunctionCallbackInfo<Value>&);
} tab[] = {
#define NODE_PROBE(name) #name, name

View File

@ -96,7 +96,7 @@ inline void THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(Environment* env,
THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(env, message.str().c_str());
}
inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate *isolate) {
inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
char message[128];
snprintf(message, sizeof(message),
"Cannot create a Buffer larger than 0x%lx bytes",
@ -104,7 +104,7 @@ inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate *isolate) {
return ERR_BUFFER_TOO_LARGE(isolate, message);
}
inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate *isolate) {
inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
char message[128];
snprintf(message, sizeof(message),
"Cannot create a string longer than 0x%x characters",

View File

@ -659,7 +659,7 @@ inline int SyncCall(Environment* env, Local<Value> ctx, FSReqWrapSync* req_wrap,
if (err < 0) {
Local<Context> context = env->context();
Local<Object> ctx_obj = ctx.As<Object>();
Isolate *isolate = env->isolate();
Isolate* isolate = env->isolate();
ctx_obj->Set(context,
env->errno_string(),
Integer::New(isolate, err)).FromJust();

View File

@ -840,7 +840,7 @@ int Http2Session::OnFrameReceive(nghttp2_session* handle,
}
int Http2Session::OnInvalidFrame(nghttp2_session* handle,
const nghttp2_frame *frame,
const nghttp2_frame* frame,
int lib_error_code,
void* user_data) {
Http2Session* session = static_cast<Http2Session*>(user_data);

View File

@ -965,7 +965,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
void* user_data);
static int OnInvalidFrame(
nghttp2_session* session,
const nghttp2_frame *frame,
const nghttp2_frame* frame,
int lib_error_code,
void* user_data);

View File

@ -549,7 +549,7 @@ int ThreadPoolWork::CancelWork() {
return uv_cancel(reinterpret_cast<uv_req_t*>(&work_req_));
}
static inline const char *errno_string(int errorno) {
static inline const char* errno_string(int errorno) {
#define ERRNO_CASE(e) case e: return #e;
switch (errorno) {
#ifdef EACCES

View File

@ -27,7 +27,7 @@
#include <VersionHelpers.h>
#include <WinError.h>
int wmain(int argc, wchar_t *wargv[]) {
int wmain(int argc, wchar_t* wargv[]) {
if (!IsWindows7OrGreater()) {
fprintf(stderr, "This application is only supported on Windows 7, "
"Windows Server 2008 R2, or higher.");
@ -91,7 +91,7 @@ namespace node {
extern bool linux_at_secure;
} // namespace node
int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
#if defined(__POSIX__) && defined(NODE_SHARED_MODE)
// In node::PlatformInit(), we squash all signal handlers for non-shared lib
// build. In order to run test cases against shared lib build, we also need

View File

@ -16,7 +16,7 @@ using v8::Platform;
using v8::Task;
using v8::TracingController;
static void BackgroundRunner(void *data) {
static void BackgroundRunner(void* data) {
TRACE_EVENT_METADATA1("__metadata", "thread_name", "name",
"BackgroundTaskRunner");
TaskQueue<Task> *background_tasks = static_cast<TaskQueue<Task> *>(data);

View File

@ -120,8 +120,8 @@ extern int events_enabled;
void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req,
node_dtrace_connection_t* conn, const char *remote, int port,
const char *method, const char *url, int fd) {
node_dtrace_connection_t* conn, const char* remote, int port,
const char* method, const char* url, int fd) {
EVENT_DATA_DESCRIPTOR descriptors[7];
ETW_WRITE_HTTP_SERVER_REQUEST(descriptors, req);
ETW_WRITE_NET_CONNECTION(descriptors + 3, conn);
@ -130,7 +130,7 @@ void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req,
void NODE_HTTP_SERVER_RESPONSE(node_dtrace_connection_t* conn,
const char *remote, int port, int fd) {
const char* remote, int port, int fd) {
EVENT_DATA_DESCRIPTOR descriptors[4];
ETW_WRITE_NET_CONNECTION(descriptors, conn);
ETW_WRITE_EVENT(NODE_HTTP_SERVER_RESPONSE_EVENT, descriptors);
@ -138,8 +138,8 @@ void NODE_HTTP_SERVER_RESPONSE(node_dtrace_connection_t* conn,
void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req,
node_dtrace_connection_t* conn, const char *remote, int port,
const char *method, const char *url, int fd) {
node_dtrace_connection_t* conn, const char* remote, int port,
const char* method, const char* url, int fd) {
EVENT_DATA_DESCRIPTOR descriptors[6];
ETW_WRITE_HTTP_CLIENT_REQUEST(descriptors, req);
ETW_WRITE_NET_CONNECTION(descriptors + 2, conn);
@ -148,7 +148,7 @@ void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req,
void NODE_HTTP_CLIENT_RESPONSE(node_dtrace_connection_t* conn,
const char *remote, int port, int fd) {
const char* remote, int port, int fd) {
EVENT_DATA_DESCRIPTOR descriptors[4];
ETW_WRITE_NET_CONNECTION(descriptors, conn);
ETW_WRITE_EVENT(NODE_HTTP_CLIENT_RESPONSE_EVENT, descriptors);
@ -156,7 +156,7 @@ void NODE_HTTP_CLIENT_RESPONSE(node_dtrace_connection_t* conn,
void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn,
const char *remote, int port, int fd) {
const char* remote, int port, int fd) {
EVENT_DATA_DESCRIPTOR descriptors[4];
ETW_WRITE_NET_CONNECTION(descriptors, conn);
ETW_WRITE_EVENT(NODE_NET_SERVER_CONNECTION_EVENT, descriptors);
@ -164,7 +164,7 @@ void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn,
void NODE_NET_STREAM_END(node_dtrace_connection_t* conn,
const char *remote, int port, int fd) {
const char* remote, int port, int fd) {
EVENT_DATA_DESCRIPTOR descriptors[4];
ETW_WRITE_NET_CONNECTION(descriptors, conn);
ETW_WRITE_EVENT(NODE_NET_STREAM_END_EVENT, descriptors);

View File

@ -35,18 +35,18 @@ namespace node {
# define INLINE inline
#endif
typedef ULONG (NTAPI *EventRegisterFunc)(
typedef ULONG (NTAPI* EventRegisterFunc)(
LPCGUID ProviderId,
PENABLECALLBACK EnableCallback,
PVOID CallbackContext,
PREGHANDLE RegHandle
);
typedef ULONG (NTAPI *EventUnregisterFunc)(
typedef ULONG (NTAPI* EventUnregisterFunc)(
REGHANDLE RegHandle
);
typedef ULONG (NTAPI *EventWriteFunc)(
typedef ULONG (NTAPI* EventWriteFunc)(
REGHANDLE RegHandle,
PCEVENT_DESCRIPTOR EventDescriptor,
ULONG UserDataCount,
@ -57,19 +57,19 @@ void init_etw();
void shutdown_etw();
INLINE void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req,
node_dtrace_connection_t* conn, const char *remote, int port,
const char *method, const char *url, int fd);
node_dtrace_connection_t* conn, const char* remote, int port,
const char* method, const char* url, int fd);
INLINE void NODE_HTTP_SERVER_RESPONSE(node_dtrace_connection_t* conn,
const char *remote, int port, int fd);
const char* remote, int port, int fd);
INLINE void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req,
node_dtrace_connection_t* conn, const char *remote, int port,
const char *method, const char *url, int fd);
node_dtrace_connection_t* conn, const char* remote, int port,
const char* method, const char* url, int fd);
INLINE void NODE_HTTP_CLIENT_RESPONSE(node_dtrace_connection_t* conn,
const char *remote, int port, int fd);
const char* remote, int port, int fd);
INLINE void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn,
const char *remote, int port, int fd);
const char* remote, int port, int fd);
INLINE void NODE_NET_STREAM_END(node_dtrace_connection_t* conn,
const char *remote, int port, int fd);
const char* remote, int port, int fd);
INLINE void NODE_GC_START(v8::GCType type,
v8::GCCallbackFlags flags,
v8::Isolate* isolate);

View File

@ -28,60 +28,60 @@
#include "node_perfctr_provider.h"
typedef ULONG (WINAPI *PerfStartProviderExFunc)(
typedef ULONG (WINAPI* PerfStartProviderExFunc)(
__in LPGUID ProviderGuid,
__in_opt PPERF_PROVIDER_CONTEXT ProviderContext,
__out PHANDLE Provider);
typedef ULONG (WINAPI *PerfStopProviderFunc)(
typedef ULONG (WINAPI* PerfStopProviderFunc)(
__in HANDLE ProviderHandle);
typedef ULONG (WINAPI *PerfSetCounterSetInfoFunc)(
typedef ULONG (WINAPI* PerfSetCounterSetInfoFunc)(
__in HANDLE ProviderHandle,
__inout_bcount(TemplateSize) PPERF_COUNTERSET_INFO Template,
__in ULONG TemplateSize);
typedef PPERF_COUNTERSET_INSTANCE (WINAPI *PerfCreateInstanceFunc)(
typedef PPERF_COUNTERSET_INSTANCE (WINAPI* PerfCreateInstanceFunc)(
__in HANDLE ProviderHandle,
__in LPCGUID CounterSetGuid,
__in PCWSTR Name,
__in ULONG Id);
typedef ULONG (WINAPI *PerfDeleteInstanceFunc)(
typedef ULONG (WINAPI* PerfDeleteInstanceFunc)(
__in HANDLE Provider,
__in PPERF_COUNTERSET_INSTANCE InstanceBlock);
typedef ULONG (WINAPI *PerfSetULongCounterValueFunc)(
typedef ULONG (WINAPI* PerfSetULongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONG Value);
typedef ULONG (WINAPI *PerfSetULongLongCounterValueFunc)(
typedef ULONG (WINAPI* PerfSetULongLongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONGLONG Value);
typedef ULONG (WINAPI *PerfIncrementULongCounterValueFunc)(
typedef ULONG (WINAPI* PerfIncrementULongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONG Value);
typedef ULONG (WINAPI *PerfIncrementULongLongCounterValueFunc)(
typedef ULONG (WINAPI* PerfIncrementULongLongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONGLONG Value);
typedef ULONG (WINAPI *PerfDecrementULongCounterValueFunc)(
typedef ULONG (WINAPI* PerfDecrementULongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONG Value);
typedef ULONG (WINAPI *PerfDecrementULongLongCounterValueFunc)(
typedef ULONG (WINAPI* PerfDecrementULongLongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,

View File

@ -164,8 +164,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
CHECK(0 && "Invalid flush value");
}
Bytef *in;
Bytef *out;
Bytef* in;
Bytef* out;
size_t in_off, in_len, out_off, out_len;
Environment* env = ctx->env();
@ -500,7 +500,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
SetDictionary(ctx);
}
static bool Init(ZCtx *ctx, int level, int windowBits, int memLevel,
static bool Init(ZCtx* ctx, int level, int windowBits, int memLevel,
int strategy, uint32_t* write_result,
Local<Function> write_js_callback, char* dictionary,
size_t dictionary_len) {

View File

@ -341,8 +341,8 @@ Local<Object> AddressToJS(Environment* env,
Local<Object> info) {
EscapableHandleScope scope(env->isolate());
char ip[INET6_ADDRSTRLEN];
const sockaddr_in *a4;
const sockaddr_in6 *a6;
const sockaddr_in* a4;
const sockaddr_in6* a6;
int port;
if (info.IsEmpty())

27
tools/cpplint.py vendored
View File

@ -527,6 +527,10 @@ _SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
r'(?<!(sizeof|return))'
r'\s\*[a-zA-z_][0-9a-zA-z_]*')
_regexp_compile_cache = {}
# {str, set(int)}: a map from error categories to sets of linenumbers
@ -4179,6 +4183,28 @@ def CheckNullTokens(filename, clean_lines, linenum, error):
error(filename, linenum, 'readability/null_usage', 2,
'Use nullptr instead of NULL')
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
"""Check for left-leaning pointer placement.
Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.
"""
line = clean_lines.elided[linenum]
# Avoid preprocessor lines
if Match(r'^\s*#', line):
return
if '/*' in line or '*/' in line:
return
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
error(filename, linenum, 'readability/null_usage', 2,
'Use left leaning pointer instead of right leaning')
def GetLineWidth(line):
"""Determines the width of the line in column positions.
@ -4321,6 +4347,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
CheckCheck(filename, clean_lines, linenum, error)
CheckAltTokens(filename, clean_lines, linenum, error)
CheckNullTokens(filename, clean_lines, linenum, error)
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
classinfo = nesting_state.InnermostClass()
if classinfo:
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)