Browse Source

fix warning

Samuel Thibault 6 years ago
parent
commit
79b3da6686
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/util/openmp_runtime_support_environment.c

+ 9 - 3
src/util/openmp_runtime_support_environment.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2014-2017, 2019                          CNRS
  * Copyright (C) 2014,2016                                Inria
- * Copyright (C) 2015-2017                                Université de Bordeaux
+ * Copyright (C) 2015-2017, 2019                          Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -127,17 +127,23 @@ static int read_int_var(const char *str, int *dst)
 {
 	char *endptr;
 	int val;
+	long lval;
 
 	if (!str)
 		return 0;
 
 	errno = 0; /* To distinguish success/failure after call */
-	val = (int)strtol(str, &endptr, 10);
+	lval = strtol(str, &endptr, 10);
 
 	/* Check for various possible errors */
-	if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0))
+	if ((errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) || (errno != 0 && lval == 0))
 		return 0;
 
+	if (lval < INT_MIN || lval > INT_MAX)
+		return 0;
+
+	val = (int) lval;
+
 	/* No digits were found. */
 	if (str == endptr)
 		return 0;