Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
9bf5f285
Commit
9bf5f285
authored
Oct 09, 2014
by
Damien George
Browse files
py: Add further checks for failed malloc in lexer init functions.
parent
a8202762
Changes
5
Hide whitespace changes
Inline
Side-by-side
py/lexer.c
View file @
9bf5f285
...
...
@@ -731,7 +731,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
}
mp_lexer_t
*
mp_lexer_new
(
qstr
src_name
,
void
*
stream_data
,
mp_lexer_stream_next_byte_t
stream_next_byte
,
mp_lexer_stream_close_t
stream_close
)
{
mp_lexer_t
*
lex
=
m_new_maybe
(
mp_lexer_t
,
1
);
mp_lexer_t
*
lex
=
m_new_
obj_
maybe
(
mp_lexer_t
);
// check for memory allocation error
if
(
lex
==
NULL
)
{
...
...
py/lexerstr.c
View file @
9bf5f285
...
...
@@ -52,7 +52,7 @@ STATIC void str_buf_free(mp_lexer_str_buf_t *sb) {
}
mp_lexer_t
*
mp_lexer_new_from_str_len
(
qstr
src_name
,
const
char
*
str
,
mp_uint_t
len
,
mp_uint_t
free_len
)
{
mp_lexer_str_buf_t
*
sb
=
m_new_maybe
(
mp_lexer_str_buf_t
,
1
);
mp_lexer_str_buf_t
*
sb
=
m_new_
obj_
maybe
(
mp_lexer_str_buf_t
);
if
(
sb
==
NULL
)
{
return
NULL
;
}
...
...
py/lexerunix.c
View file @
9bf5f285
...
...
@@ -69,7 +69,10 @@ STATIC void file_buf_close(mp_lexer_file_buf_t *fb) {
}
mp_lexer_t
*
mp_lexer_new_from_file
(
const
char
*
filename
)
{
mp_lexer_file_buf_t
*
fb
=
m_new_obj
(
mp_lexer_file_buf_t
);
mp_lexer_file_buf_t
*
fb
=
m_new_obj_maybe
(
mp_lexer_file_buf_t
);
if
(
fb
==
NULL
)
{
return
NULL
;
}
fb
->
fd
=
open
(
filename
,
O_RDONLY
);
if
(
fb
->
fd
<
0
)
{
m_del_obj
(
mp_lexer_file_buf_t
,
fb
);
...
...
py/misc.h
View file @
9bf5f285
...
...
@@ -54,6 +54,7 @@ typedef unsigned int uint;
#define m_new_maybe(type, num) ((type*)(m_malloc_maybe(sizeof(type) * (num))))
#define m_new0(type, num) ((type*)(m_malloc0(sizeof(type) * (num))))
#define m_new_obj(type) (m_new(type, 1))
#define m_new_obj_maybe(type) (m_new_maybe(type, 1))
#define m_new_obj_var(obj_type, var_type, var_num) ((obj_type*)m_malloc(sizeof(obj_type) + sizeof(var_type) * (var_num)))
#define m_new_obj_var_maybe(obj_type, var_type, var_num) ((obj_type*)m_malloc_maybe(sizeof(obj_type) + sizeof(var_type) * (var_num)))
#if MICROPY_ENABLE_FINALISER
...
...
stmhal/lexerfatfs.c
View file @
9bf5f285
...
...
@@ -64,7 +64,10 @@ STATIC void file_buf_close(mp_lexer_file_buf_t *fb) {
}
mp_lexer_t
*
mp_lexer_new_from_file
(
const
char
*
filename
)
{
mp_lexer_file_buf_t
*
fb
=
m_new_obj
(
mp_lexer_file_buf_t
);
mp_lexer_file_buf_t
*
fb
=
m_new_obj_maybe
(
mp_lexer_file_buf_t
);
if
(
fb
==
NULL
)
{
return
NULL
;
}
FRESULT
res
=
f_open
(
&
fb
->
fp
,
filename
,
FA_READ
);
if
(
res
!=
FR_OK
)
{
m_del_obj
(
mp_lexer_file_buf_t
,
fb
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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