]> granicus.if.org Git - graphviz/commitdiff
common emit_edge_label: replace manual buffer allocation with an agxbuf
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 28 Jan 2023 16:42:51 +0000 (08:42 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 30 Jan 2023 15:43:10 +0000 (07:43 -0800)
Gitlab: #1950

lib/common/emit.c

index 99ed362e921e79d55f5962e659eb29b642338683..40dabdacfaa99f1903a8572ab6d899b149d0b32f 100644 (file)
@@ -2676,11 +2676,11 @@ emit_edge_label(GVJ_t* job, textlabel_t* lbl, emit_state_t lkind, int explicit,
     int flags = job->flags;
     emit_state_t old_emit_state;
     char* newid;
+    agxbuf xb = {0};
     char* type;
 
     if (lbl == NULL || !lbl->set) return;
     if (id) { /* non-NULL if needed */
-       newid = N_NEW(strlen(id) + sizeof("-headlabel"),char);
        switch (lkind) {
        case EMIT_ELABEL :
            type = "label";
@@ -2695,7 +2695,8 @@ emit_edge_label(GVJ_t* job, textlabel_t* lbl, emit_state_t lkind, int explicit,
            assert (0);
            break;
        }
-       sprintf (newid, "%s-%s", id, type);
+       agxbprint(&xb, "%s-%s", id, type);
+       newid = agxbuse(&xb);
     }
     else
        newid = NULL;
@@ -2714,7 +2715,7 @@ emit_edge_label(GVJ_t* job, textlabel_t* lbl, emit_state_t lkind, int explicit,
        }
        gvrender_end_anchor(job);
     }
-    free (newid);
+    agxbfree(&xb);
     job->obj->emit_state = old_emit_state;
 }