From 7aa2c6f32fbed65cb0fd91094d6eb9fe6fcab160 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 23 Apr 2021 21:11:23 -0700 Subject: [PATCH] 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. --- lib/sparse/DotIO.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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)); } -- 2.50.1