Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
2e0a7fda
Commit
2e0a7fda
authored
Sep 11, 2014
by
Vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check return values of malloc, realloc, strdup and strndup
parent
3f9d9217
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
8 deletions
+46
-8
auto-static.c
auto-static.c
+6
-0
generate.c
generate.c
+7
-1
interface.c
interface.c
+25
-7
loop.c
loop.c
+2
-0
lua-tg.c
lua-tg.c
+2
-0
structures.c
structures.c
+4
-0
No files found.
auto-static.c
View file @
2e0a7fda
...
@@ -57,6 +57,7 @@ static int (*autocomplete_fun)(const char *, int, int, char **);
...
@@ -57,6 +57,7 @@ static int (*autocomplete_fun)(const char *, int, int, char **);
static
void
set_autocomplete_string
(
const
char
*
s
)
{
static
void
set_autocomplete_string
(
const
char
*
s
)
{
if
(
autocomplete_string
)
{
free
(
autocomplete_string
);
}
if
(
autocomplete_string
)
{
free
(
autocomplete_string
);
}
autocomplete_string
=
strdup
(
s
);
autocomplete_string
=
strdup
(
s
);
assert
(
autocomplete_string
);
autocomplete_mode
=
1
;
autocomplete_mode
=
1
;
}
}
...
@@ -116,12 +117,16 @@ static double get_double (void) {
...
@@ -116,12 +117,16 @@ static double get_double (void) {
static
struct
paramed_type
*
paramed_type_dup
(
struct
paramed_type
*
P
)
{
static
struct
paramed_type
*
paramed_type_dup
(
struct
paramed_type
*
P
)
{
if
(
ODDP
(
P
))
{
return
P
;
}
if
(
ODDP
(
P
))
{
return
P
;
}
struct
paramed_type
*
R
=
malloc
(
sizeof
(
*
R
));
struct
paramed_type
*
R
=
malloc
(
sizeof
(
*
R
));
assert
(
R
);
R
->
type
=
malloc
(
sizeof
(
*
R
->
type
));
R
->
type
=
malloc
(
sizeof
(
*
R
->
type
));
assert
(
R
->
type
);
memcpy
(
R
->
type
,
P
->
type
,
sizeof
(
*
P
->
type
));
memcpy
(
R
->
type
,
P
->
type
,
sizeof
(
*
P
->
type
));
R
->
type
->
id
=
strdup
(
P
->
type
->
id
);
R
->
type
->
id
=
strdup
(
P
->
type
->
id
);
assert
(
R
->
type
->
id
);
if
(
P
->
type
->
params_num
)
{
if
(
P
->
type
->
params_num
)
{
R
->
params
=
malloc
(
sizeof
(
void
*
)
*
P
->
type
->
params_num
);
R
->
params
=
malloc
(
sizeof
(
void
*
)
*
P
->
type
->
params_num
);
assert
(
R
->
params
);
int
i
;
int
i
;
for
(
i
=
0
;
i
<
P
->
type
->
params_num
;
i
++
)
{
for
(
i
=
0
;
i
<
P
->
type
->
params_num
;
i
++
)
{
R
->
params
[
i
]
=
paramed_type_dup
(
P
->
params
[
i
]);
R
->
params
[
i
]
=
paramed_type_dup
(
P
->
params
[
i
]);
...
@@ -287,6 +292,7 @@ int tglf_extf_autocomplete (const char *text, int text_len, int index, char **R,
...
@@ -287,6 +292,7 @@ int tglf_extf_autocomplete (const char *text, int text_len, int index, char **R,
index
=
0
;
index
=
0
;
if
(
!
strncmp
(
text
,
autocomplete_string
,
len
))
{
if
(
!
strncmp
(
text
,
autocomplete_string
,
len
))
{
*
R
=
strdup
(
autocomplete_string
);
*
R
=
strdup
(
autocomplete_string
);
assert
(
*
R
);
return
index
;
return
index
;
}
else
{
}
else
{
return
-
1
;
return
-
1
;
...
...
generate.c
View file @
2e0a7fda
...
@@ -99,6 +99,7 @@ long long get_long (void) {
...
@@ -99,6 +99,7 @@ long long get_long (void) {
static
void
*
malloc0
(
int
size
)
{
static
void
*
malloc0
(
int
size
)
{
void
*
r
=
malloc
(
size
);
void
*
r
=
malloc
(
size
);
assert
(
r
);
memset
(
r
,
0
,
size
);
memset
(
r
,
0
,
size
);
return
r
;
return
r
;
}
}
...
@@ -126,7 +127,9 @@ char *get_string (void) {
...
@@ -126,7 +127,9 @@ char *get_string (void) {
buf_ptr
+=
tlen
/
4
;
buf_ptr
+=
tlen
/
4
;
assert
(
buf_ptr
<=
buf_end
);
assert
(
buf_ptr
<=
buf_end
);
return
strndup
(
res
,
len
);
char
*
r
=
strndup
(
res
,
len
);
assert
(
r
);
return
r
;
}
}
...
@@ -144,6 +147,7 @@ int read_args_list (struct arg **args, int args_num, int *var_num);
...
@@ -144,6 +147,7 @@ int read_args_list (struct arg **args, int args_num, int *var_num);
void
*
int_to_var_nat_const_init
(
long
long
x
)
{
void
*
int_to_var_nat_const_init
(
long
long
x
)
{
if
(
use_var_nat_full_form
(
x
))
{
if
(
use_var_nat_full_form
(
x
))
{
struct
tl_tree_nat_const
*
T
=
malloc
(
sizeof
(
*
T
));
struct
tl_tree_nat_const
*
T
=
malloc
(
sizeof
(
*
T
));
assert
(
T
);
T
->
self
.
flags
=
0
;
T
->
self
.
flags
=
0
;
T
->
self
.
methods
=
&
tl_pnat_const_full_methods
;
T
->
self
.
methods
=
&
tl_pnat_const_full_methods
;
T
->
value
=
x
;
T
->
value
=
x
;
...
@@ -1460,6 +1464,7 @@ struct tl_combinator *read_combinators (int v) {
...
@@ -1460,6 +1464,7 @@ struct tl_combinator *read_combinators (int v) {
c
->
name
=
get_int
();
c
->
name
=
get_int
();
c
->
id
=
get_string
();
c
->
id
=
get_string
();
c
->
print_id
=
strdup
(
gen_print_id
(
c
->
id
));
c
->
print_id
=
strdup
(
gen_print_id
(
c
->
id
));
assert
(
c
->
print_id
);
//char *s = c->id;
//char *s = c->id;
//while (*s) { if (*s == '.') { *s = '_'; } ; s ++;}
//while (*s) { if (*s == '.') { *s = '_'; } ; s ++;}
int
x
=
get_int
();
int
x
=
get_int
();
...
@@ -1485,6 +1490,7 @@ struct tl_type *read_types (void) {
...
@@ -1485,6 +1490,7 @@ struct tl_type *read_types (void) {
t
->
name
=
get_int
();
t
->
name
=
get_int
();
t
->
id
=
get_string
();
t
->
id
=
get_string
();
t
->
print_id
=
strdup
(
gen_print_id
(
t
->
id
));
t
->
print_id
=
strdup
(
gen_print_id
(
t
->
id
));
assert
(
t
->
print_id
);
t
->
constructors_num
=
get_int
();
t
->
constructors_num
=
get_int
();
assert
(
t
->
constructors_num
>=
0
&&
t
->
constructors_num
<=
1000
);
assert
(
t
->
constructors_num
>=
0
&&
t
->
constructors_num
<=
1000
);
...
...
interface.c
View file @
2e0a7fda
...
@@ -461,6 +461,7 @@ int complete_string_list (char **list, int index, const char *text, int len, cha
...
@@ -461,6 +461,7 @@ int complete_string_list (char **list, int index, const char *text, int len, cha
}
}
if
(
list
[
index
])
{
if
(
list
[
index
])
{
*
R
=
strdup
(
list
[
index
]);
*
R
=
strdup
(
list
[
index
]);
assert
(
*
R
);
return
index
;
return
index
;
}
else
{
}
else
{
*
R
=
0
;
*
R
=
0
;
...
@@ -475,6 +476,7 @@ int complete_command_list (int index, const char *text, int len, char **R) {
...
@@ -475,6 +476,7 @@ int complete_command_list (int index, const char *text, int len, char **R) {
}
}
if
(
commands
[
index
].
name
)
{
if
(
commands
[
index
].
name
)
{
*
R
=
strdup
(
commands
[
index
].
name
);
*
R
=
strdup
(
commands
[
index
].
name
);
assert
(
*
R
);
return
index
;
return
index
;
}
else
{
}
else
{
*
R
=
0
;
*
R
=
0
;
...
@@ -1163,7 +1165,9 @@ void interpreter (char *line UU) {
...
@@ -1163,7 +1165,9 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
tgl_do_send_photo
(
tgl_message_media_photo
,
id
,
strndup
(
s
,
t
),
0
,
0
);
char
*
d
=
strndup
(
s
,
t
);
assert
(
d
);
tgl_do_send_photo
(
tgl_message_media_photo
,
id
,
d
,
0
,
0
);
}
else
if
(
IS_WORD
(
"chat_set_photo"
))
{
}
else
if
(
IS_WORD
(
"chat_set_photo"
))
{
GET_PEER_CHAT
;
GET_PEER_CHAT
;
int
t
;
int
t
;
...
@@ -1172,7 +1176,9 @@ void interpreter (char *line UU) {
...
@@ -1172,7 +1176,9 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
tgl_do_set_chat_photo
(
id
,
strndup
(
s
,
t
),
0
,
0
);
char
*
d
=
strndup
(
s
,
t
);
assert
(
d
);
tgl_do_set_chat_photo
(
id
,
d
,
0
,
0
);
}
else
if
(
IS_WORD
(
"set_profile_photo"
))
{
}
else
if
(
IS_WORD
(
"set_profile_photo"
))
{
int
t
;
int
t
;
char
*
s
=
end_string_token
(
&
t
);
char
*
s
=
end_string_token
(
&
t
);
...
@@ -1180,7 +1186,9 @@ void interpreter (char *line UU) {
...
@@ -1180,7 +1186,9 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
tgl_do_set_profile_photo
(
strndup
(
s
,
t
),
0
,
0
);
char
*
d
=
strndup
(
s
,
t
);
assert
(
d
);
tgl_do_set_profile_photo
(
d
,
0
,
0
);
}
else
if
(
IS_WORD
(
"send_video"
))
{
}
else
if
(
IS_WORD
(
"send_video"
))
{
GET_PEER
;
GET_PEER
;
int
t
;
int
t
;
...
@@ -1189,7 +1197,9 @@ void interpreter (char *line UU) {
...
@@ -1189,7 +1197,9 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
tgl_do_send_photo
(
tgl_message_media_video
,
id
,
strndup
(
s
,
t
),
0
,
0
);
char
*
d
=
strndup
(
s
,
t
);
assert
(
d
);
tgl_do_send_photo
(
tgl_message_media_video
,
id
,
d
,
0
,
0
);
}
else
if
(
IS_WORD
(
"send_text"
))
{
}
else
if
(
IS_WORD
(
"send_text"
))
{
GET_PEER
;
GET_PEER
;
int
t
;
int
t
;
...
@@ -1198,7 +1208,9 @@ void interpreter (char *line UU) {
...
@@ -1198,7 +1208,9 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
tgl_do_send_text
(
id
,
strndup
(
s
,
t
),
0
,
0
);
char
*
d
=
strndup
(
s
,
t
);
assert
(
d
);
tgl_do_send_text
(
id
,
d
,
0
,
0
);
}
else
if
(
IS_WORD
(
"fwd"
))
{
}
else
if
(
IS_WORD
(
"fwd"
))
{
GET_PEER
;
GET_PEER
;
int
num
=
next_token_int
();
int
num
=
next_token_int
();
...
@@ -1533,7 +1545,9 @@ void interpreter (char *line UU) {
...
@@ -1533,7 +1545,9 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
tgl_do_send_photo
(
tgl_message_media_audio
,
id
,
strndup
(
s
,
t
),
0
,
0
);
char
*
d
=
strndup
(
s
,
t
);
assert
(
d
);
tgl_do_send_photo
(
tgl_message_media_audio
,
id
,
d
,
0
,
0
);
}
else
if
(
IS_WORD
(
"send_document"
))
{
}
else
if
(
IS_WORD
(
"send_document"
))
{
GET_PEER
;
GET_PEER
;
int
t
;
int
t
;
...
@@ -1542,7 +1556,9 @@ void interpreter (char *line UU) {
...
@@ -1542,7 +1556,9 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
tgl_do_send_photo
(
tgl_message_media_document
,
id
,
strndup
(
s
,
t
),
0
,
0
);
char
*
d
=
strndup
(
s
,
t
);
assert
(
d
);
tgl_do_send_photo
(
tgl_message_media_document
,
id
,
d
,
0
,
0
);
}
else
if
(
IS_WORD
(
"load_audio"
))
{
}
else
if
(
IS_WORD
(
"load_audio"
))
{
long
long
num
=
next_token_int
();
long
long
num
=
next_token_int
();
if
(
num
==
NOT_FOUND
)
{
if
(
num
==
NOT_FOUND
)
{
...
@@ -1739,6 +1755,7 @@ void print_start (void) {
...
@@ -1739,6 +1755,7 @@ void print_start (void) {
saved_point
=
rl_point
;
saved_point
=
rl_point
;
#ifdef READLINE_GNU
#ifdef READLINE_GNU
saved_line
=
malloc
(
rl_end
+
1
);
saved_line
=
malloc
(
rl_end
+
1
);
assert
(
saved_line
);
saved_line
[
rl_end
]
=
0
;
saved_line
[
rl_end
]
=
0
;
memcpy
(
saved_line
,
rl_line_buffer
,
rl_end
);
memcpy
(
saved_line
,
rl_line_buffer
,
rl_end
);
...
@@ -1747,6 +1764,7 @@ void print_start (void) {
...
@@ -1747,6 +1764,7 @@ void print_start (void) {
#else
#else
assert
(
rl_end
>=
0
);
assert
(
rl_end
>=
0
);
saved_line
=
malloc
(
rl_end
+
1
);
saved_line
=
malloc
(
rl_end
+
1
);
assert
(
saved_line
);
memcpy
(
saved_line
,
rl_line_buffer
,
rl_end
+
1
);
memcpy
(
saved_line
,
rl_line_buffer
,
rl_end
+
1
);
rl_line_buffer
[
0
]
=
0
;
rl_line_buffer
[
0
]
=
0
;
set_prompt
(
""
);
set_prompt
(
""
);
...
...
loop.c
View file @
2e0a7fda
...
@@ -96,6 +96,7 @@ static void stdin_read_callback_all (int arg, short what, struct event *self) {
...
@@ -96,6 +96,7 @@ static void stdin_read_callback_all (int arg, short what, struct event *self) {
while
(
1
)
{
while
(
1
)
{
if
(
line_buffer_pos
==
line_buffer_size
)
{
if
(
line_buffer_pos
==
line_buffer_size
)
{
line_buffer
=
realloc
(
line_buffer
,
line_buffer_size
*
2
+
100
);
line_buffer
=
realloc
(
line_buffer
,
line_buffer_size
*
2
+
100
);
assert
(
line_buffer
);
line_buffer_size
=
line_buffer_size
*
2
+
100
;
line_buffer_size
=
line_buffer_size
*
2
+
100
;
assert
(
line_buffer
);
assert
(
line_buffer
);
}
}
...
@@ -267,6 +268,7 @@ void sign_in_callback (void *extra, int success, int registered, const char *mha
...
@@ -267,6 +268,7 @@ void sign_in_callback (void *extra, int success, int registered, const char *mha
}
}
should_register
=
!
registered
;
should_register
=
!
registered
;
hash
=
strdup
(
mhash
);
hash
=
strdup
(
mhash
);
assert
(
hash
);
}
}
...
...
lua-tg.c
View file @
2e0a7fda
...
@@ -1181,6 +1181,7 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) {
...
@@ -1181,6 +1181,7 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) {
int
a2
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
int
a2
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
struct
lua_query_extra
*
e
=
malloc
(
sizeof
(
*
e
));
struct
lua_query_extra
*
e
=
malloc
(
sizeof
(
*
e
));
assert
(
e
);
e
->
func
=
a2
;
e
->
func
=
a2
;
e
->
param
=
a1
;
e
->
param
=
a1
;
...
@@ -1357,6 +1358,7 @@ static int postpone_from_lua (lua_State *L) {
...
@@ -1357,6 +1358,7 @@ static int postpone_from_lua (lua_State *L) {
int
*
t
=
malloc
(
16
);
int
*
t
=
malloc
(
16
);
assert
(
t
);
struct
event
*
ev
=
evtimer_new
(
tgl_state
.
ev_base
,
lua_postpone_alarm
,
t
);
struct
event
*
ev
=
evtimer_new
(
tgl_state
.
ev_base
,
lua_postpone_alarm
,
t
);
t
[
0
]
=
a1
;
t
[
0
]
=
a1
;
t
[
1
]
=
a2
;
t
[
1
]
=
a2
;
...
...
structures.c
View file @
2e0a7fda
...
@@ -1754,6 +1754,7 @@ int tgl_complete_user_list (int index, const char *text, int len, char **R) {
...
@@ -1754,6 +1754,7 @@ int tgl_complete_user_list (int index, const char *text, int len, char **R) {
}
}
if
(
index
<
peer_num
)
{
if
(
index
<
peer_num
)
{
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
assert
(
*
R
);
return
index
;
return
index
;
}
else
{
}
else
{
return
-
1
;
return
-
1
;
...
@@ -1767,6 +1768,7 @@ int tgl_complete_chat_list (int index, const char *text, int len, char **R) {
...
@@ -1767,6 +1768,7 @@ int tgl_complete_chat_list (int index, const char *text, int len, char **R) {
}
}
if
(
index
<
peer_num
)
{
if
(
index
<
peer_num
)
{
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
assert
(
*
R
);
return
index
;
return
index
;
}
else
{
}
else
{
return
-
1
;
return
-
1
;
...
@@ -1780,6 +1782,7 @@ int tgl_complete_encr_chat_list (int index, const char *text, int len, char **R)
...
@@ -1780,6 +1782,7 @@ int tgl_complete_encr_chat_list (int index, const char *text, int len, char **R)
}
}
if
(
index
<
peer_num
)
{
if
(
index
<
peer_num
)
{
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
assert
(
*
R
);
return
index
;
return
index
;
}
else
{
}
else
{
return
-
1
;
return
-
1
;
...
@@ -1793,6 +1796,7 @@ int tgl_complete_peer_list (int index, const char *text, int len, char **R) {
...
@@ -1793,6 +1796,7 @@ int tgl_complete_peer_list (int index, const char *text, int len, char **R) {
}
}
if
(
index
<
peer_num
)
{
if
(
index
<
peer_num
)
{
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
assert
(
*
R
);
return
index
;
return
index
;
}
else
{
}
else
{
return
-
1
;
return
-
1
;
...
...
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