Skip to content

Commit 7daa5e8

Browse files
committed
all: fix warning about unused return value in g_string_free (.., FALSE)
1 parent 423a8ee commit 7daa5e8

8 files changed

Lines changed: 31 additions & 45 deletions

File tree

src/arvdebug.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ arv_debug_dup_infos_as_string (void)
264264
GEnumClass *debug_level_class = g_type_class_ref (ARV_TYPE_DEBUG_LEVEL);
265265
GString *string = g_string_new ("");
266266
unsigned int i;
267-
char *str;
268267

269268
g_string_append (string, "Debug categories:\n");
270269
for (i = 0; i < ARV_DEBUG_CATEGORY_N_ELEMENTS; i++) {
@@ -285,10 +284,7 @@ arv_debug_dup_infos_as_string (void)
285284

286285
g_type_class_unref (debug_level_class);
287286

288-
str = string->str;
289-
g_string_free (string, FALSE);
290-
291-
return str;
287+
return arv_g_string_free_and_steal(string);
292288
}
293289

294290
void

src/arvgcpropertynode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <arvgcstring.h>
3737
#include <arvgc.h>
3838
#include <arvdomtext.h>
39-
#include <arvmisc.h>
39+
#include <arvmiscprivate.h>
4040
#include <arvdebugprivate.h>
4141
#include <arvenumtypes.h>
4242
#include <string.h>
@@ -242,8 +242,7 @@ _get_value_data (ArvGcPropertyNode *property_node)
242242
iter = arv_dom_node_get_next_sibling (iter))
243243
g_string_append (string, arv_dom_character_data_get_data (ARV_DOM_CHARACTER_DATA (iter)));
244244
g_free (priv->value_data);
245-
priv->value_data = string->str;
246-
g_string_free (string, FALSE);
245+
priv->value_data = arv_g_string_free_and_steal(string);
247246
priv->value_data_up_to_date = TRUE;
248247
}
249248

