浏览代码

Fix allocation, clean code a bit

Samuel Thibault 10 年之前
父节点
当前提交
b0a03415e9
共有 1 个文件被更改,包括 4 次插入5 次删除
  1. 4 5
      tests/loader.c

+ 4 - 5
tests/loader.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010  Université de Bordeaux 1
+ * Copyright (C) 2010, 2014  Université de Bordeaux 1
  *
  * 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
@@ -136,14 +136,13 @@ static int _decode(char **src, char *motif, const char *value)
 	found = strstr(*src, motif);
 	if (found == NULL) return 0;
 
-	char *new_src = malloc((strlen(*src)+strlen(value))*sizeof(char));
-	strcpy(new_src, "");
+	char *new_src = malloc(strlen(*src)-strlen(motif)+strlen(value)+1);
 
-	strncat(new_src, *src, strlen(*src)-strlen(found));
+	strncpy(new_src, *src, found - *src);
 	strcat(new_src, value);
 	strcat(new_src, found+strlen(motif));
 
-	*src = strdup(new_src);
+	*src = new_src;
 	return 1;
 }