Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
31d1aa76
Commit
31d1aa76
authored
Apr 30, 2011
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vlc_towc(): unroll multibyte sequence decoding, fix overlong detection
parent
8a1afb86
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
25 deletions
+40
-25
src/text/unicode.c
src/text/unicode.c
+40
-25
No files found.
src/text/unicode.c
View file @
31d1aa76
...
...
@@ -225,59 +225,74 @@ int utf8_fprintf( FILE *stream, const char *fmt, ... )
*/
size_t
vlc_towc
(
const
char
*
str
,
uint32_t
*
restrict
pwc
)
{
uint8_t
*
ptr
=
(
uint8_t
*
)
str
;
assert
(
str
!=
NULL
);
uint8_t
c
=
ptr
[
0
];
uint8_t
*
ptr
=
(
uint8_t
*
)
str
,
c
;
uint32_t
cp
;
if
(
unlikely
(
c
==
'\0'
))
{
*
pwc
=
0
;
return
0
;
}
assert
(
str
!=
NULL
);
c
=
*
ptr
;
if
(
unlikely
(
c
>
0xF4
))
return
-
1
;
int
charlen
=
clz8
(
c
^
0xFF
);
switch
(
charlen
)
{
case
0
:
// 7-bit ASCII character ->
OK
case
0
:
// 7-bit ASCII character ->
short cut
*
pwc
=
c
;
return
1
;
return
c
!=
'\0'
;
case
1
:
// continuation byte -> error
return
-
1
;
}
assert
(
charlen
>=
2
&&
charlen
<=
4
);
case
2
:
if
(
unlikely
(
c
<
0xC2
))
// ASCII overlong
return
-
1
;
cp
=
(
c
&
0x1F
)
<<
6
;
break
;
uint32_t
cp
=
c
&
~
((
0xff
>>
(
7
-
charlen
))
<<
(
7
-
charlen
));
for
(
int
i
=
1
;
i
<
charlen
;
i
++
)
{
assert
(
cp
<
(
1
<<
26
));
c
=
ptr
[
i
];
case
3
:
cp
=
(
c
&
0x0F
)
<<
12
;
break
;
if
(
unlikely
((
c
>>
6
)
!=
2
))
// not a continuation byte
return
-
1
;
case
4
:
cp
=
(
c
&
0x07
)
<<
16
;
break
;
cp
=
(
cp
<<
6
)
|
(
ptr
[
i
]
&
0x3f
);
default:
assert
(
0
);
}
/* Unrolled continuation bytes decoding */
switch
(
charlen
)
{
case
4
:
if
(
unlikely
(
cp
>
0x10FFFF
))
// beyond Unicode
c
=
*++
ptr
;
if
(
unlikely
((
c
>>
6
)
!=
2
))
// not a continuation byte
return
-
1
;
cp
|=
(
c
&
0x3f
)
<<
12
;
if
(
unlikely
(
cp
>=
0x110000
))
// beyond Unicode range
return
-
1
;
/* fall through */
case
3
:
c
=
*++
ptr
;
if
(
unlikely
((
c
>>
6
)
!=
2
))
// not a continuation byte
return
-
1
;
cp
|=
(
c
&
0x3f
)
<<
6
;
if
(
unlikely
(
cp
>=
0xD800
&&
cp
<
0xC000
))
// UTF-16 surrogate
return
-
1
;
case
2
:
if
(
unlikely
(
cp
<
128
))
// ASCII overlong
if
(
unlikely
(
cp
<
(
1u
<<
(
5
*
charlen
-
4
))))
// non-ASCII overlong
return
-
1
;
if
(
unlikely
(
cp
<
(
1u
<<
(
5
*
charlen
-
3
))))
// overlong
/* fall through */
case
2
:
c
=
*++
ptr
;
if
(
unlikely
((
c
>>
6
)
!=
2
))
// not a continuation byte
return
-
1
;
cp
|=
(
c
&
0x3f
);
break
;
}
*
pwc
=
cp
;
return
charlen
;
}
...
...
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