소스 검색

tests/main/starpu_init.c: use a dynamically allocated string to give to putenv

  putenv manual page says "The string pointed to by string becomes part of
  the environment, so altering the string changes the environment." It is
  therefore safer to use a dynamic string rather than a static one.
Nathalie Furmento 12 년 전
부모
커밋
05fc5e563e
1개의 변경된 파일3개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      tests/main/starpu_init.c

+ 3 - 1
tests/main/starpu_init.c

@@ -30,12 +30,13 @@ int main(int argc, char **argv)
 static int check_cpu(int env_cpu, int conf_cpu, int expected_cpu, int *cpu)
 {
 	int ret;
+	char *string;
 
 	FPRINTF(stderr, "Testing with env=%d - conf=%d\n", env_cpu, conf_cpu);
 
 	if (env_cpu != -1)
 	{
-		char string[50];
+		string = malloc(50);
 		sprintf(string, "STARPU_NCPUS=%d", env_cpu);
 		putenv(string);
 	}
@@ -57,6 +58,7 @@ static int check_cpu(int env_cpu, int conf_cpu, int expected_cpu, int *cpu)
 	if (env_cpu != -1)
 	{
 		unsetenv("STARPU_NCPUS");
+		free(string);
 	}
 
 	if (expected_cpu == -1)