Skip to content

Commit 55ea3c5

Browse files
committed
apply code review feedback and always initialize pointers to NULL
1 parent d6eee1a commit 55ea3c5

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

agent/php_user_instrument_wraprec_hashmap.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct _nr_func_hashmap {
3333
} nr_func_hashmap_t;
3434

3535
static nr_func_hashmap_t* nr_func_hashmap_create_internal(size_t log2_num_buckets) {
36-
nr_func_hashmap_t* hashmap;
36+
nr_func_hashmap_t* hashmap = NULL;
3737

3838
if (0 == log2_num_buckets) {
3939
/*
@@ -68,8 +68,7 @@ static bool nr_func_hashmap_key_equals(nr_func_hashmap_key_t* a, nr_func_hashmap
6868
}
6969

7070
static bool nr_func_hashmap_fetch_internal(nr_func_hashmap_t* hashmap, size_t hash, nr_func_hashmap_key_t* key, nr_func_bucket_t** bucket_ptr) {
71-
nr_func_bucket_t* bucket;
72-
for (bucket = hashmap->buckets[hash]; bucket; bucket = bucket->next) {
71+
for (nr_func_bucket_t* bucket = hashmap->buckets[hash]; bucket; bucket = bucket->next) {
7372
if (nr_func_hashmap_key_equals(bucket->key, key)) {
7473
if (bucket_ptr) {
7574
*bucket_ptr = bucket;
@@ -83,9 +82,8 @@ static bool nr_func_hashmap_fetch_internal(nr_func_hashmap_t* hashmap, size_t ha
8382
static nruserfn_t* nr_func_hashmap_add_internal(nr_func_hashmap_t* hashmap,
8483
size_t hash_key,
8584
nr_func_hashmap_key_t* key) {
86-
nr_func_bucket_t* bucket;
85+
nr_func_bucket_t* bucket = (nr_func_bucket_t*)nr_malloc(sizeof(nr_func_bucket_t));
8786

88-
bucket = (nr_func_bucket_t*)nr_malloc(sizeof(nr_func_bucket_t));
8987
bucket->prev = NULL;
9088
bucket->next = hashmap->buckets[hash_key];
9189
bucket->key = (nr_func_hashmap_key_t*)nr_malloc(sizeof(nr_func_hashmap_key_t));
@@ -107,7 +105,7 @@ static nruserfn_t* nr_func_hashmap_add_internal(nr_func_hashmap_t* hashmap,
107105

108106
static nruserfn_t* nr_func_hashmap_lookup_internal(nr_func_hashmap_t* hashmap, nr_func_hashmap_key_t* key) {
109107
size_t hash;
110-
nr_func_bucket_t* bucket;
108+
nr_func_bucket_t* bucket = NULL;
111109

112110
if (nrunlikely((NULL == hashmap) || (NULL == key))) {
113111
return NULL;
@@ -123,8 +121,8 @@ static nruserfn_t* nr_func_hashmap_lookup_internal(nr_func_hashmap_t* hashmap, n
123121

124122
static nruserfn_t* nr_func_hashmap_update_internal(nr_func_hashmap_t* hashmap, nr_func_hashmap_key_t* key, bool* created) {
125123
size_t hash;
126-
nr_func_bucket_t* bucket;
127-
nruserfn_t* wraprec;
124+
nr_func_bucket_t* bucket = NULL;
125+
nruserfn_t* wraprec = NULL;
128126

129127
if (nrunlikely((NULL == hashmap) || (NULL == key))) {
130128
return NULL;
@@ -156,7 +154,7 @@ static void nr_func_hashmap_destroy_bucket_internal(nr_func_bucket_t** bucket_pt
156154

157155
static void nr_func_hashmap_destroy_internal(nr_func_hashmap_t** hashmap_ptr) {
158156
size_t count;
159-
nr_func_hashmap_t* hashmap;
157+
nr_func_hashmap_t* hashmap = NULL;
160158
size_t i;
161159

162160
if ((NULL == hashmap_ptr) || (NULL == *hashmap_ptr)) {
@@ -204,7 +202,7 @@ typedef struct _nr_scope_hashmap {
204202
} nr_scope_hashmap_t;
205203

206204
static nr_scope_hashmap_t* nr_scope_hashmap_create_internal(size_t log2_num_buckets) {
207-
nr_scope_hashmap_t* hashmap;
205+
nr_scope_hashmap_t* hashmap = NULL;
208206

209207
if (0 == log2_num_buckets) {
210208
/*
@@ -239,8 +237,8 @@ static bool nr_scope_hashmap_key_equals(nr_scope_hashmap_key_t* a, nr_scope_hash
239237
}
240238

241239
static bool nr_scope_hashmap_fetch_internal(nr_scope_hashmap_t* hashmap, size_t hash, nr_scope_hashmap_key_t* key, nr_scope_bucket_t** bucket_ptr) {
242-
nr_scope_bucket_t* bucket;
243-
for (bucket = hashmap->buckets[hash]; bucket; bucket = bucket->next) {
240+
241+
for (nr_scope_bucket_t* bucket = hashmap->buckets[hash]; bucket; bucket = bucket->next) {
244242
if (nr_scope_hashmap_key_equals(bucket->key, key)) {
245243
if (bucket_ptr) {
246244
*bucket_ptr = bucket;
@@ -254,9 +252,7 @@ static bool nr_scope_hashmap_fetch_internal(nr_scope_hashmap_t* hashmap, size_t
254252
static nr_func_hashmap_t* nr_scope_hashmap_add_internal(nr_scope_hashmap_t* hashmap,
255253
size_t hash_key,
256254
nr_scope_hashmap_key_t* key) {
257-
nr_scope_bucket_t* bucket;
258-
259-
bucket = (nr_scope_bucket_t*)nr_malloc(sizeof(nr_scope_bucket_t));
255+
nr_scope_bucket_t* bucket = (nr_scope_bucket_t*)nr_malloc(sizeof(nr_scope_bucket_t));
260256
bucket->prev = NULL;
261257
bucket->next = hashmap->buckets[hash_key];
262258
bucket->key = (nr_scope_hashmap_key_t*)nr_malloc(sizeof(nr_scope_hashmap_key_t));
@@ -277,7 +273,7 @@ static nr_func_hashmap_t* nr_scope_hashmap_add_internal(nr_scope_hashmap_t* hash
277273

278274
static nr_func_hashmap_t* nr_scope_hashmap_lookup_internal(nr_scope_hashmap_t* hashmap, nr_scope_hashmap_key_t* key) {
279275
size_t hash;
280-
nr_scope_bucket_t* bucket;
276+
nr_scope_bucket_t* bucket = NULL;
281277

282278
if (nrunlikely((NULL == hashmap) || (NULL == key))) {
283279
return NULL;
@@ -293,7 +289,7 @@ static nr_func_hashmap_t* nr_scope_hashmap_lookup_internal(nr_scope_hashmap_t* h
293289

294290
static nr_func_hashmap_t* nr_scope_hashmap_update_internal(nr_scope_hashmap_t* hashmap, nr_scope_hashmap_key_t* key) {
295291
size_t hash;
296-
nr_scope_bucket_t* bucket;
292+
nr_scope_bucket_t* bucket = NULL;
297293

298294
if (nrunlikely((NULL == hashmap) || (NULL == key))) {
299295
return NULL;
@@ -319,7 +315,7 @@ static void nr_scope_hashmap_destroy_bucket_internal(nr_scope_bucket_t** bucket_
319315

320316
static void nr_scope_hashmap_destroy_internal(nr_scope_hashmap_t** hashmap_ptr) {
321317
size_t count;
322-
nr_scope_hashmap_t* hashmap;
318+
nr_scope_hashmap_t* hashmap = NULL;
323319
size_t i;
324320

325321
if ((NULL == hashmap_ptr) || (NULL == *hashmap_ptr)) {

0 commit comments

Comments
 (0)