]> granicus.if.org Git - graphviz/commitdiff
remove an unnecessary intermediate buffer
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 6 Mar 2021 23:05:41 +0000 (15:05 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 16 Mar 2021 03:48:27 +0000 (20:48 -0700)
lib/sparse/DotIO.c

index b0c706ef5a8986a2e632aadb9736a8f1191b8a46..ee73fc1242725fa280a3635e4e46607fc02992ea 100644 (file)
@@ -604,17 +604,9 @@ char *cat_string(char *s1, char *s2){
 }
 
 static char *cat_string3(char *s1, char *s2, char *s3, int id){
-  char *s;
-  char sid[1000];
-  sprintf(sid,"%d",id);
-  s = malloc(sizeof(char)*(strlen(s1)+strlen(s2)+strlen(s3)+strlen(sid)+1+3));
-  strcpy(s,s1);
-  strcat(s,"|");
-  strcat(s,s2);
-  strcat(s,"|");
-  strcat(s,s3);
-  strcat(s,"|");
-  strcat(s,sid);
+  size_t len = (size_t)snprintf(NULL, 0, "%s|%s|%s|%d", s1, s2, s3, id) + 1;
+  char *s = malloc(sizeof(char) * len);
+  snprintf(s, len, "%s|%s|%s|%d", s1, s2, s3, id);
   return s;
 }