Skip to content

Commit 1278516

Browse files
committed
Replaced c-style casts with static_cast<>
1 parent 234a4c0 commit 1278516

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

kdtree.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct kdtree *kd_create(int k)
108108
{
109109
struct kdtree *tree;
110110

111-
if(!(tree = (kdtree*)malloc(sizeof *tree))) {
111+
if(!(tree = static_cast<kdtree*>(malloc(sizeof *tree)))) {
112112
return 0;
113113
}
114114

@@ -165,10 +165,10 @@ static int insert_rec(struct kdnode **nptr, const double *pos, void *data, int d
165165
struct kdnode *node;
166166

167167
if(!*nptr) {
168-
if(!(node = (kdnode*)malloc(sizeof *node))) {
168+
if(!(node = static_cast<kdnode*>(malloc(sizeof *node)))) {
169169
return -1;
170170
}
171-
if(!(node->pos = (double*)malloc(dim * sizeof *node->pos))) {
171+
if(!(node->pos = static_cast<double*>(malloc(dim * sizeof *node->pos)))) {
172172
free(node);
173173
return -1;
174174
}
@@ -212,10 +212,10 @@ int kd_insertf(struct kdtree *tree, const float *pos, void *data)
212212
if(dim > 16) {
213213
#ifndef NO_ALLOCA
214214
if(dim <= 256)
215-
bptr = buf = (double*)alloca(dim * sizeof *bptr);
215+
bptr = buf = static_cast<double*>(alloca(dim * sizeof *bptr));
216216
else
217217
#endif
218-
if(!(bptr = buf = (double*)malloc(dim * sizeof *bptr))) {
218+
if(!(bptr = buf = static_cast<double*>(malloc(dim * sizeof *bptr)))) {
219219
return -1;
220220
}
221221
} else {
@@ -408,10 +408,10 @@ struct kdres *kd_nearest(struct kdtree *kd, const double *pos)
408408
if (!kd->rect) return 0;
409409

410410
/* Allocate result set */
411-
if(!(rset = (kdres*)malloc(sizeof *rset))) {
411+
if(!(rset = static_cast<kdres*>(malloc(sizeof *rset)))) {
412412
return 0;
413413
}
414-
if(!(rset->rlist = (res_node*)alloc_resnode())) {
414+
if(!(rset->rlist = static_cast<res_node*>(alloc_resnode()))) {
415415
free(rset);
416416
return 0;
417417
}
@@ -461,10 +461,10 @@ struct kdres *kd_nearestf(struct kdtree *tree, const float *pos)
461461
if(dim > 16) {
462462
#ifndef NO_ALLOCA
463463
if(dim <= 256)
464-
bptr = buf = (double*)alloca(dim * sizeof *bptr);
464+
bptr = buf = static_cast<double*>(alloca(dim * sizeof *bptr));
465465
else
466466
#endif
467-
if(!(bptr = buf = (double*)malloc(dim * sizeof *bptr))) {
467+
if(!(bptr = buf = static_cast<double*>(malloc(dim * sizeof *bptr)))) {
468468
return 0;
469469
}
470470
} else {
@@ -534,10 +534,10 @@ struct kdres *kd_nearest_range(struct kdtree *kd, const double *pos, double rang
534534
int ret;
535535
struct kdres *rset;
536536

537-
if(!(rset = (kdres*)malloc(sizeof *rset))) {
537+
if(!(rset = static_cast<kdres*>(malloc(sizeof *rset)))) {
538538
return 0;
539539
}
540-
if(!(rset->rlist = (res_node*)alloc_resnode())) {
540+
if(!(rset->rlist = static_cast<res_node*>(alloc_resnode()))) {
541541
free(rset);
542542
return 0;
543543
}
@@ -563,10 +563,10 @@ struct kdres *kd_nearest_rangef(struct kdtree *kd, const float *pos, float range
563563
if(dim > 16) {
564564
#ifndef NO_ALLOCA
565565
if(dim <= 256)
566-
bptr = buf = (double*)alloca(dim * sizeof *bptr);
566+
bptr = buf = static_cast<double*>(alloca(dim * sizeof *bptr));
567567
else
568568
#endif
569-
if(!(bptr = buf = (double*)malloc(dim * sizeof *bptr))) {
569+
if(!(bptr = buf = static_cast<double*>(malloc(dim * sizeof *bptr)))) {
570570
return 0;
571571
}
572572
} else {
@@ -689,16 +689,16 @@ static struct kdhyperrect* hyperrect_create(int dim, const double *min, const do
689689
size_t size = dim * sizeof(double);
690690
struct kdhyperrect* rect = 0;
691691

692-
if (!(rect = (kdhyperrect*)malloc(sizeof(struct kdhyperrect)))) {
692+
if (!(rect = static_cast<kdhyperrect*>(malloc(sizeof(struct kdhyperrect))))) {
693693
return 0;
694694
}
695695

696696
rect->dim = dim;
697-
if (!(rect->min = (double*)malloc(size))) {
697+
if (!(rect->min = static_cast<double*>(malloc(size)))) {
698698
free(rect);
699699
return 0;
700700
}
701-
if (!(rect->max = (double*)malloc(size))) {
701+
if (!(rect->max = static_cast<double*>(malloc(size)))) {
702702
free(rect->min);
703703
free(rect);
704704
return 0;
@@ -806,7 +806,7 @@ static int rlist_insert(struct res_node *list, struct kdnode *item, double dist_
806806
{
807807
struct res_node *rnode;
808808

809-
if(!(rnode = (res_node*)alloc_resnode())) {
809+
if(!(rnode = static_cast<res_node*>(alloc_resnode()))) {
810810
return -1;
811811
}
812812
rnode->item = item;

0 commit comments

Comments
 (0)