Patch from Matt Kraai <kraai@alumni.carnegiemellon.edu>:
authorEric Andersen <andersen@codepoet.org>
Mon, 10 Jul 2000 16:38:50 +0000 (16:38 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 10 Jul 2000 16:38:50 +0000 (16:38 -0000)
GNU tr complains on the following:

$ tr a ''
tr: when not truncating set1, string2 must be non-empty

BusyBox tr does not complain:

$ tr a ''
a
^D
0

It should result in an error, not in some spurious output.  The attached
patch generates an error.

Matt

coreutils/tr.c
tr.c

index 48cdd47bddfe5503c48e18ea5a6870cf3c694c3b..5a8116db06ccd9b4a0ec78e44766654433303337 100644 (file)
@@ -187,10 +187,12 @@ extern int tr_main(int argc, char **argv)
                expand(argv[index++], input);
                if (com_fl)
                        complement(input);
-               if (argv[index] != NULL)
+               if (argv[index] != NULL) {
+                       if (*argv[index] == '\0')
+                               fatalError("tr: STRING2 cannot be empty\n");
                        expand(argv[index], output);
-               if (argv[index] != NULL)
                        map(input, output);
+               }
                for (ptr = input; *ptr; ptr++)
                        invec[*ptr] = TRUE;
                for (ptr = output; *ptr; ptr++)
diff --git a/tr.c b/tr.c
index 48cdd47bddfe5503c48e18ea5a6870cf3c694c3b..5a8116db06ccd9b4a0ec78e44766654433303337 100644 (file)
--- a/tr.c
+++ b/tr.c
@@ -187,10 +187,12 @@ extern int tr_main(int argc, char **argv)
                expand(argv[index++], input);
                if (com_fl)
                        complement(input);
-               if (argv[index] != NULL)
+               if (argv[index] != NULL) {
+                       if (*argv[index] == '\0')
+                               fatalError("tr: STRING2 cannot be empty\n");
                        expand(argv[index], output);
-               if (argv[index] != NULL)
                        map(input, output);
+               }
                for (ptr = input; *ptr; ptr++)
                        invec[*ptr] = TRUE;
                for (ptr = output; *ptr; ptr++)