mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 12:15:12 +00:00
[FIX] configure.c: Do not assume git
If parsee were downloaded from sources other than git-clone(1) (e.g.: a tarball), perror(3) fails and/or git(1) is not available on the system, "git remote get-url origin" would have unexpected results or even return a NULL pointer, which would cause undefined behaviour on strchr(repo, ...); In such conditions, a placeholder string, namely "N/A", is strdup(3)ed to `repo`.
This commit is contained in:
parent
e0f76e7929
commit
2074d8e768
1 changed files with 24 additions and 5 deletions
29
configure.c
29
configure.c
|
|
@ -186,18 +186,34 @@ cmd_stdout(char *cmd)
|
|||
FILE *f;
|
||||
char *line = NULL;
|
||||
size_t size;
|
||||
int result;
|
||||
if (!cmd)
|
||||
{
|
||||
return NULL;
|
||||
goto failure;
|
||||
}
|
||||
if (!(f = popen(cmd, "r")))
|
||||
{
|
||||
return NULL;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
getline(&line, &size, f);
|
||||
pclose(f);
|
||||
result = pclose(f);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
perror("pclose(3)");
|
||||
goto failure;
|
||||
}
|
||||
else if (result)
|
||||
{
|
||||
fprintf(stderr, "command exited with status %d: %s\n", result, cmd);
|
||||
goto failure;
|
||||
}
|
||||
return line;
|
||||
|
||||
failure:
|
||||
free(line);
|
||||
return NULL;
|
||||
}
|
||||
static int
|
||||
exec_code(char *program, char *argv[])
|
||||
|
|
@ -426,10 +442,13 @@ main_build(int argc, char *argv[])
|
|||
int opt;
|
||||
str_array_t *sources, *images, *utils, *aya;
|
||||
|
||||
if (strchr(repo, '\n'))
|
||||
if (repo)
|
||||
{
|
||||
*(strchr(repo, '\n')) = '\0';
|
||||
char *lf = strchr(repo, '\n');
|
||||
*lf = '\0';
|
||||
}
|
||||
else
|
||||
repo = strdup("N/A");
|
||||
|
||||
while ((opt = getopt(argc, argv, "sl")) != -1)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue