From 450f320f4ef5bc1204368adf26cf9591c336738c Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Tue, 1 Jun 2010 17:26:45 +0000
Subject: [PATCH] fixed issue when doing strtoul instead of xstrntol

---
 src/common/hostlist.c                         |  3 ++-
 src/common/slurmdb_defs.c                     |  4 +++-
 src/common/xstring.c                          |  9 ++++----
 .../block_allocator/block_allocator.c         | 22 ++++++++++++-------
 .../bluegene/plugin/bg_record_functions.c     | 15 ++++++++-----
 src/smap/configure_functions.c                | 18 ++++++++++-----
 src/smap/partition_functions.c                |  9 +++++---
 7 files changed, 50 insertions(+), 30 deletions(-)

diff --git a/src/common/hostlist.c b/src/common/hostlist.c
index 2aeefcc3930..752f1f67c90 100644
--- a/src/common/hostlist.c
+++ b/src/common/hostlist.c
@@ -2588,8 +2588,9 @@ void hostlist_parse_int_to_array(int in, int *out, int dims, int hostlist_base)
 			my_pow_minus /= hostlist_base;
 		}
 		if(out[a] < 0) {
-			fatal("Dim %d returned negitive %d from %d %d %d",
+			error("Dim %d returned negitive %d from %d %d %d",
 			      a, out[a], in, my_pow, my_pow_minus);
+			xassert(0);
 			out[a] = 0;
 		}
 	}
diff --git a/src/common/slurmdb_defs.c b/src/common/slurmdb_defs.c
index b04947e3324..2eaa930e22e 100644
--- a/src/common/slurmdb_defs.c
+++ b/src/common/slurmdb_defs.c
@@ -856,7 +856,9 @@ static int _setup_cluster_rec(slurmdb_cluster_rec_t *cluster_rec)
 			i--;
 		if(i > cluster_rec->dimensions) {
 			char *p = '\0';
-			number = strtoul(nodes + i, &p, 36);
+			number = xstrntol(nodes + i, &p,
+					  cluster_rec->dimensions,
+					  36);
 			hostlist_parse_int_to_array(
 				number, cluster_rec->dim_size,
 				cluster_rec->dimensions, 36);
diff --git a/src/common/xstring.c b/src/common/xstring.c
index 1dd095c48d4..c6c2d3d03f2 100644
--- a/src/common/xstring.c
+++ b/src/common/xstring.c
@@ -373,14 +373,13 @@ char * xstrndup(const char *str, size_t n)
 long int xstrntol(const char *str, char **endptr, size_t n, int base)
 {
 	long int number = 0;
-	char *new_str = xstrndup(str, n);
+	char new_str[n+1];
 
-	if(!new_str)
-		goto end_it;
+	memcpy(new_str, str, n);
+	new_str[n] = '\0';
 
 	number = strtol(new_str, endptr, base);
-	xfree(new_str);
-end_it:
+
 	return number;
 }
 
diff --git a/src/plugins/select/bluegene/block_allocator/block_allocator.c b/src/plugins/select/bluegene/block_allocator/block_allocator.c
index a9e1c4bb4d5..7558c0d49f0 100644
--- a/src/plugins/select/bluegene/block_allocator/block_allocator.c
+++ b/src/plugins/select/bluegene/block_allocator/block_allocator.c
@@ -953,7 +953,8 @@ extern void ba_init(node_info_msg_t *node_info_ptr, bool sanity_check)
 					numeric++;
 					continue;
 				}
-				number = strtoul(numeric, &p, cluster_base);
+				number = xstrntol(numeric, &p, cluster_dims,
+						  cluster_base);
 				break;
 			}
 			hostlist_parse_int_to_array(
@@ -1002,8 +1003,9 @@ node_info_error:
 					j++;
 					continue;
 				}
-				number = strtoul(node->nodenames + j,
-						 &p, cluster_base);
+				number = xstrntol(node->nodenames + j,
+						  &p, cluster_dims,
+						  cluster_base);
 				hostlist_parse_int_to_array(
 					number, coords, cluster_dims,
 					cluster_base);
