Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Libraries
mruby
Commits
952e7efd
Unverified
Commit
952e7efd
authored
3 years ago
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pack.c: refactor pack/unpack 'X'.
parent
3ddc57ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
28 deletions
+12
-28
mrbgems/mruby-pack/src/pack.c
mrbgems/mruby-pack/src/pack.c
+12
-28
No files found.
mrbgems/mruby-pack/src/pack.c
View file @
952e7efd
...
...
@@ -1016,31 +1016,12 @@ pack_x(mrb_state *mrb, mrb_value dst, mrb_int didx, int count)
return
count
;
}
static
int
unpack_x
(
mrb_state
*
mrb
,
int
slen
,
int
count
)
{
if
(
slen
<
count
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"x outside of string"
);
}
return
count
;
}
static
int
pack_X
(
mrb_state
*
mrb
,
mrb_value
dst
,
mrb_int
didx
,
int
count
)
{
if
(
count
>
didx
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"X outside of string"
);
}
return
count
;
}
static
int
unpack_X
(
mrb_state
*
mrb
,
int
sidx
,
int
count
)
static
void
check_x
(
mrb_state
*
mrb
,
int
a
,
int
count
,
char
c
)
{
if
(
sidx
<
count
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"X outside of string"
);
if
(
a
<
count
)
{
mrb_raise
f
(
mrb
,
E_ARGUMENT_ERROR
,
"%c outside of string"
,
c
);
}
return
count
;
}
static
void
...
...
@@ -1318,13 +1299,14 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary)
if
(
dir
==
PACK_DIR_INVALID
)
continue
;
else
if
(
dir
==
PACK_DIR_NUL
)
{
if
(
count
>
0
&&
ridx
>
INT_MAX
-
count
)
goto
overflow
;
grow:
if
(
ridx
>
INT_MAX
-
count
)
goto
overflow
;
ridx
+=
pack_x
(
mrb
,
result
,
ridx
,
count
);
continue
;
}
else
if
(
dir
==
PACK_DIR_BACK
)
{
if
(
count
>
0
&&
ridx
>
INT_MAX
-
count
)
goto
overflow
;
ridx
-=
pack_X
(
mrb
,
result
,
ridx
,
count
)
;
check_x
(
mrb
,
ridx
,
count
,
'X'
)
;
ridx
-=
count
;
continue
;
}
...
...
@@ -1436,11 +1418,13 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single)
if
(
dir
==
PACK_DIR_INVALID
)
continue
;
else
if
(
dir
==
PACK_DIR_NUL
)
{
srcidx
+=
unpack_x
(
mrb
,
srclen
-
srcidx
,
count
);
check_x
(
mrb
,
srclen
-
srcidx
,
count
,
'x'
);
srcidx
+=
count
;
continue
;
}
else
if
(
dir
==
PACK_DIR_BACK
)
{
srcidx
-=
unpack_X
(
mrb
,
srcidx
,
count
);
check_x
(
mrb
,
srcidx
,
count
,
'X'
);
srcidx
-=
count
;
continue
;
}
...
...
This diff is collapsed.
Click to expand it.
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