diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-12-10 03:16:37 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-12-10 03:16:37 +0000 |
commit | 7b4e89b9e3acfee4295dc88fcda5605907d17651 (patch) | |
tree | f0334c8bde0d98c50cc0559ca6e10631a726442d /coreutils | |
parent | 38386d7fed1ffbeed3421ffe6ecb07e06f1473f8 (diff) |
Fix undefined behaviour and save some bytes as suggested by Manuel Novoa III
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/realpath.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/coreutils/realpath.c b/coreutils/realpath.c index 7ef935ee0..f89e0a274 100644 --- a/coreutils/realpath.c +++ b/coreutils/realpath.c @@ -21,24 +21,22 @@ int realpath_main(int argc, char **argv) { - char *resolved_path; - int count; + RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX); - if (argc == 1) { + if (--argc == 0) { show_usage(); } - resolved_path = malloc(PATH_MAX); - - for (count = 1; count < argc; count++) { - resolved_path = realpath(argv[count], resolved_path); - if (resolved_path) { + do { + argv++; + if (realpath(*argv, resolved_path) != NULL) { puts(resolved_path); } else { - perror_msg("%s", argv[count]); + perror_msg("%s", *argv); } - } - free(resolved_path); + } while (--argc); + + RELEASE_CONFIG_BUFFER(resolved_path); return(EXIT_SUCCESS); -}
\ No newline at end of file +} |