shogun-toolbox/shogun — pull request #2274 by mazumdarparijat (2014-06-01 18:19:45+00:00)
Title: coverity scan defects fixed

- coverity scan defects handled

```Defect(s) Reported-by: Coverity Scan
Showing 4 of 4 defect(s)

** CID 60490: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 483 in shogun::CC45ClassifierTree::apply_multiclass_from_current_node(shogun::CDenseFeatures *, shogun::CTreeMachineNode *)()

** CID 60491: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 499 in shogun::CC45ClassifierTree::apply_multiclass_from_current_node(shogun::CDenseFeatures *, shogun::CTreeMachineNode *)()

** CID 60492: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 459 in shogun::CC45ClassifierTree::apply_multiclass_from_current_node(shogun::CDenseFeatures *, shogun::CTreeMachineNode *)()

** CID 60493: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 138 in shogun::CC45ClassifierTree::C45train(shogun::CFeatures *, shogun::SGVector, shogun::CMulticlassLabels *, shogun::SGVector, int)()

________________________________________________________________________________________________________
*** CID 60490: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 483 in shogun::CC45ClassifierTree::apply_multiclass_from_current_node(shogun::CDenseFeatures *, shogun::CTreeMachineNode *)()
477 }
478 // if not nominal attribute check if greater or less than threshold
479 else
480 {
481 node_t* left_child=dynamic_cast(children->get_element(0));
482 node_t* right_child=dynamic_cast(children->get_element(1));
>>> CID 60490: Unchecked dynamic_cast (FORWARD_NULL)
>>> Dereferencing null pointer "left_child".
483 if (left_child->data.transit_if_feature_value>=sample[node->data.attribute_id])
484 {
485 SG_UNREF(node);
486 node=left_child;
487 SG_REF(left_child)
488

________________________________________________________________________________________________________
*** CID 60491: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 499 in shogun::CC45ClassifierTree::apply_multiclass_from_current_node(shogun::CDenseFeatures *, shogun::CTreeMachineNode *)()
493 {
494 SG_UNREF(node);
495 node=right_child;
496 SG_REF(right_child)
497
498 SG_UNREF(children);
>>> CID 60491: Unchecked dynamic_cast (FORWARD_NULL)
>>> Passing null pointer "node" to "get_children", which dereferences it. (The dereference happens because this is a virtual function call.)
499 children=node->get_children();
500 }
501
502 SG_UNREF(left_child);
503 SG_UNREF(right_child);
504 }

________________________________________________________________________________________________________
*** CID 60492: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 459 in shogun::CC45ClassifierTree::apply_multiclass_from_current_node(shogun::CDenseFeatures *, shogun::CTreeMachineNode *)()
453 // if nominal attribute check for equality
454 if (m_nominal[node->data.attribute_id])
455 {
456 for (int32_t j=0; jget_num_elements(); j++)
457 {
458 node_t* child=dynamic_cast(children->get_element(j));
>>> CID 60492: Unchecked dynamic_cast (FORWARD_NULL)
>>> Dereferencing null pointer "child".
459 if (child->data.transit_if_feature_value==sample[node->data.attribute_id])
460 {
461 flag=true;
462
463 SG_UNREF(node);
464 node=child;

________________________________________________________________________________________________________
*** CID 60493: Unchecked dynamic_cast (FORWARD_NULL)
/home/buildslave/coverity_analysis/build/src/shogun/multiclass/tree/C45ClassifierTree.cpp: 138 in shogun::CC45ClassifierTree::C45train(shogun::CFeatures *, shogun::SGVector, shogun::CMulticlassLabels *, shogun::SGVector, int)()
132
133 CTreeMachineNode* CC45ClassifierTree::C45train(CFeatures* data, SGVector weights,
134 CMulticlassLabels* class_labels, SGVector feature_id_vector, int32_t level)
135 {
136 node_t* node=new node_t();
137 CDenseFeatures* feats=dynamic_cast*>(data);
>>> CID 60493: Unchecked dynamic_cast (FORWARD_NULL)
>>> Passing null pointer "feats" to "get_num_vectors", which dereferences it. (The dereference happens because this is a virtual function call.)
138 int32_t num_vecs=feats->get_num_vectors();
139
140 // set class_label for the node as the mode of occurring multiclass labels
141 SGVector labels=class_labels->get_labels_copy();
142 labels.qsort();
143```