Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
C programming 2nd term
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ильин Владимир Александрович
C programming 2nd term
Commits
10711ec5
Commit
10711ec5
authored
May 04, 2024
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix segfault in get_default_filepath
parent
23119ece
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
17 deletions
+11
-17
main.c
avtomat/main.c
+11
-17
No files found.
avtomat/main.c
View file @
10711ec5
...
@@ -89,7 +89,8 @@ main(int argc, char** argv)
...
@@ -89,7 +89,8 @@ main(int argc, char** argv)
die_if_null
(
filepaths_file
,
"Could not open given file file %s!"
,
filepaths_file_path
);
die_if_null
(
filepaths_file
,
"Could not open given file file %s!"
,
filepaths_file_path
);
while
(
getline
(
&
curr_url
,
&
url_len
,
url_file
)
!=
-
1
){
while
(
getline
(
&
curr_url
,
&
url_len
,
url_file
)
!=
-
1
){
drop_newline
(
curr_url
);
drop_newline
(
curr_url
);
// Determine the filepath
// Determine the filepath
// Memory leak.
if
(
filepaths_file_path
!=
NULL
&&
getline
(
&
curr_filepath
,
&
filepath_len
,
filepaths_file
)
!=
-
1
)
{
if
(
filepaths_file_path
!=
NULL
&&
getline
(
&
curr_filepath
,
&
filepath_len
,
filepaths_file
)
!=
-
1
)
{
// Try to read a filepath from the filepaths file
// Try to read a filepath from the filepaths file
drop_newline
(
curr_filepath
);
drop_newline
(
curr_filepath
);
...
@@ -161,24 +162,17 @@ download_file(char *url, char *filepath, CURL *curl)
...
@@ -161,24 +162,17 @@ download_file(char *url, char *filepath, CURL *curl)
char
*
char
*
get_default_filepath
(
const
char
*
url
)
get_default_filepath
(
const
char
*
url
)
{
{
char
*
url_cpy
=
malloc
(
strlen
(
url
)
+
1
);
char
*
last_slash
=
strrchr
(
url
,
'/'
);
strcpy
(
url_cpy
,
url
);
if
(
last_slash
==
NULL
)
die_if_null
(
url_cpy
,
"Malloc failed!"
);
last_slash
=
(
char
*
)
url
;
else
char
*
tok_pointer
=
strtok
(
url_cpy
,
"/"
);
last_slash
+=
1
;
// remove '/'
char
*
tok_buf
=
tok_pointer
;
//case of adress without '/' this will return adress as filename
while
(
tok_buf
!=
NULL
){
tok_pointer
=
tok_buf
;
tok_buf
=
strtok
(
NULL
,
"/"
);
}
char
*
filepath
=
malloc
(
strlen
(
tok_pointer
)
+
1
)
;
char
*
filepath
=
NULL
;
die_if_null
(
filepath
,
"Malloc failed!"
);
filepath
=
malloc
(
strlen
(
last_slash
)
+
1
);
strcpy
(
filepath
,
tok_pointer
);
die_if_null
(
filepath
,
"Malloc failed!"
);
free
(
url_cpy
);
strcpy
(
filepath
,
last_slash
);
return
filepath
;
return
filepath
;
}
}
...
...
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