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
b09f1712
Commit
b09f1712
authored
Apr 30, 2015
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2778 from cremno/fix-load-size-error-macros
src/load.c: fix size error macros
parents
5d0c8a70
c579ab1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
18 deletions
+8
-18
src/load.c
src/load.c
+8
-18
No files found.
src/load.c
View file @
b09f1712
...
...
@@ -14,23 +14,17 @@
#include "mruby/debug.h"
#include "mruby/error.h"
#if SIZE_MAX < UINT32_MAX
# error size_t must be at least 32 bits wide
#endif
#define FLAG_BYTEORDER_BIG 2
#define FLAG_BYTEORDER_LIL 4
#define FLAG_BYTEORDER_NATIVE 8
#define FLAG_SRC_MALLOC 1
#define FLAG_SRC_STATIC 0
#if SIZE_MAX < UINT32_MAX
# define SIZE_ERROR_MUL(x, y) ((x) > SIZE_MAX / (y))
# define SIZE_ERROR(x) ((x) > SIZE_MAX)
#else
# define SIZE_ERROR_MUL(x, y) (0)
# define SIZE_ERROR(x) (0)
#endif
#if UINT32_MAX > SIZE_MAX
# error This code cannot be built on your environment.
#endif
#define SIZE_ERROR_MUL(nmemb, size) ((nmemb) > SIZE_MAX / (size))
static
size_t
skip_padding
(
const
uint8_t
*
buf
)
...
...
@@ -79,7 +73,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
src
+=
skip_padding
(
src
);
if
(
irep
->
ilen
>
0
)
{
if
(
SIZE_ERROR_MUL
(
sizeof
(
mrb_code
),
irep
->
ilen
))
{
if
(
SIZE_ERROR_MUL
(
irep
->
ilen
,
sizeof
(
mrb_code
)
))
{
return
NULL
;
}
if
((
flags
&
FLAG_SRC_MALLOC
)
==
0
&&
...
...
@@ -113,7 +107,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
plen
=
(
size_t
)
bin_to_uint32
(
src
);
/* number of pool */
src
+=
sizeof
(
uint32_t
);
if
(
plen
>
0
)
{
if
(
SIZE_ERROR_MUL
(
sizeof
(
mrb_value
),
plen
))
{
if
(
SIZE_ERROR_MUL
(
plen
,
sizeof
(
mrb_value
)
))
{
return
NULL
;
}
irep
->
pool
=
(
mrb_value
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_value
)
*
plen
);
...
...
@@ -158,7 +152,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
irep
->
slen
=
(
size_t
)
bin_to_uint32
(
src
);
/* syms length */
src
+=
sizeof
(
uint32_t
);
if
(
irep
->
slen
>
0
)
{
if
(
SIZE_ERROR_MUL
(
sizeof
(
mrb_sym
),
irep
->
slen
))
{
if
(
SIZE_ERROR_MUL
(
irep
->
slen
,
sizeof
(
mrb_sym
)
))
{
return
NULL
;
}
irep
->
syms
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
)
*
irep
->
slen
);
...
...
@@ -239,9 +233,6 @@ read_lineno_record_1(mrb_state *mrb, const uint8_t *bin, mrb_irep *irep, size_t
fname_len
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
*
len
+=
sizeof
(
uint16_t
);
if
(
SIZE_ERROR
(
fname_len
+
1
))
{
return
MRB_DUMP_GENERAL_FAILURE
;
}
fname
=
(
char
*
)
mrb_malloc
(
mrb
,
fname_len
+
1
);
memcpy
(
fname
,
bin
,
fname_len
);
fname
[
fname_len
]
=
'\0'
;
...
...
@@ -667,7 +658,6 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
return
NULL
;
}
/* You don't need use SIZE_ERROR as buf_size is enough small. */
buf
=
(
uint8_t
*
)
mrb_malloc
(
mrb
,
header_size
);
if
(
fread
(
buf
,
header_size
,
1
,
fp
)
==
0
)
{
goto
irep_exit
;
...
...
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