Skip to content

Commit

Permalink
make a copy of the data to query and null terminate it
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySievert committed Feb 5, 2024
1 parent 514d978 commit 248c5d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,16 @@ Datum pg_strstr(PG_FUNCTION_ARGS) {
PG_RETURN_INT32(-1);
}

/* Make a copy of the data to null terminate. */
char left_term[ len_left + 1 ];
memcpy(left_term, VARDATA_ANY(left), len_left);
left_term[ len_left ] = '\0';
char right_term[ len_right + 1 ];
memcpy(right_term, VARDATA_ANY(right), len_right);
right_term[ len_right ] = '\0';

/* Get the results from the simd functions. */
size_t ret =
fast_strstr(VARDATA_ANY(left), len_left, VARDATA_ANY(right), len_right);
size_t ret = fast_strstr(left_term, len_left, right_term, len_right);

PG_RETURN_INT32(ret);
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion stringtheory.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# compare extension
comment = 'tools for comparing strings'
default_version = '1.0.0'
default_version = '1.0.1'
module_pathname = '$libdir/stringtheory'
relocatable = true

0 comments on commit 248c5d6

Please sign in to comment.