Skip to content

Commit ad235ee

Browse files
authored
Merge pull request #5 from hydradatabase/copy-data
Copy data and null terminate
2 parents 1f52833 + 2f94560 commit ad235ee

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ OBJS = $(subst .cpp,.o, $(SRCS))
55

66
MODULE_big = stringtheory
77

8-
PG_CPPFLAGS = -O3 -std=c++17 -I src/sse
8+
PG_CXXFLAGS = -O3 -std=c++17 -I src/sse
99

1010
UNAME_S := $(shell uname -m)
1111
ifeq ($(UNAME_S),arm64)
12-
PG_CPPFLAGS += -stdlib=libc++ -DHAVE_NEON_INSTRUCTIONS=1
12+
PG_CXXFLAGS += -stdlib=libc++ -DHAVE_NEON_INSTRUCTIONS=1
1313
endif
1414
ifeq ($(UNAME_S),aarch64)
1515
PG_CPPFLAGS += -DHAVE_NEON_INSTRUCTIONS=1
1616
endif
1717
ifeq ($(UNAME_S),x86_64)
1818
SHLIB_LINK += -lrt -std=c++17 -msse4.2
19-
PG_CPPFLAGS += -msse4.2
19+
PG_CXXFLAGS += -msse4.2
2020
endif
2121

2222
EXTENSION = stringtheory
23-
DATA = stringtheory--1.0.0.sql
23+
DATA = stringtheory--1.0.1.sql
2424
PGFILEDESC = "stringtheory - tools for testing equality"
2525

2626
PG_CONFIG = pg_config

src/text.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,16 @@ Datum pg_strstr(PG_FUNCTION_ARGS) {
7474
PG_RETURN_INT32(-1);
7575
}
7676

77+
/* Make a copy of the data to null terminate. */
78+
char left_term[ len_left + 1 ];
79+
memcpy(left_term, VARDATA_ANY(left), len_left);
80+
left_term[ len_left ] = '\0';
81+
char right_term[ len_right + 1 ];
82+
memcpy(right_term, VARDATA_ANY(right), len_right);
83+
right_term[ len_right ] = '\0';
84+
7785
/* Get the results from the simd functions. */
78-
size_t ret =
79-
fast_strstr(VARDATA_ANY(left), len_left, VARDATA_ANY(right), len_right);
86+
size_t ret = fast_strstr(left_term, len_left, right_term, len_right);
8087

8188
PG_RETURN_INT32(ret);
8289
}
File renamed without changes.

stringtheory.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# compare extension
22
comment = 'tools for comparing strings'
3-
default_version = '1.0.0'
3+
default_version = '1.0.1'
44
module_pathname = '$libdir/stringtheory'
55
relocatable = true

0 commit comments

Comments
 (0)