Skip to content

Commit 39d6fac

Browse files
committed
use CMake's join function for string concatenation, copy catalog version string using strncopy instead of using pointer
1 parent 6cb66ab commit 39d6fac

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,8 @@ foreach(file ${_update_files})
285285
endforeach()
286286

287287
# Convert the list to a C array
288-
set(COMPATIBLE_VERSIONS_ARRAY "")
289-
foreach(version ${COMPATIBLE_VERSIONS_LIST})
290-
set(COMPATIBLE_VERSIONS_ARRAY "${COMPATIBLE_VERSIONS_ARRAY}\"${version}\", ")
291-
endforeach()
292-
string(REGEX REPLACE ", $|,$" "" COMPATIBLE_VERSIONS_ARRAY "${COMPATIBLE_VERSIONS_ARRAY}")
293-
set(COMPATIBLE_VERSIONS_ARRAY "{ ${COMPATIBLE_VERSIONS_ARRAY} }")
288+
string(JOIN "\",\"" COMPATIBLE_VERSIONS_ARRAY ${COMPATIBLE_VERSIONS_LIST})
289+
set(COMPATIBLE_VERSIONS_ARRAY "{ \"${COMPATIBLE_VERSIONS_ARRAY}\" }")
294290
list(LENGTH COMPATIBLE_VERSIONS_LIST COMPATIBLE_VERSIONS_COUNT)
295291

296292
add_custom_command(

src/hnsw/utils.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#include "usearch_storage.hpp"
2323
#include "version.h"
2424

25-
bool version_checked = false;
26-
bool versions_match = true;
27-
char *catalog_version = "unknown";
25+
bool version_checked = false;
26+
bool versions_match = false;
27+
char catalog_version[ NAMEDATALEN ] = "unknown";
2828

2929
static const char *COMPATIBLE_VERSIONS[ LDB_COMPATIBLE_VERSIONS_COUNT ] = LDB_COMPATIBLE_VERSIONS;
3030

@@ -189,12 +189,7 @@ void CheckExtensionVersions()
189189

190190
// Grab the result and check that it matches the version in the generated header
191191
version_text = DatumGetTextP(val);
192-
catalog_version = text_to_cstring(version_text);
193-
194-
if(strlen(catalog_version) == 0) {
195-
SPI_finish();
196-
return;
197-
}
192+
strncpy(catalog_version, text_to_cstring(version_text), NAMEDATALEN);
198193

199194
if(strcmp(catalog_version, LDB_BINARY_VERSION) == 0) {
200195
versions_match = true;

0 commit comments

Comments
 (0)