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 | |
parent | 38386d7fed1ffbeed3421ffe6ecb07e06f1473f8 (diff) | |
download | busybox-w32-7b4e89b9e3acfee4295dc88fcda5605907d17651.tar.gz busybox-w32-7b4e89b9e3acfee4295dc88fcda5605907d17651.tar.bz2 busybox-w32-7b4e89b9e3acfee4295dc88fcda5605907d17651.zip |
Fix undefined behaviour and save some bytes as suggested by Manuel Novoa III
-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 @@ | |||
21 | 21 | ||
22 | int realpath_main(int argc, char **argv) | 22 | int realpath_main(int argc, char **argv) |
23 | { | 23 | { |
24 | char *resolved_path; | 24 | RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX); |
25 | int count; | ||
26 | 25 | ||
27 | if (argc == 1) { | 26 | if (--argc == 0) { |
28 | show_usage(); | 27 | show_usage(); |
29 | } | 28 | } |
30 | 29 | ||
31 | resolved_path = malloc(PATH_MAX); | 30 | do { |
32 | 31 | argv++; | |
33 | for (count = 1; count < argc; count++) { | 32 | if (realpath(*argv, resolved_path) != NULL) { |
34 | resolved_path = realpath(argv[count], resolved_path); | ||
35 | if (resolved_path) { | ||
36 | puts(resolved_path); | 33 | puts(resolved_path); |
37 | } else { | 34 | } else { |
38 | perror_msg("%s", argv[count]); | 35 | perror_msg("%s", *argv); |
39 | } | 36 | } |
40 | } | 37 | } while (--argc); |
41 | free(resolved_path); | 38 | |
39 | RELEASE_CONFIG_BUFFER(resolved_path); | ||
42 | 40 | ||
43 | return(EXIT_SUCCESS); | 41 | return(EXIT_SUCCESS); |
44 | } \ No newline at end of file | 42 | } |