@@ -155,8 +155,8 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
155155 clear ();
156156 }
157157
158- char *& getLinkListPtrRef (tableint internal_id) {
159- return *reinterpret_cast <char **>(linkLists_[internal_id]);
158+ void setLinkListPtr (tableint internal_id, char * data ) {
159+ *reinterpret_cast <char **>(linkLists_[internal_id]) = data ;
160160 }
161161
162162 char * getLinkListPtr (tableint internal_id) const {
@@ -724,7 +724,7 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
724724 unsigned int linkListSize = element_levels_[i] > 0 ? size_links_per_element_ * element_levels_[i] : 0 ;
725725 writeBinaryPOD (output, linkListSize);
726726 if (linkListSize)
727- output.write (getLinkListPtrRef (i), linkListSize);
727+ output.write (getLinkListPtr (i), linkListSize);
728728 }
729729 output.close ();
730730 return OkStatus ();
@@ -826,13 +826,13 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
826826 readBinaryPOD (input, linkListSize);
827827 if (linkListSize == 0 ) {
828828 element_levels_[i] = 0 ;
829- getLinkListPtrRef (i) = nullptr ;
829+ setLinkListPtr (i, nullptr ) ;
830830 } else {
831831 element_levels_[i] = linkListSize / size_links_per_element_;
832- getLinkListPtrRef (i) = (char *) malloc (linkListSize);
833- if (getLinkListPtrRef (i) == nullptr )
832+ setLinkListPtr (i, (char *) malloc (linkListSize) );
833+ if (getLinkListPtr (i) == nullptr )
834834 return Status (" Not enough memory: loadIndex failed to allocate linklist" );
835- input.read (getLinkListPtrRef (i), linkListSize);
835+ input.read (getLinkListPtr (i), linkListSize);
836836 }
837837 }
838838
@@ -1241,11 +1241,12 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
12411241 memcpy (getDataByInternalId (cur_c), data_point, data_size_);
12421242
12431243 if (curlevel) {
1244- getLinkListPtrRef (cur_c) = (char *) malloc (size_links_per_element_ * curlevel + 1 );
1245- if (getLinkListPtrRef (cur_c) == nullptr ) {
1244+ size_t link_list_num_bytes = size_links_per_element_ * curlevel + 1 ;
1245+ setLinkListPtr (cur_c, (char *) malloc (link_list_num_bytes));
1246+ if (getLinkListPtr (cur_c) == nullptr ) {
12461247 return Status (" Not enough memory: addPoint failed to allocate linklist" );
12471248 }
1248- memset (getLinkListPtrRef (cur_c), 0 , size_links_per_element_ * curlevel + 1 );
1249+ memset (getLinkListPtr (cur_c), 0 , link_list_num_bytes );
12491250 }
12501251
12511252 if ((signed )currObj != -1 ) {
0 commit comments