Skip to content

Commit

Permalink
src, tools: add check for left leaning pointers
Browse files Browse the repository at this point in the history
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: #21010
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
danbev authored and targos committed Jun 7, 2018
1 parent c7add3d commit 20ca31a
Show file tree
Hide file tree
Showing 23 changed files with 114 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}

Expand Down
2 changes: 1 addition & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ 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
// false.
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
Expand Down Expand Up @@ -356,7 +356,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;
Expand All @@ -378,7 +378,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
Expand Down Expand Up @@ -423,7 +423,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
Expand Down Expand Up @@ -2456,7 +2456,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;
Expand Down
14 changes: 7 additions & 7 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)(
Expand Down
20 changes: 10 additions & 10 deletions src/node_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3988,8 +3988,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);
Expand Down
14 changes: 7 additions & 7 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/node_dtrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ namespace node {

// Errors with predefined non-static messages

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",
v8::TypedArray::kMaxLength);
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",
Expand Down
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/node_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions src/node_win32_etw_provider-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -130,16 +130,16 @@ 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);
}


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);
Expand All @@ -148,23 +148,23 @@ 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);
}


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);
}


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);
Expand Down
Loading

0 comments on commit 20ca31a

Please sign in to comment.