@@ -1736,11 +1738,13 @@ extern int removable_set_bps(char *bps)
 		    && (bps[j+4] == 'x' || bps[j+4] == '-')) {
 
 			j++;
-			number = strtoul(bps + j, &p, cluster_base);
+			number = xstrntol(bps + j, &p, cluster_dims,
+					  cluster_base);
 			hostlist_parse_int_to_array(
 				number, start, cluster_dims, cluster_base);
 			j += 4;
-			number = strtoul(bps + j, &p, cluster_base);
+			number = xstrntol(bps + j, &p, cluster_dims,
+					  cluster_base);
 			hostlist_parse_int_to_array(
 				number, end, cluster_dims, cluster_base);
 			j += 3;
@@ -1761,7 +1765,8 @@ extern int removable_set_bps(char *bps)
 			j--;
 		} else if((bps[j] >= '0' && bps[j] <= '9')
 			  || (bps[j] >= 'A' && bps[j] <= 'Z')) {
-			number = strtoul(bps + j, &p, cluster_base);
+			number = xstrntol(bps + j, &p, cluster_dims,
+					  cluster_base);
 			hostlist_parse_int_to_array(
 				number, start, cluster_dims, cluster_base);
 			x = start[X];
@@ -1828,7 +1833,8 @@ extern int set_all_bps_except(char *bps)
 				numeric++;
 				continue;
 			}
-			number = strtoul(numeric, &p, cluster_base);
+			number = xstrntol(numeric, &p, cluster_dims,
+					  cluster_base);
 			break;
 		}
 		hostlist_parse_int_to_array(
@@ -2136,7 +2142,7 @@ extern char *find_bp_rack_mid(char* xyz)
 		return NULL;
 	}
 
-	number = strtoul(xyz[X]+len, &p, cluster_base);
+	number = xstrntol(xyz[X]+len, &p, cluster_dims, cluster_base);
 	hostlist_parse_int_to_array(number, coord, cluster_dims, cluster_base);
 
 	if(!bp_map_list) {
diff --git a/src/plugins/select/bluegene/plugin/bg_record_functions.c b/src/plugins/select/bluegene/plugin/bg_record_functions.c
index f35c6a1e415..ec3075c3a36 100644
--- a/src/plugins/select/bluegene/plugin/bg_record_functions.c
+++ b/src/plugins/select/bluegene/plugin/bg_record_functions.c
@@ -202,14 +202,16 @@ extern void process_nodes(bg_record_t *bg_record, bool startup)
 			    && (bg_record->nodes[j+4] == 'x'
 				|| bg_record->nodes[j+4] == '-')) {
 				j++;
-				number = strtoul(bg_record->nodes + j,
-						 &p, HOSTLIST_BASE);
+				number = xstrntol(bg_record->nodes + j, &p,
+						  SYSTEM_DIMENSIONS,
+						  HOSTLIST_BASE);
 				hostlist_parse_int_to_array(
 					number, start, SYSTEM_DIMENSIONS,
 					HOSTLIST_BASE);
 				j += 4;
-				number = strtoul(bg_record->nodes + j,
-						 &p, HOSTLIST_BASE);
+				number = xstrntol(bg_record->nodes + j, &p,
+						  SYSTEM_DIMENSIONS,
+						  HOSTLIST_BASE);
 				hostlist_parse_int_to_array(
 					number, end, SYSTEM_DIMENSIONS,
 					HOSTLIST_BASE);
@@ -238,8 +240,9 @@ extern void process_nodes(bg_record_t *bg_record, bool startup)
 				  || (bg_record->nodes[j] >= 'A'
 				      && bg_record->nodes[j] <= 'Z')) {
 
-				number = strtoul(bg_record->nodes + j,
-						 &p, HOSTLIST_BASE);
+				number = xstrntol(bg_record->nodes + j, &p,
+						  SYSTEM_DIMENSIONS,
+						  HOSTLIST_BASE);
 				hostlist_parse_int_to_array(
 					number, start, SYSTEM_DIMENSIONS,
 					HOSTLIST_BASE);
diff --git a/src/smap/configure_functions.c b/src/smap/configure_functions.c
index 409693b7bce..4e207ad2611 100644
--- a/src/smap/configure_functions.c
+++ b/src/smap/configure_functions.c
@@ -714,7 +714,8 @@ static int _change_state_bps(char *com, int state)
 			goto error_message2;
 
 		}
