Fix undefined behaviour and save some bytes as suggested by Manuel Novoa III
authorGlenn L McGrath <bug1@ihug.co.nz>
Tue, 10 Dec 2002 03:16:37 +0000 (03:16 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Tue, 10 Dec 2002 03:16:37 +0000 (03:16 -0000)
coreutils/realpath.c

index 7ef935ee078fabd9214e6c665e15685f24f0fa03..f89e0a27460c1b5858a0bfcfd468fa37bde46d2b 100644 (file)
 
 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
+}