@@ -259,6 +259,7 @@ int InsertNetmask(TreeNode *node, TreeNode *parent, TreeNode *new_node,
259
259
260
260
node->count ++;
261
261
node->netmasks = reinterpret_cast <unsigned char *>(malloc (node->count * sizeof (unsigned char )));
262
+ memset (node->netmasks , 0 , (node->count * sizeof (unsigned char )));
262
263
263
264
if (node->netmasks == NULL )
264
265
return 0 ;
@@ -410,6 +411,7 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
410
411
node->count ++;
411
412
new_node = node;
412
413
node->netmasks = reinterpret_cast <unsigned char *>(malloc (node->count * sizeof (unsigned char )));
414
+ memset (node->netmasks , 0 , (node->count * sizeof (unsigned char )));
413
415
414
416
if ((node->count -1 ) == 0 ) {
415
417
node->netmasks [0 ] = netmask;
@@ -418,16 +420,16 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
418
420
419
421
node->netmasks [node->count - 1 ] = netmask;
420
422
421
- i = node->count - 2 ;
422
- while (i >= 0 ) {
423
- if (netmask < node->netmasks [i ]) {
424
- node->netmasks [i + 1 ] = netmask;
423
+ int index = node->count - 2 ;
424
+ while (index >= 0 ) {
425
+ if (netmask < node->netmasks [index ]) {
426
+ node->netmasks [index + 1 ] = netmask;
425
427
break ;
426
428
}
427
429
428
- node->netmasks [i + 1 ] = node->netmasks [i ];
429
- node->netmasks [i ] = netmask;
430
- i --;
430
+ node->netmasks [index + 1 ] = node->netmasks [index ];
431
+ node->netmasks [index ] = netmask;
432
+ index --;
431
433
}
432
434
}
433
435
} else {
@@ -481,6 +483,7 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
481
483
}
482
484
483
485
i_node->netmasks = reinterpret_cast <unsigned char *>(malloc ((node->count - i) * sizeof (unsigned char )));
486
+ memset (i_node->netmasks , 0 , ((node->count - i) * sizeof (unsigned char )));
484
487
485
488
if (i_node->netmasks == NULL ) {
486
489
free (new_node->prefix );
0 commit comments