]> granicus.if.org Git - graphviz/commitdiff
abbreviate some manual strdup code
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 24 Apr 2021 04:11:23 +0000 (21:11 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 14 May 2021 00:03:36 +0000 (17:03 -0700)
These locations were doing the exact functionality of strdup, but using manual
malloc. It is more readable to just call the library function for this.

lib/sparse/DotIO.c

index c6f2a92a69ec86d7b039b4f51bbb7d45895c854f..2c1995f4b64b73f53e0bb1f41c15010e1c22affe 100644 (file)
@@ -18,6 +18,7 @@
 #include <sparse/mq.h>
 #include <sparse/color_palette.h>
 #include <sparse/colorutil.h>
+#include <string.h>
 
 typedef struct {
     Agrec_t h;
@@ -318,8 +319,7 @@ int Import_dot_splines(Agraph_t* g, int *ne, char ***xsplines){
       /* edge weight */
       if (sym) {
        char *pos = agxget (e, sym);
-       (*xsplines)[i] = malloc(sizeof(char)*(strlen(pos)+1));
-       strcpy((*xsplines)[i], pos);
+       (*xsplines)[i] = strdup(pos);
       } else {
        (*xsplines)[i] = NULL;
       }
@@ -918,13 +918,10 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim
     }
 
    if (agget(n, "label") && strcmp(agget(n, "label"), "") != 0 && strcmp(agget(n, "label"), "\\N") != 0){
-     char *lbs;
-     lbs = agget(n, "label");
-      (*labels)[i] = MALLOC(sizeof(char)*(strlen(lbs)+1));
-      strcpy((*labels)[i], lbs);
+     char *lbs = agget(n, "label");
+      (*labels)[i] = strdup(lbs);
     } else {
-     (*labels)[i] = MALLOC(sizeof(char)*(strlen(agnameof(n))+1));
-      strcpy((*labels)[i], agnameof(n));
+     (*labels)[i] = strdup(agnameof(n));
     }