Browse Source

Fix some issues discovered while testing out the Debian GNU/kFreeBSD
build.

Douglas William Thrift 14 years ago
parent
commit
075bd3a750
2 changed files with 12 additions and 12 deletions
  1. 1 1
      GNUmakefile
  2. 11 11
      dtpstree.cpp

+ 1 - 1
GNUmakefile

@@ -1,5 +1,5 @@
 CXXFLAGS ?= -g -O2
-CXXFLAGS += -pedantic -Wall -Wno-long-long
+CXXFLAGS += -Wall -Wno-long-long
 LDLIBS := -lkvm
 
 .PHONY: all man clean

+ 11 - 11
dtpstree.cpp

@@ -304,12 +304,12 @@ static Type value(char *program, option options[], bool *success = NULL)
 			warnx("invalid numeric value: \"%s\"", optarg);
 			help(program, options, 1);
 		}
-	else if (value < minimum)
+	else if (value <= minimum)
 	{
 		warnx("number too small: %s", optarg);
 		help(program, options, 1);
 	}
-	else if (value > maximum)
+	else if (value >= maximum)
 	{
 		warnx("number too large: %s", optarg);
 		help(program, options, 1);
@@ -362,7 +362,7 @@ static int options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&user)
 		case 'h':
 			help(program, options);
 		case 'H':
-			hpid = optarg ? value<pid_t, 0, INT_MAX>(program, options) : getpid();
+			hpid = optarg ? value<pid_t, -1, INT_MAX>(program, options) : getpid();
 			flags |= Highlight;
 
 			break;
@@ -398,7 +398,7 @@ static int options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&user)
 
 				if (option == "pid")
 				{
-					pid = value<pid_t, 0, INT_MAX>(program, options);
+					pid = value<pid_t, -1, INT_MAX>(program, options);
 					flags |= Pid;
 					flags &= ~User;
 				}
@@ -422,9 +422,14 @@ static int options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&user)
 		bool success;
 
 		optarg = argv[index];
-		pid = value<pid_t, 0, INT_MAX>(program, options, &success);
+		pid = value<pid_t, -1, INT_MAX>(program, options, &success);
 
 		if (success)
+		{
+			flags |= Pid;
+			flags &= ~User;
+		}
+		else
 		{
 			std::free(user);
 
@@ -432,11 +437,6 @@ static int options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&user)
 			flags |= User;
 			flags &= ~Pid;
 		}
-		else
-		{
-			flags |= Pid;
-			flags &= ~User;
-		}
 	}
 
 	return flags;
@@ -444,7 +444,7 @@ static int options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&user)
 
 int main(int argc, char *argv[])
 {
-	pid_t hpid, pid;
+	pid_t hpid(-1), pid(-1);
 	char *user(NULL);
 	int flags(options(argc, argv, hpid, pid, user));