]> granicus.if.org Git - graphviz/commitdiff
remove an unnecessary use of C string functions in SWIG bindings code
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 2 Sep 2021 01:37:14 +0000 (18:37 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 7 Sep 2021 14:11:58 +0000 (07:11 -0700)
tclpkg/gv/gv.cpp

index 9a07d42ae1691e4fb5841cc12be3531fab3a9c6c..4af459ae21397842756fb3afaf960e42907df27c 100644 (file)
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <gvc/gvc.h>
+#include <string>
 
 extern "C" {
 extern void gv_string_writer_init(GVC_t *gvc);
@@ -174,16 +175,11 @@ char *getv(Agraph_t *g, char *attr)
 }
 static void myagxset(void *obj, Agsym_t *a, char *val)
 {
-    int len;
-    char *hs;
-
     if (strcmp(a->name, "label") == 0 && val[0] == '<') {
-        len = strlen(val);
+        size_t len = strlen(val);
         if (val[len-1] == '>') {
-            hs = strdup(val+1);
-                *(hs+len-2) = '\0';
-            val = agstrdup_html(agraphof(obj),hs);
-            free(hs);
+            std::string hs(val + 1, len - 2);
+            val = agstrdup_html(agraphof(obj), hs.c_str());
         }
     }
     agxset(obj, a, val);