-		number = strtoul(com + i, &p, params.cluster_base);
+		number = xstrntol(com + i, &p, params.cluster_dims,
+				  params.cluster_base);
 		hostlist_parse_int_to_array(
 			number, start, params.cluster_dims,
 			params.cluster_base);
@@ -727,7 +728,8 @@ static int _change_state_bps(char *com, int state)
 				continue;
 			goto error_message2;
 		}
-		number = strtoul(com + i, &p,  params.cluster_base);
+		number = xstrntol(com + i, &p, params.cluster_dims,
+				  params.cluster_base);
 		hostlist_parse_int_to_array(
 			number, end, params.cluster_dims,
 			params.cluster_base);
@@ -739,7 +741,8 @@ static int _change_state_bps(char *com, int state)
 				continue;
 			goto error_message2;
 		}
-		number = strtoul(com + i, &p,  params.cluster_base);
+		number = xstrntol(com + i, &p, params.cluster_dims,
+				  params.cluster_base);
 		hostlist_parse_int_to_array(
 			number, start, params.cluster_dims,
 			params.cluster_base);
@@ -1170,12 +1173,14 @@ static int _add_bg_record(blockreq_t *blockreq, List allocated_blocks)
 		    && (nodes[j+8] == ']' || nodes[j+8] == ',')
 		    && (nodes[j+4] == 'x' || nodes[j+4] == '-')) {
 			j++;
-			number = strtoul(nodes + j, &p, params.cluster_base);
+			number = xstrntol(nodes + j, &p, params.cluster_dims,
+					  params.cluster_base);
 			hostlist_parse_int_to_array(
 				number, start, params.cluster_dims,
 				params.cluster_base);
 			j += 4;
-			number = strtoul(nodes + j, &p, params.cluster_base);
+			number = xstrntol(nodes + j, &p, params.cluster_dims,
+					  params.cluster_base);
 			hostlist_parse_int_to_array(
 				number, end, params.cluster_dims,
 				params.cluster_base);
@@ -1208,7 +1213,8 @@ static int _add_bg_record(blockreq_t *blockreq, List allocated_blocks)
 			j--;
 		} else if((nodes[j] >= '0' && nodes[j] <= '9')
 			  || (nodes[j] >= 'A' && nodes[j] <= 'Z')) {
-			number = strtoul(nodes + j, &p, params.cluster_base);
+			number = xstrntol(nodes + j, &p, params.cluster_dims,
+					  params.cluster_base);
 			hostlist_parse_int_to_array(
 				number, start, params.cluster_dims,
 				params.cluster_base);
diff --git a/src/smap/partition_functions.c b/src/smap/partition_functions.c
index 0ff569b3147..18b9355f1a4 100644
--- a/src/smap/partition_functions.c
+++ b/src/smap/partition_functions.c
@@ -953,12 +953,14 @@ static int _make_nodelist(char *nodes, List nodelist)
 		    && (nodes[j+4] == 'x'
 			|| nodes[j+4] == '-')) {
 			j++;
-			number = strtoul(nodes + j, &p, params.cluster_base);
+			number = xstrntol(nodes + j, &p, params.cluster_dims,
+					  params.cluster_base);
 			hostlist_parse_int_to_array(
 				number, start, params.cluster_dims,
 				params.cluster_base);
 			j += 4;
-			number = strtoul(nodes + j, &p, params.cluster_base);
+			number = xstrntol(nodes + j, &p, params.cluster_dims,
+					  params.cluster_base);
 			hostlist_parse_int_to_array(
 				number, end, params.cluster_dims,
 				params.cluster_base);
@@ -970,7 +972,8 @@ static int _make_nodelist(char *nodes, List nodelist)
 		} else if((nodes[j] >= '0' && nodes[j] <= '9')
 			  || (nodes[j] >= 'A' && nodes[j] <= 'Z')) {
 
-			number = strtoul(nodes + j, &p, params.cluster_base);
+			number = xstrntol(nodes + j, &p, params.cluster_dims,
+					  params.cluster_base);
 			hostlist_parse_int_to_array(
 				number, start, params.cluster_dims,
 				params.cluster_base);
-- 
GitLab