[hackers] [sbase][PATCH] od: Fix argument parsing for -t flag

From: prez <prez_AT_national.shitposting.agency>
Date: Sun, 16 Feb 2020 21:11:47 +0100

when the -t flag is used without a number of bytes, od exits with
usage(). 'od -tx foo' should behave like 'od -tx4 foo'.

---
 od.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/od.c b/od.c
index 0b1c5c6..1780710 100644
--- a/od.c
+++ b/od.c
_AT_@ -250,6 +250,7 @@ main(int argc, char *argv[])
 		break;
 	case 't':
 		s = EARGF(usage());
+		int done = 0;
 		for (; *s; s++) {
 			switch (*s) {
 			case 'a':
_AT_@ -277,11 +278,15 @@ main(int argc, char *argv[])
 					case 'L':
 						len = sizeof(long);
 						break;
-					default:
+					case '\0':
 						len = sizeof(int);
+						done = 1;
+						break;
+					default:
+						usage();
 					}
 				}
-				addtype(*s++, len);
+				addtype(*(done ? s : s++), len);
 				break;
 			default:
 				usage();
-- 
2.20.1
Received on Sun Feb 16 2020 - 21:11:47 CET

This archive was generated by hypermail 2.3.0 : Sun Feb 16 2020 - 21:12:39 CET