Skip to content

Commit cbc3dd9

Browse files
committed
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: nodejs#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>
1 parent 75e9165 commit cbc3dd9

23 files changed

+114
-87
lines changed

src/cares_wrap.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ class QueryWrap : public AsyncWrap {
633633
wrap->env()->CloseHandle(handle, CaresAsyncClose);
634634
}
635635

636-
static void Callback(void *arg, int status, int timeouts,
636+
static void Callback(void* arg, int status, int timeouts,
637637
unsigned char* answer_buf, int answer_len) {
638638
QueryWrap* wrap = static_cast<QueryWrap*>(arg);
639639

@@ -661,7 +661,7 @@ class QueryWrap : public AsyncWrap {
661661
uv_async_send(async_handle);
662662
}
663663

664-
static void Callback(void *arg, int status, int timeouts,
664+
static void Callback(void* arg, int status, int timeouts,
665665
struct hostent* host) {
666666
QueryWrap* wrap = static_cast<QueryWrap*>(arg);
667667

src/env-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ inline uv_idle_t* Environment::immediate_idle_handle() {
349349

350350
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
351351
HandleCleanupCb cb,
352-
void *arg) {
352+
void* arg) {
353353
handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg});
354354
}
355355

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ class Environment {
615615
// Register clean-up cb to be called on environment destruction.
616616
inline void RegisterHandleCleanup(uv_handle_t* handle,
617617
HandleCleanupCb cb,
618-
void *arg);
618+
void* arg);
619619

620620
template <typename T, typename OnCloseCallback>
621621
inline void CloseHandle(T* handle, OnCloseCallback callback);

src/exceptions.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ using v8::Value;
2222

2323
Local<Value> ErrnoException(Isolate* isolate,
2424
int errorno,
25-
const char *syscall,
26-
const char *msg,
27-
const char *path) {
25+
const char* syscall,
26+
const char* msg,
27+
const char* path) {
2828
Environment* env = Environment::GetCurrent(isolate);
2929

3030
Local<Value> e;
@@ -143,8 +143,8 @@ Local<Value> UVException(Isolate* isolate,
143143
#ifdef _WIN32
144144
// Does about the same as strerror(),
145145
// but supports all windows error messages
146-
static const char *winapi_strerror(const int errorno, bool* must_free) {
147-
char *errmsg = nullptr;
146+
static const char* winapi_strerror(const int errorno, bool* must_free) {
147+
char* errmsg = nullptr;
148148

149149
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
150150
FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, errorno,

src/node.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,15 @@ static struct {
320320
}
321321

322322
#if HAVE_INSPECTOR
323-
bool StartInspector(Environment *env, const char* script_path,
323+
bool StartInspector(Environment* env, const char* script_path,
324324
const DebugOptions& options) {
325325
// Inspector agent can't fail to start, but if it was configured to listen
326326
// right away on the websocket port and fails to bind/etc, this will return
327327
// false.
328328
return env->inspector_agent()->Start(platform_, script_path, options);
329329
}
330330

331-
bool InspectorStarted(Environment *env) {
331+
bool InspectorStarted(Environment* env) {
332332
return env->inspector_agent()->IsStarted();
333333
}
334334
#endif // HAVE_INSPECTOR
@@ -357,7 +357,7 @@ static struct {
357357
void Dispose() {}
358358
void DrainVMTasks(Isolate* isolate) {}
359359
void CancelVMTasks(Isolate* isolate) {}
360-
bool StartInspector(Environment *env, const char* script_path,
360+
bool StartInspector(Environment* env, const char* script_path,
361361
const DebugOptions& options) {
362362
env->ThrowError("Node compiled with NODE_USE_V8_PLATFORM=0");
363363
return true;
@@ -379,7 +379,7 @@ static struct {
379379
#endif // !NODE_USE_V8_PLATFORM
380380

381381
#if !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR
382-
bool InspectorStarted(Environment *env) {
382+
bool InspectorStarted(Environment* env) {
383383
return false;
384384
}
385385
#endif // !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR
@@ -424,7 +424,7 @@ static void PrintErrorString(const char* format, ...) {
424424
va_end(ap);
425425
}
426426

427-
const char *signo_string(int signo) {
427+
const char* signo_string(int signo) {
428428
#define SIGNO_CASE(e) case e: return #e;
429429
switch (signo) {
430430
#ifdef SIGHUP
@@ -2442,7 +2442,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
24422442
Local<Array> envarr = Array::New(isolate);
24432443
WCHAR* p = environment;
24442444
while (*p) {
2445-
WCHAR *s;
2445+
WCHAR* s;
24462446
if (*p == L'=') {
24472447
// If the key starts with '=' it is a hidden environment variable.
24482448
p += wcslen(p) + 1;

src/node.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ NODE_EXTERN extern bool force_fips_crypto;
208208
# endif
209209
#endif
210210

211-
NODE_EXTERN int Start(int argc, char *argv[]);
211+
NODE_EXTERN int Start(int argc, char* argv[]);
212212
NODE_EXTERN void Init(int* argc,
213213
const char** argv,
214214
int* exec_argc,
@@ -455,14 +455,14 @@ NODE_DEPRECATED("Use DecodeWrite(isolate, ...)",
455455
NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(
456456
v8::Isolate* isolate,
457457
int errorno,
458-
const char *syscall = nullptr,
459-
const char *msg = "",
460-
const char *path = nullptr);
458+
const char* syscall = nullptr,
459+
const char* msg = "",
460+
const char* path = nullptr);
461461

462462
NODE_DEPRECATED("Use WinapiErrnoException(isolate, ...)",
463463
inline v8::Local<v8::Value> WinapiErrnoException(int errorno,
464-
const char *syscall = nullptr, const char *msg = "",
465-
const char *path = nullptr) {
464+
const char* syscall = nullptr, const char* msg = "",
465+
const char* path = nullptr) {
466466
return WinapiErrnoException(v8::Isolate::GetCurrent(),
467467
errorno,
468468
syscall,
@@ -471,7 +471,7 @@ NODE_DEPRECATED("Use WinapiErrnoException(isolate, ...)",
471471
})
472472
#endif
473473

474-
const char *signo_string(int errorno);
474+
const char* signo_string(int errorno);
475475

476476

477477
typedef void (*addon_register_func)(

src/node_api_types.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
// JSVM API types are all opaque pointers for ABI stability
1212
// typedef undefined structs instead of void* for compile time type safety
13-
typedef struct napi_env__ *napi_env;
14-
typedef struct napi_value__ *napi_value;
15-
typedef struct napi_ref__ *napi_ref;
16-
typedef struct napi_handle_scope__ *napi_handle_scope;
17-
typedef struct napi_escapable_handle_scope__ *napi_escapable_handle_scope;
18-
typedef struct napi_callback_scope__ *napi_callback_scope;
19-
typedef struct napi_callback_info__ *napi_callback_info;
20-
typedef struct napi_async_context__ *napi_async_context;
21-
typedef struct napi_async_work__ *napi_async_work;
22-
typedef struct napi_deferred__ *napi_deferred;
13+
typedef struct napi_env__* napi_env;
14+
typedef struct napi_value__* napi_value;
15+
typedef struct napi_ref__* napi_ref;
16+
typedef struct napi_handle_scope__* napi_handle_scope;
17+
typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
18+
typedef struct napi_callback_scope__* napi_callback_scope;
19+
typedef struct napi_callback_info__* napi_callback_info;
20+
typedef struct napi_async_context__* napi_async_context;
21+
typedef struct napi_async_work__* napi_async_work;
22+
typedef struct napi_deferred__* napi_deferred;
2323

2424
typedef enum {
2525
napi_default = 0,

src/node_crypto.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3985,8 +3985,8 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
39853985

39863986
bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
39873987
dh_.reset(DH_new());
3988-
BIGNUM *bn_p = BN_bin2bn(reinterpret_cast<const unsigned char*>(p), p_len, 0);
3989-
BIGNUM *bn_g = BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, 0);
3988+
BIGNUM* bn_p = BN_bin2bn(reinterpret_cast<const unsigned char*>(p), p_len, 0);
3989+
BIGNUM* bn_g = BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, 0);
39903990
if (!DH_set0_pqg(dh_.get(), bn_p, nullptr, bn_g)) {
39913991
BN_free(bn_p);
39923992
BN_free(bn_g);

src/node_crypto.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@ class CipherBase : public BaseObject {
368368
const char* iv,
369369
int iv_len,
370370
unsigned int auth_tag_len);
371-
bool InitAuthenticated(const char *cipher_type, int iv_len,
371+
bool InitAuthenticated(const char* cipher_type, int iv_len,
372372
unsigned int auth_tag_len);
373373
bool CheckCCMMessageLength(int message_len);
374374
UpdateResult Update(const char* data, int len, unsigned char** out,
375375
int* out_len);
376-
bool Final(unsigned char** out, int *out_len);
376+
bool Final(unsigned char** out, int* out_len);
377377
bool SetAutoPadding(bool auto_padding);
378378

379379
bool IsAuthenticatedMode() const;
@@ -492,7 +492,7 @@ class Sign : public SignBase {
492492
int key_pem_len,
493493
const char* passphrase,
494494
unsigned char* sig,
495-
unsigned int *sig_len,
495+
unsigned int* sig_len,
496496
int padding,
497497
int saltlen);
498498

@@ -532,10 +532,10 @@ class Verify : public SignBase {
532532

533533
class PublicKeyCipher {
534534
public:
535-
typedef int (*EVP_PKEY_cipher_init_t)(EVP_PKEY_CTX *ctx);
536-
typedef int (*EVP_PKEY_cipher_t)(EVP_PKEY_CTX *ctx,
537-
unsigned char *out, size_t *outlen,
538-
const unsigned char *in, size_t inlen);
535+
typedef int (*EVP_PKEY_cipher_init_t)(EVP_PKEY_CTX* ctx);
536+
typedef int (*EVP_PKEY_cipher_t)(EVP_PKEY_CTX* ctx,
537+
unsigned char* out, size_t* outlen,
538+
const unsigned char* in, size_t inlen);
539539

540540
enum Operation {
541541
kPublic,

src/node_dtrace.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void DTRACE_HTTP_SERVER_RESPONSE(const FunctionCallbackInfo<Value>& args) {
194194

195195
void DTRACE_HTTP_CLIENT_REQUEST(const FunctionCallbackInfo<Value>& args) {
196196
node_dtrace_http_client_request_t req;
197-
char *header;
197+
char* header;
198198

199199
if (!NODE_HTTP_CLIENT_REQUEST_ENABLED())
200200
return;
@@ -259,7 +259,7 @@ void InitDTrace(Environment* env, Local<Object> target) {
259259
HandleScope scope(env->isolate());
260260

261261
static struct {
262-
const char *name;
262+
const char* name;
263263
void (*func)(const FunctionCallbackInfo<Value>&);
264264
} tab[] = {
265265
#define NODE_PROBE(name) #name, name

src/node_errors.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ inline void THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(Environment* env,
9696
THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(env, message.str().c_str());
9797
}
9898

99-
inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate *isolate) {
99+
inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
100100
char message[128];
101101
snprintf(message, sizeof(message),
102102
"Cannot create a Buffer larger than 0x%lx bytes",
103103
v8::TypedArray::kMaxLength);
104104
return ERR_BUFFER_TOO_LARGE(isolate, message);
105105
}
106106

107-
inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate *isolate) {
107+
inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
108108
char message[128];
109109
snprintf(message, sizeof(message),
110110
"Cannot create a string longer than 0x%x characters",

src/node_file.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ inline int SyncCall(Environment* env, Local<Value> ctx, FSReqWrapSync* req_wrap,
659659
if (err < 0) {
660660
Local<Context> context = env->context();
661661
Local<Object> ctx_obj = ctx.As<Object>();
662-
Isolate *isolate = env->isolate();
662+
Isolate* isolate = env->isolate();
663663
ctx_obj->Set(context,
664664
env->errno_string(),
665665
Integer::New(isolate, err)).FromJust();

src/node_http2.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ int Http2Session::OnFrameReceive(nghttp2_session* handle,
840840
}
841841

842842
int Http2Session::OnInvalidFrame(nghttp2_session* handle,
843-
const nghttp2_frame *frame,
843+
const nghttp2_frame* frame,
844844
int lib_error_code,
845845
void* user_data) {
846846
Http2Session* session = static_cast<Http2Session*>(user_data);

src/node_http2.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
965965
void* user_data);
966966
static int OnInvalidFrame(
967967
nghttp2_session* session,
968-
const nghttp2_frame *frame,
968+
const nghttp2_frame* frame,
969969
int lib_error_code,
970970
void* user_data);
971971

src/node_internals.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ int ThreadPoolWork::CancelWork() {
549549
return uv_cancel(reinterpret_cast<uv_req_t*>(&work_req_));
550550
}
551551

552-
static inline const char *errno_string(int errorno) {
552+
static inline const char* errno_string(int errorno) {
553553
#define ERRNO_CASE(e) case e: return #e;
554554
switch (errorno) {
555555
#ifdef EACCES

src/node_main.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <VersionHelpers.h>
2828
#include <WinError.h>
2929

30-
int wmain(int argc, wchar_t *wargv[]) {
30+
int wmain(int argc, wchar_t* wargv[]) {
3131
if (!IsWindows7OrGreater()) {
3232
fprintf(stderr, "This application is only supported on Windows 7, "
3333
"Windows Server 2008 R2, or higher.");
@@ -91,7 +91,7 @@ namespace node {
9191
extern bool linux_at_secure;
9292
} // namespace node
9393

94-
int main(int argc, char *argv[]) {
94+
int main(int argc, char* argv[]) {
9595
#if defined(__POSIX__) && defined(NODE_SHARED_MODE)
9696
// In node::PlatformInit(), we squash all signal handlers for non-shared lib
9797
// build. In order to run test cases against shared lib build, we also need

src/node_platform.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using v8::Platform;
1616
using v8::Task;
1717
using v8::TracingController;
1818

19-
static void BackgroundRunner(void *data) {
19+
static void BackgroundRunner(void* data) {
2020
TRACE_EVENT_METADATA1("__metadata", "thread_name", "name",
2121
"BackgroundTaskRunner");
2222
TaskQueue<Task> *background_tasks = static_cast<TaskQueue<Task> *>(data);

src/node_win32_etw_provider-inl.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ extern int events_enabled;
120120

121121

122122
void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req,
123-
node_dtrace_connection_t* conn, const char *remote, int port,
124-
const char *method, const char *url, int fd) {
123+
node_dtrace_connection_t* conn, const char* remote, int port,
124+
const char* method, const char* url, int fd) {
125125
EVENT_DATA_DESCRIPTOR descriptors[7];
126126
ETW_WRITE_HTTP_SERVER_REQUEST(descriptors, req);
127127
ETW_WRITE_NET_CONNECTION(descriptors + 3, conn);
@@ -130,16 +130,16 @@ void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req,
130130

131131

132132
void NODE_HTTP_SERVER_RESPONSE(node_dtrace_connection_t* conn,
133-
const char *remote, int port, int fd) {
133+
const char* remote, int port, int fd) {
134134
EVENT_DATA_DESCRIPTOR descriptors[4];
135135
ETW_WRITE_NET_CONNECTION(descriptors, conn);
136136
ETW_WRITE_EVENT(NODE_HTTP_SERVER_RESPONSE_EVENT, descriptors);
137137
}
138138

139139

140140
void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req,
141-
node_dtrace_connection_t* conn, const char *remote, int port,
142-
const char *method, const char *url, int fd) {
141+
node_dtrace_connection_t* conn, const char* remote, int port,
142+
const char* method, const char* url, int fd) {
143143
EVENT_DATA_DESCRIPTOR descriptors[6];
144144
ETW_WRITE_HTTP_CLIENT_REQUEST(descriptors, req);
145145
ETW_WRITE_NET_CONNECTION(descriptors + 2, conn);
@@ -148,23 +148,23 @@ void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req,
148148

149149

150150
void NODE_HTTP_CLIENT_RESPONSE(node_dtrace_connection_t* conn,
151-
const char *remote, int port, int fd) {
151+
const char* remote, int port, int fd) {
152152
EVENT_DATA_DESCRIPTOR descriptors[4];
153153
ETW_WRITE_NET_CONNECTION(descriptors, conn);
154154
ETW_WRITE_EVENT(NODE_HTTP_CLIENT_RESPONSE_EVENT, descriptors);
155155
}
156156

157157

158158
void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn,
159-
const char *remote, int port, int fd) {
159+
const char* remote, int port, int fd) {
160160
EVENT_DATA_DESCRIPTOR descriptors[4];
161161
ETW_WRITE_NET_CONNECTION(descriptors, conn);
162162
ETW_WRITE_EVENT(NODE_NET_SERVER_CONNECTION_EVENT, descriptors);
163163
}
164164

165165

166166
void NODE_NET_STREAM_END(node_dtrace_connection_t* conn,
167-
const char *remote, int port, int fd) {
167+
const char* remote, int port, int fd) {
168168
EVENT_DATA_DESCRIPTOR descriptors[4];
169169
ETW_WRITE_NET_CONNECTION(descriptors, conn);
170170
ETW_WRITE_EVENT(NODE_NET_STREAM_END_EVENT, descriptors);

0 commit comments

Comments
 (0)