src/arvgvcp.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <arvgvcpprivate.h>
2929
#include <arvgvspprivate.h>
30+
#include <arvmiscprivate.h>
3031
#include <arvenumtypes.h>
3132
#include <arvenumtypesprivate.h>
3233
#include <string.h>
@@ -487,7 +488,6 @@ char *
487488
arv_gvcp_packet_flags_to_string_new (ArvGvcpCommand command, guint8 flags)
488489
{
489490
GString *string = g_string_new ("");
490-
char *buffer = NULL;
491491
unsigned i;
492492

493493
for (i = 0; i < 8; i++) {
@@ -518,11 +518,7 @@ arv_gvcp_packet_flags_to_string_new (ArvGvcpCommand command, guint8 flags)
518518
if (string->len == 0)
519519
g_string_append (string, "none");
520520

521-
buffer = string->str;
522-
523-
g_string_free (string, FALSE);
524-
525-
return buffer;
521+
return arv_g_string_free_and_steal(string);
526522
}
527523

528524
/**
@@ -572,7 +568,6 @@ char *
572568
arv_gvcp_packet_to_string (const ArvGvcpPacket *packet)
573569
{
574570
GString *string;
575-
char *c_string;
576571
char *data;
577572
int packet_size;
578573
guint32 value;
@@ -663,11 +658,7 @@ arv_gvcp_packet_to_string (const ArvGvcpPacket *packet)
663658

664659
arv_g_string_append_hex_dump (string, packet, packet_size);
665660

666-
c_string = string->str;
667-
668-
g_string_free (string, FALSE);
669-
670-
return c_string;
661+
return arv_g_string_free_and_steal(string);
671662
}
672663

673664
/**

src/arvgvsp.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727

2828
#include <arvdebug.h>
29-
#include <arvmisc.h>
29+
#include <arvmiscprivate.h>
3030
#include <arvenumtypes.h>
3131
#include <arvgvspprivate.h>
3232
#include <arvenumtypesprivate.h>
@@ -173,7 +173,6 @@ arv_gvsp_packet_to_string (const ArvGvspPacket *packet, size_t packet_size)
173173
guint part_id;
174174
ptrdiff_t offset;
175175
GString *string;
176-
char *c_string;
177176

178177
string = g_string_new ("");
179178

@@ -275,11 +274,7 @@ arv_gvsp_packet_to_string (const ArvGvspPacket *packet, size_t packet_size)
275274
break;
276275
}
277276

278-
c_string = string->str;
279-
280-
g_string_free (string, FALSE);
281-
282-
return c_string;
277+
return arv_g_string_free_and_steal(string);
283278
}
284279

285280
void

src/arvmisc.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ arv_histogram_to_string (const ArvHistogram *histogram)
279279
int i, j, bin_max;
280280
gboolean max_found = FALSE;
281281
GString *string;
282-
char *str;
283282

284283
g_return_val_if_fail (histogram != NULL, NULL);
285284

@@ -369,10 +368,7 @@ arv_histogram_to_string (const ArvHistogram *histogram)
369368
g_string_append_printf (string, ":%12llu", (unsigned long long) histogram->variables[j].counter);
370369
}
371370

372-
str = string->str;
373-
g_string_free (string, FALSE);
374-
375-
return str;
371+
return arv_g_string_free_and_steal(string);
376372
}
377373

378374
ArvValue *
@@ -1158,3 +1154,17 @@ arv_regex_new_from_glob_pattern (const char *glob, gboolean caseless)
11581154

11591155
return regex;
11601156
}
1157+
1158+
char *
1159+
arv_g_string_free_and_steal (GString *string)
1160+
{
1161+
#if GLIB_CHECK_VERSION(2,75,4)
1162+
return g_string_free_and_steal(string);
1163+
#else
1164+
char *buffer = string->str;
1165+
1166+
g_string_free (string, FALSE);
1167+
1168+
return buffer;
1169+
#endif
1170+
}

src/arvmiscprivate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ double arv_value_get_double (ArvValue *value);
6666
gboolean arv_value_holds_int64 (ArvValue *value);
6767
double arv_value_holds_double (ArvValue *value);
6868

69+
/* Compatibility functions */
70+
71+
char * arv_g_string_free_and_steal (GString *string) G_GNUC_WARN_UNUSED_RESULT;
72+
6973
/* private, but used by tests */
7074
ARV_API gboolean arv_parse_genicam_url (const char *url, gssize url_length,
7175
char **scheme, char **authority, char **path,

src/arvuvcp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @short_description: USB3Vision control packet handling
2626
*/
2727

28+
#include <arvmiscprivate.h>
2829
#include <arvuvcpprivate.h>
2930
#include <arvenumtypesprivate.h>
3031
#include <arvdebug.h>
@@ -148,7 +149,6 @@ arv_uvcp_packet_to_string (const ArvUvcpPacket *packet)
148149
{
149150
ArvUvcpCommand command;
150151
GString *string;
151-
char *c_string;
152152
int packet_size;
153153
guint64 value;
154154

@@ -206,11 +206,7 @@ arv_uvcp_packet_to_string (const ArvUvcpPacket *packet)
206206

207207
arv_g_string_append_hex_dump (string, packet, packet_size);
208208

209-
c_string = string->str;
210-
211-
g_string_free (string, FALSE);
212-
213-
return c_string;
209+
return arv_g_string_free_and_steal(string);
214210
}
215211

216212
/**

src/arvuvsp.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include <arvuvspprivate.h>
2424
#include <arvstr.h>
25-
#include <arvmisc.h>
25+
#include <arvmiscprivate.h>
2626

2727
/*
2828
* SECTION: arvuvsp
@@ -44,7 +44,6 @@ arv_uvsp_packet_to_string (const ArvUvspPacket *packet)
4444
ArvUvspLeader *leader = (ArvUvspLeader *) packet;
4545
ArvUvspTrailer *trailer = (ArvUvspTrailer *) packet;
4646
GString *string;
47-
char *c_string;
4847

4948
g_return_val_if_fail (packet != NULL, NULL);
5049

@@ -101,11 +100,7 @@ arv_uvsp_packet_to_string (const ArvUvspPacket *packet)
101100
}
102101
#endif
103102

104-
c_string = string->str;
105-
106-
g_string_free (string, FALSE);
107-
108-
return c_string;
103+
return arv_g_string_free_and_steal(string);
109104
}
110105

111106
/**

0 commit comments

Comments
 (0)