Fix undefined behaviour and save some bytes as suggested by Manuel Novoa III
This commit is contained in:
parent
38386d7fed
commit
7b4e89b9e3
@ -21,24 +21,22 @@
|
|||||||
|
|
||||||
int realpath_main(int argc, char **argv)
|
int realpath_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *resolved_path;
|
RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
|
||||||
int count;
|
|
||||||
|
|
||||||
if (argc == 1) {
|
if (--argc == 0) {
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
resolved_path = malloc(PATH_MAX);
|
do {
|
||||||
|
argv++;
|
||||||
for (count = 1; count < argc; count++) {
|
if (realpath(*argv, resolved_path) != NULL) {
|
||||||
resolved_path = realpath(argv[count], resolved_path);
|
|
||||||
if (resolved_path) {
|
|
||||||
puts(resolved_path);
|
puts(resolved_path);
|
||||||
} else {
|
} else {
|
||||||
perror_msg("%s", argv[count]);
|
perror_msg("%s", *argv);
|
||||||
}
|
}
|
||||||
}
|
} while (--argc);
|
||||||
free(resolved_path);
|
|
||||||
|
RELEASE_CONFIG_BUFFER(resolved_path);
|
||||||
|
|
||||||
return(EXIT_SUCCESS);
|
return(EXIT_SUCCESS);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user