Skip to content

Commit 04690b3

Browse files
committed
miscgtk: don't implement strdup
1 parent 35a5f93 commit 04690b3

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

src/hal/utils/miscgtk.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,12 @@ void gtk_label_size_to_fit(GtkLabel * label, const gchar * str)
164164

165165
/* get a pointer to the current text */
166166
current_text = gtk_label_get_text(label);
167-
/* how long is it */
168-
text_len = strlen(current_text);
169-
/* allocate memory to save it */
170-
text_buf = malloc(text_len + 2);
167+
/* make a temporary copy */
168+
text_buf = strdup(current_text);
171169
if (text_buf == NULL) {
172-
printf("gtk_label_size_to_fit() - malloc failed\n");
170+
printf("gtk_label_size_to_fit() - strdup failed\n");
173171
return;
174172
}
175-
/* save the text */
176-
strncpy(text_buf, current_text, text_len + 1);
177173
/* set the label to display the new text */
178174
gtk_label_set_text(label, str);
179175
/* how big is the label with the new text? */

0 commit comments

Comments
 (0)