From: Matthew Fernandez Date: Sat, 24 Apr 2021 04:11:23 +0000 (-0700) Subject: abbreviate some manual strdup code X-Git-Tag: 2.47.2~13^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7aa2c6f32fbed65cb0fd91094d6eb9fe6fcab160;p=graphviz abbreviate some manual strdup code 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. --- diff --git a/lib/sparse/DotIO.c b/lib/sparse/DotIO.c index c6f2a92a6..2c1995f4b 100644 --- a/lib/sparse/DotIO.c +++ b/lib/sparse/DotIO.c @@ -18,6 +18,7 @@ #include #include #include +#include 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)); }