Changeset: 65a27b2b9306 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=65a27b2b9306
Added Files:
sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.sql
sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.err
sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.out
Modified Files:
monetdb5/modules/atoms/str.c
sql/test/BugTracker-2014/Tests/All
Branch: Oct2014
Log Message:
Fix for bug 3563: don't confuse needle and haystack.
diffs (247 lines):
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -1862,12 +1862,12 @@ STRUpper(str *res, str *arg1)
}
str
-STRstrSearch(int *res, str *arg1, str *arg2)
+STRstrSearch(int *res, str *haystack, str *needle)
{
/* 64bit: should return wrd */
char *p;
- const char *s = *arg1;
- const char *s2 = *arg2;
+ const char *s = *haystack;
+ const char *s2 = *needle;
if (strNil(s) || strNil(s2)) {
*res = int_nil;
@@ -2472,22 +2472,24 @@ STRsuffix(str *ret, str *s, int *l){
int start = (int) (strlen(*s)- *l);
return STRSubString(ret,s,&start,l);
}
+
str
-STRlocate(int *ret, str *s1, str *s2){
- int p;
- STRstrSearch(&p, s2, s1);
- *ret= p>=0? p+1:0;
+STRlocate2(int *ret, str *needle, str *haystack, int *start)
+{
+ int off = *start <= 0 ? 1 : *start;
+ char *s = UTF8_strtail(*haystack, off - 1);
+ int res;
+
+ STRstrSearch(&res, &s, needle);
+ *ret = res >= 0 ? res + off : 0;
return MAL_SUCCEED;
}
+
str
-STRlocate2(int *ret, str *s1, str *s2, int *start){
- int p;
- str dummy;
- STRTail(&dummy, s1, start);
- STRstrSearch(&p, s2, &dummy);
- if( dummy) GDKfree(dummy);
- *ret= p>=0? p+1:0;
- return MAL_SUCCEED;
+STRlocate(int *ret, str *needle, str *haystack)
+{
+ int p = 1;
+ return STRlocate2(ret, needle, haystack, &p);
}
str
diff --git a/sql/test/BugTracker-2014/Tests/All
b/sql/test/BugTracker-2014/Tests/All
--- a/sql/test/BugTracker-2014/Tests/All
+++ b/sql/test/BugTracker-2014/Tests/All
@@ -39,3 +39,4 @@ subselect-reverse.Bug-3552
orderby_on_constant.Bug-3554
div_by_zero_in_return.Bug-3555
round-sorted.Bug-3562
+locate-offset.Bug-3563
diff --git a/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.sql
b/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.sql
@@ -0,0 +1,10 @@
+select locate('@','joeuser@mydatabase@test', 1) as string_position;
+select locate('@','joeuser@mydatabase@test', 2) as string_position;
+select locate('@','joeuser@mydatabase@test', 3) as string_position;
+select locate('@','joeuser@mydatabase@test', 4) as string_position;
+select locate('@','joeuser@mydatabase@test', 8) as string_position;
+select locate('@','joeuser@mydatabase@test', 9) as string_position;
+select locate('@','joeuser@mydatabase@test', -1) as string_position;
+select locate('@','joeuser@mydatabase@test', -2) as string_position;
+select locate('@','joeuser@mydatabase@test', -3) as string_position;
+select locate('@','joeuser@mydatabase@test', -4) as string_position;
diff --git a/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.err
b/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.err
@@ -0,0 +1,37 @@
+stderr of test 'locate-offset.Bug-3563` in directory
'sql/test/BugTracker-2014` itself:
+
+
+# 16:52:45 >
+# 16:52:45 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=34206" "--set"
"mapi_usock=/var/tmp/mtest-5089/.s.monetdb.34206" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/ufs/sjoerd/Monet-candidate/var/MonetDB/mTests_sql_test_BugTracker-2014"
"--set" "mal_listing=0" "--set" "embedded_r=yes"
+# 16:52:45 >
+
+# builtin opt gdk_dbpath =
/ufs/sjoerd/Monet-candidate/var/monetdb5/dbfarm/demo
+# builtin opt gdk_debug = 0
+# builtin opt gdk_vmtrim = no
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 34206
+# cmdline opt mapi_usock = /var/tmp/mtest-5089/.s.monetdb.34206
+# cmdline opt monet_prompt =
+# cmdline opt mal_listing = 2
+# cmdline opt gdk_dbpath =
/ufs/sjoerd/Monet-candidate/var/MonetDB/mTests_sql_test_BugTracker-2014
+# cmdline opt mal_listing = 0
+# cmdline opt embedded_r = yes
+# cmdline opt gdk_debug = 536870922
+
+# 16:52:46 >
+# 16:52:46 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-5089" "--port=34206"
+# 16:52:46 >
+
+
+# 16:52:46 >
+# 16:52:46 > "Done."
+# 16:52:46 >
+
diff --git a/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.out
b/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2014/Tests/locate-offset.Bug-3563.stable.out
@@ -0,0 +1,121 @@
+stdout of test 'locate-offset.Bug-3563` in directory
'sql/test/BugTracker-2014` itself:
+
+
+# 16:52:45 >
+# 16:52:45 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=34206" "--set"
"mapi_usock=/var/tmp/mtest-5089/.s.monetdb.34206" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/ufs/sjoerd/Monet-candidate/var/MonetDB/mTests_sql_test_BugTracker-2014"
"--set" "mal_listing=0" "--set" "embedded_r=yes"
+# 16:52:45 >
+
+# MonetDB 5 server v11.19.0 (hg id: 580357e42f8c+)
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2014', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically
linked
+# Found 15.590 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2014 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://madrid.ins.cwi.nl:34206/
+# Listening for UNIX domain connection requests on
mapi:monetdb:///var/tmp/mtest-5089/.s.monetdb.34206
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+# MonetDB/R module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_querylog.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 19_cluster.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 24_zorder.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 26_sysmon.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 40_geom.sql
+# loading sql script: 40_json.sql
+# loading sql script: 41_jsonstore.sql
+# loading sql script: 45_uuid.sql
+# loading sql script: 46_gsl.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_statistics.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 85_bam.sql
+# loading sql script: 90_generator.sql
+# loading sql script: 99_system.sql
+
+# 16:52:46 >
+# 16:52:46 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-5089" "--port=34206"
+# 16:52:46 >
+
+#select locate('@','joeuser@mydatabase@test', 1) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', 2) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', 3) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', 4) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', 8) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', 9) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 2 # length
+[ 19 ]
+#select locate('@','joeuser@mydatabase@test', -1) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', -2) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', -3) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+#select locate('@','joeuser@mydatabase@test', -4) as string_position;
+% .L # table_name
+% string_position # name
+% int # type
+% 1 # length
+[ 8 ]
+
+# 16:52:46 >
+# 16:52:46 > "Done."
+# 16:52:46 >
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list