[PATCH] policycoreutils/hll/pp: use argv[optind] appropriately

Stephen Smalley <[email protected]>
Newsgroups org.kernel.vger.selinux
Message-ID <[email protected]>
The input and output filenames are read from argv[1] and argv[2]
regardless of what getopt consumed so "pp -- foo.pp" tries to open
"--". Use optind.

Signed-off-by: Stephen Smalley <[email protected]>
---
 policycoreutils/hll/pp/pp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/policycoreutils/hll/pp/pp.c b/policycoreutils/hll/pp/pp.c
index 7280a70b..08d2c56d 100644
--- a/policycoreutils/hll/pp/pp.c
+++ b/policycoreutils/hll/pp/pp.c
@@ -90,8 +90,8 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (argc >= optind + 1 && strcmp(argv[1], "-") != 0) {
-		ifile = argv[1];
+	if (argc >= optind + 1 && strcmp(argv[optind], "-") != 0) {
+		ifile = argv[optind];
 		in = fopen(ifile, "rb");
 		if (in == NULL) {
 			log_err("Failed to open %s: %s", ifile,
@@ -104,8 +104,8 @@ int main(int argc, char **argv)
 		in = stdin;
 	}
 
-	if (argc >= optind + 2 && strcmp(argv[2], "-") != 0) {
-		ofile = argv[2];
+	if (argc >= optind + 2 && strcmp(argv[optind + 1], "-") != 0) {
+		ofile = argv[optind + 1];
 		out = fopen(ofile, "w");
 		if (out == NULL) {
 			log_err("Failed to open %s: %s", ofile,
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.