Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
YGOPRO-520DIY
ygopro
Commits
81d0ef16
Commit
81d0ef16
authored
May 03, 2024
by
salix5
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EncodeUTF8: check array size
parent
d58bb28a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
29 deletions
+45
-29
gframe/bufferio.h
gframe/bufferio.h
+45
-29
No files found.
gframe/bufferio.h
View file @
81d0ef16
...
...
@@ -58,23 +58,36 @@ public:
return
l
;
}
// UTF-16/UTF-32 to UTF-8
static
int
EncodeUTF8
(
const
wchar_t
*
wsrc
,
char
*
str
)
{
template
<
size_t
N
>
static
int
EncodeUTF8
(
const
wchar_t
*
wsrc
,
char
(
&
str
)[
N
])
{
char
*
pstr
=
str
;
while
(
*
wsrc
!=
0
)
{
while
(
*
wsrc
!=
0
)
{
unsigned
cur
=
*
wsrc
;
if
(
cur
<
0x80
)
{
*
str
=
(
char
)
cur
;
++
str
;
}
else
if
(
cur
<
0x800
)
{
str
[
0
]
=
((
cur
>>
6
)
&
0x1f
)
|
0xc0
;
str
[
1
]
=
(
cur
&
0x3f
)
|
0x80
;
str
+=
2
;
}
else
if
(
cur
<
0x10000
&&
(
cur
<
0xd800
||
cur
>
0xdfff
))
{
str
[
0
]
=
((
cur
>>
12
)
&
0xf
)
|
0xe0
;
str
[
1
]
=
((
cur
>>
6
)
&
0x3f
)
|
0x80
;
str
[
2
]
=
(
cur
&
0x3f
)
|
0x80
;
str
+=
3
;
}
else
{
int
codepoint_size
=
0
;
if
(
cur
<
0x80U
)
codepoint_size
=
1
;
else
if
(
cur
<
0x800U
)
codepoint_size
=
2
;
else
if
(
cur
<
0x10000U
&&
(
cur
<
0xd800U
||
cur
>
0xdfffU
))
codepoint_size
=
3
;
else
codepoint_size
=
4
;
if
(
pstr
-
str
+
codepoint_size
>
N
-
1
)
break
;
switch
(
codepoint_size
)
{
case
1
:
*
pstr
=
(
char
)
cur
;
break
;
case
2
:
pstr
[
0
]
=
((
cur
>>
6
)
&
0x1f
)
|
0xc0
;
pstr
[
1
]
=
(
cur
&
0x3f
)
|
0x80
;
break
;
case
3
:
pstr
[
0
]
=
((
cur
>>
12
)
&
0xf
)
|
0xe0
;
pstr
[
1
]
=
((
cur
>>
6
)
&
0x3f
)
|
0x80
;
pstr
[
2
]
=
(
cur
&
0x3f
)
|
0x80
;
break
;
case
4
:
if
(
sizeof
(
wchar_t
)
==
2
)
{
cur
=
0
;
cur
|=
((
unsigned
)
*
wsrc
&
0x3ff
)
<<
10
;
...
...
@@ -82,16 +95,19 @@ public:
cur
|=
(
unsigned
)
*
wsrc
&
0x3ff
;
cur
+=
0x10000
;
}
str
[
0
]
=
((
cur
>>
18
)
&
0x7
)
|
0xf0
;
str
[
1
]
=
((
cur
>>
12
)
&
0x3f
)
|
0x80
;
str
[
2
]
=
((
cur
>>
6
)
&
0x3f
)
|
0x80
;
str
[
3
]
=
(
cur
&
0x3f
)
|
0x80
;
str
+=
4
;
pstr
[
0
]
=
((
cur
>>
18
)
&
0x7
)
|
0xf0
;
pstr
[
1
]
=
((
cur
>>
12
)
&
0x3f
)
|
0x80
;
pstr
[
2
]
=
((
cur
>>
6
)
&
0x3f
)
|
0x80
;
pstr
[
3
]
=
(
cur
&
0x3f
)
|
0x80
;
break
;
default:
break
;
}
pstr
+=
codepoint_size
;
wsrc
++
;
}
*
str
=
0
;
return
str
-
p
str
;
*
p
str
=
0
;
return
pstr
-
str
;
}
// UTF-8 to UTF-16/UTF-32
static
int
DecodeUTF8
(
const
char
*
src
,
wchar_t
*
wstr
)
{
...
...
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