attached.
From 4f57f0d1b1ba4c3cbf4d317f8a826f354c53a094 Mon Sep 17 00:00:00 2001
From: Hongjia Cao <[email protected]>
Date: Sun, 19 Jul 2015 15:56:43 +0800
Subject: [PATCH] env-var option value comparison fix for srun/sbatch/salloc

---
 src/salloc/opt.c       | 8 ++++----
 src/sbatch/opt.c       | 8 ++++----
 src/srun/libsrun/opt.c | 4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/salloc/opt.c b/src/salloc/opt.c
index 7a34021..1ee01e6 100644
--- a/src/salloc/opt.c
+++ b/src/salloc/opt.c
@@ -478,7 +478,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		*((char **) e->arg) = xstrdup(val);
 		break;
 	case OPT_INT:
-		if (val != NULL) {
+		if (val[0] != '\0') {
 			*((int *) e->arg) = (int) strtol(val, &end, 10);
 			if (!(end && *end == '\0')) {
 				error("%s=%s invalid. ignoring...",
@@ -493,7 +493,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		 *  - argument is "yes"
 		 *  - argument is a non-zero number
 		 */
-		if (val == NULL || strcmp(val, "") == 0) {
+		if (val[0] == '\0') {
 			*((bool *)e->arg) = true;
 		} else if (strcasecmp(val, "yes") == 0) {
 			*((bool *)e->arg) = true;
@@ -506,7 +506,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		break;
 
 	case OPT_DEBUG:
-		if (val != NULL) {
+		if (val[0] != '\0') {
 			opt.verbose = (int) strtol(val, &end, 10);
 			if (!(end && *end == '\0'))
 				error("%s=%s invalid", e->var, val);
@@ -556,7 +556,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		info("WARNING: You are attempting to initiate a second job");
 		break;
 	case OPT_EXCLUSIVE:
-		if (val == NULL) {
+		if (val[0] == '\0') {
 			opt.shared = 0;
 		} else if (!strcasecmp(val, "user")) {
 			opt.shared = 2;
diff --git a/src/sbatch/opt.c b/src/sbatch/opt.c
index db31487..f658dc8 100644
--- a/src/sbatch/opt.c
+++ b/src/sbatch/opt.c
@@ -521,7 +521,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		*((char **) e->arg) = xstrdup(val);
 		break;
 	case OPT_INT:
-		if (val != NULL) {
+		if (val[0] != '\0') {
 			*((int *) e->arg) = (int) strtol(val, &end, 10);
 			if (!(end && *end == '\0')) {
 				error("%s=%s invalid. ignoring...",
@@ -536,7 +536,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		 *  - argument is "yes"
 		 *  - argument is a non-zero number
 		 */
-		if (val == NULL || strcmp(val, "") == 0) {
+		if (val[0] == '\0') {
 			*((bool *)e->arg) = true;
 		} else if (strcasecmp(val, "yes") == 0) {
 			*((bool *)e->arg) = true;
@@ -553,7 +553,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		opt.array_inx = xstrdup(val);
 
 	case OPT_DEBUG:
-		if (val != NULL) {
+		if (val[0] != '\0') {
 			opt.verbose = (int) strtol(val, &end, 10);
 			if (!(end && *end == '\0'))
 				error("%s=%s invalid", e->var, val);
@@ -611,7 +611,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		break;
 
 	case OPT_EXCLUSIVE:
-		if (val == NULL) {
+		if (val[0] == '\0') {
 			opt.shared = 0;
 		} else if (!strcasecmp(val, "user")) {
 			opt.shared = 2;
diff --git a/src/srun/libsrun/opt.c b/src/srun/libsrun/opt.c
index 5d69b2a..dde67d3 100644
--- a/src/srun/libsrun/opt.c
+++ b/src/srun/libsrun/opt.c
@@ -679,7 +679,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		*((char **) e->arg) = xstrdup(val);
 		break;
 	case OPT_INT:
-		if (val != NULL) {
+		if (val[0] != '\0') {
 			*((int *) e->arg) = (int) strtol(val, &end, 10);
 			if (!(end && *end == '\0')) {
 				error("%s=%s invalid. ignoring...",
@@ -744,7 +744,7 @@ _process_env_var(env_vars_t *e, const char *val)
 		break;
 
 	case OPT_EXCLUSIVE:
-		if (val == NULL) {
+		if (val[0] == '\0') {
 			opt.exclusive = true;
 			opt.shared = 0;
 		} else if (!strcasecmp(val, "user")) {
-- 
2.1.4

Reply via email to