Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
69cf7271
Commit
69cf7271
authored
Nov 23, 2005
by
jimw@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix possible corruption of results from SUBSTRING_INDEX(). (Bug #14676)
parent
63554e10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
16 deletions
+37
-16
mysql-test/r/func_str.result
mysql-test/r/func_str.result
+7
-0
mysql-test/t/func_str.test
mysql-test/t/func_str.test
+8
-0
sql/item_strfunc.cc
sql/item_strfunc.cc
+22
-16
No files found.
mysql-test/r/func_str.result
View file @
69cf7271
...
...
@@ -1023,3 +1023,10 @@ select format(d, 2) from t1;
format(d, 2)
NULL
drop table t1;
create table t1 (c varchar(40));
insert into t1 values ('y,abc'),('y,abc');
select c, substring_index(lcase(c), @q:=',', -1) as res from t1;
c res
y,abc abc
y,abc abc
drop table t1;
mysql-test/t/func_str.test
View file @
69cf7271
...
...
@@ -676,4 +676,12 @@ insert into t1 values (null);
select
format
(
d
,
2
)
from
t1
;
drop
table
t1
;
#
# Bug #14676: substring_index() returns incorrect results
#
create
table
t1
(
c
varchar
(
40
));
insert
into
t1
values
(
'y,abc'
),(
'y,abc'
);
select
c
,
substring_index
(
lcase
(
c
),
@
q
:=
','
,
-
1
)
as
res
from
t1
;
drop
table
t1
;
# End of 5.0 tests
sql/item_strfunc.cc
View file @
69cf7271
...
...
@@ -1094,9 +1094,9 @@ void Item_func_substr_index::fix_length_and_dec()
String
*
Item_func_substr_index
::
val_str
(
String
*
str
)
{
DBUG_ASSERT
(
fixed
==
1
);
String
*
res
=
args
[
0
]
->
val_str
(
str
);
String
*
delim
eter
=
args
[
1
]
->
val_str
(
&
tmp_value
);
int32
count
=
(
int32
)
args
[
2
]
->
val_int
();
String
*
res
=
args
[
0
]
->
val_str
(
str
);
String
*
delim
iter
=
args
[
1
]
->
val_str
(
&
tmp_value
);
int32
count
=
(
int32
)
args
[
2
]
->
val_int
();
uint
offset
;
if
(
args
[
0
]
->
null_value
||
args
[
1
]
->
null_value
||
args
[
2
]
->
null_value
)
...
...
@@ -1105,8 +1105,8 @@ String *Item_func_substr_index::val_str(String *str)
return
0
;
}
null_value
=
0
;
uint
delim
eter_length
=
delime
ter
->
length
();
if
(
!
res
->
length
()
||
!
delim
e
ter_length
||
!
count
)
uint
delim
iter_length
=
delimi
ter
->
length
();
if
(
!
res
->
length
()
||
!
delim
i
ter_length
||
!
count
)
return
&
my_empty_string
;
// Wrong parameters
res
->
set_charset
(
collation
.
collation
);
...
...
@@ -1114,11 +1114,11 @@ String *Item_func_substr_index::val_str(String *str)
#ifdef USE_MB
if
(
use_mb
(
res
->
charset
()))
{
const
char
*
ptr
=
res
->
ptr
();
const
char
*
strend
=
ptr
+
res
->
length
();
const
char
*
end
=
strend
-
delime
ter_length
+
1
;
const
char
*
search
=
delime
ter
->
ptr
();
const
char
*
search_end
=
search
+
delime
ter_length
;
const
char
*
ptr
=
res
->
ptr
();
const
char
*
strend
=
ptr
+
res
->
length
();
const
char
*
end
=
strend
-
delimi
ter_length
+
1
;
const
char
*
search
=
delimi
ter
->
ptr
();
const
char
*
search_end
=
search
+
delimi
ter_length
;
int32
n
=
0
,
c
=
count
,
pass
;
register
uint32
l
;
for
(
pass
=
(
count
>
0
);
pass
<
2
;
++
pass
)
...
...
@@ -1133,7 +1133,7 @@ String *Item_func_substr_index::val_str(String *str)
if
(
*
i
++
!=
*
j
++
)
goto
skip
;
if
(
pass
==
0
)
++
n
;
else
if
(
!--
c
)
break
;
ptr
+=
delime
ter_length
;
ptr
+=
delimi
ter_length
;
continue
;
}
skip:
...
...
@@ -1155,7 +1155,7 @@ String *Item_func_substr_index::val_str(String *str)
}
else
/* return right part */
{
ptr
+=
delime
ter_length
;
ptr
+=
delimi
ter_length
;
tmp_value
.
set
(
*
res
,(
ulong
)
(
ptr
-
res
->
ptr
()),
(
ulong
)
(
strend
-
ptr
));
}
}
...
...
@@ -1166,9 +1166,9 @@ String *Item_func_substr_index::val_str(String *str)
{
if
(
count
>
0
)
{
// start counting from the beginning
for
(
offset
=
0
;;
offset
+=
delime
ter_length
)
for
(
offset
=
0
;
;
offset
+=
delimi
ter_length
)
{
if
((
int
)
(
offset
=
res
->
strstr
(
*
delimeter
,
offset
))
<
0
)
if
((
int
)
(
offset
=
res
->
strstr
(
*
delimiter
,
offset
))
<
0
)
return
res
;
// Didn't find, return org string
if
(
!--
count
)
{
...
...
@@ -1189,7 +1189,7 @@ String *Item_func_substr_index::val_str(String *str)
address space less than where the found substring is located
in res
*/
if
((
int
)
(
offset
=
res
->
strrstr
(
*
delimeter
,
offset
))
<
0
)
if
((
int
)
(
offset
=
res
->
strrstr
(
*
delimiter
,
offset
))
<
0
)
return
res
;
// Didn't find, return org string
/*
At this point, we've searched for the substring
...
...
@@ -1197,13 +1197,19 @@ String *Item_func_substr_index::val_str(String *str)
*/
if
(
!++
count
)
{
offset
+=
delime
ter_length
;
offset
+=
delimi
ter_length
;
tmp_value
.
set
(
*
res
,
offset
,
res
->
length
()
-
offset
);
break
;
}
}
}
}
/*
We always mark tmp_value as const so that if val_str() is called again
on this object, we don't disrupt the contents of tmp_value when it was
derived from another String.
*/
tmp_value
.
mark_as_const
();
return
(
&
tmp_value
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment