Skip to content

Commit

Permalink
all: fix warning about unused return value in g_string_free (.., FALSE)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Mar 10, 2023
1 parent 423a8ee commit 7daa5e8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 45 deletions.
6 changes: 1 addition & 5 deletions src/arvdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ arv_debug_dup_infos_as_string (void)
GEnumClass *debug_level_class = g_type_class_ref (ARV_TYPE_DEBUG_LEVEL);
GString *string = g_string_new ("");
unsigned int i;
char *str;

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

g_type_class_unref (debug_level_class);

str = string->str;
g_string_free (string, FALSE);

return str;
return arv_g_string_free_and_steal(string);
}

void
Expand Down
5 changes: 2 additions & 3 deletions src/arvgcpropertynode.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <arvgcstring.h>
#include <arvgc.h>
#include <arvdomtext.h>
#include <arvmisc.h>
#include <arvmiscprivate.h>
#include <arvdebugprivate.h>
#include <arvenumtypes.h>
#include <string.h>
Expand Down Expand Up @@ -242,8 +242,7 @@ _get_value_data (ArvGcPropertyNode *property_node)
iter = arv_dom_node_get_next_sibling (iter))
g_string_append (string, arv_dom_character_data_get_data (ARV_DOM_CHARACTER_DATA (iter)));
g_free (priv->value_data);
priv->value_data = string->str;
g_string_free (string, FALSE);
priv->value_data = arv_g_string_free_and_steal(string);
priv->value_data_up_to_date = TRUE;
}

Expand Down
15 changes: 3 additions & 12 deletions src/arvgvcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <arvgvcpprivate.h>
#include <arvgvspprivate.h>
#include <arvmiscprivate.h>
#include <arvenumtypes.h>
#include <arvenumtypesprivate.h>
#include <string.h>
Expand Down Expand Up @@ -487,7 +488,6 @@ char *
arv_gvcp_packet_flags_to_string_new (ArvGvcpCommand command, guint8 flags)
{
GString *string = g_string_new ("");
char *buffer = NULL;
unsigned i;

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

buffer = string->str;

g_string_free (string, FALSE);

return buffer;
return arv_g_string_free_and_steal(string);
}

/**
Expand Down Expand Up @@ -572,7 +568,6 @@ char *
arv_gvcp_packet_to_string (const ArvGvcpPacket *packet)
{
GString *string;
char *c_string;
char *data;
int packet_size;
guint32 value;
Expand Down Expand Up @@ -663,11 +658,7 @@ arv_gvcp_packet_to_string (const ArvGvcpPacket *packet)

arv_g_string_append_hex_dump (string, packet, packet_size);

c_string = string->str;

g_string_free (string, FALSE);

return c_string;
return arv_g_string_free_and_steal(string);
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/arvgvsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

#include <arvdebug.h>
#include <arvmisc.h>
#include <arvmiscprivate.h>
#include <arvenumtypes.h>
#include <arvgvspprivate.h>
#include <arvenumtypesprivate.h>
Expand Down Expand Up @@ -173,7 +173,6 @@ arv_gvsp_packet_to_string (const ArvGvspPacket *packet, size_t packet_size)
guint part_id;
ptrdiff_t offset;
GString *string;
char *c_string;

string = g_string_new ("");

Expand Down Expand Up @@ -275,11 +274,7 @@ arv_gvsp_packet_to_string (const ArvGvspPacket *packet, size_t packet_size)
break;
}

c_string = string->str;

g_string_free (string, FALSE);

return c_string;
return arv_g_string_free_and_steal(string);
}

void
Expand Down
20 changes: 15 additions & 5 deletions src/arvmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ arv_histogram_to_string (const ArvHistogram *histogram)
int i, j, bin_max;
gboolean max_found = FALSE;
GString *string;
char *str;

g_return_val_if_fail (histogram != NULL, NULL);

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

str = string->str;
g_string_free (string, FALSE);

return str;
return arv_g_string_free_and_steal(string);
}

ArvValue *
Expand Down Expand Up @@ -1158,3 +1154,17 @@ arv_regex_new_from_glob_pattern (const char *glob, gboolean caseless)

return regex;
}

char *
arv_g_string_free_and_steal (GString *string)
{
#if GLIB_CHECK_VERSION(2,75,4)
return g_string_free_and_steal(string);
#else
char *buffer = string->str;

g_string_free (string, FALSE);

return buffer;
#endif
}
4 changes: 4 additions & 0 deletions src/arvmiscprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ double arv_value_get_double (ArvValue *value);
gboolean arv_value_holds_int64 (ArvValue *value);
double arv_value_holds_double (ArvValue *value);

/* Compatibility functions */

char * arv_g_string_free_and_steal (GString *string) G_GNUC_WARN_UNUSED_RESULT;

/* private, but used by tests */
ARV_API gboolean arv_parse_genicam_url (const char *url, gssize url_length,
char **scheme, char **authority, char **path,
Expand Down
8 changes: 2 additions & 6 deletions src/arvuvcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @short_description: USB3Vision control packet handling
*/

#include <arvmiscprivate.h>
#include <arvuvcpprivate.h>
#include <arvenumtypesprivate.h>
#include <arvdebug.h>
Expand Down Expand Up @@ -148,7 +149,6 @@ arv_uvcp_packet_to_string (const ArvUvcpPacket *packet)
{
ArvUvcpCommand command;
GString *string;
char *c_string;
int packet_size;
guint64 value;

Expand Down Expand Up @@ -206,11 +206,7 @@ arv_uvcp_packet_to_string (const ArvUvcpPacket *packet)

arv_g_string_append_hex_dump (string, packet, packet_size);

c_string = string->str;

g_string_free (string, FALSE);

return c_string;
return arv_g_string_free_and_steal(string);
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/arvuvsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <arvuvspprivate.h>
#include <arvstr.h>
#include <arvmisc.h>
#include <arvmiscprivate.h>

/*
* SECTION: arvuvsp
Expand All @@ -44,7 +44,6 @@ arv_uvsp_packet_to_string (const ArvUvspPacket *packet)
ArvUvspLeader *leader = (ArvUvspLeader *) packet;
ArvUvspTrailer *trailer = (ArvUvspTrailer *) packet;
GString *string;
char *c_string;

g_return_val_if_fail (packet != NULL, NULL);

Expand Down Expand Up @@ -101,11 +100,7 @@ arv_uvsp_packet_to_string (const ArvUvspPacket *packet)
}
#endif

c_string = string->str;

g_string_free (string, FALSE);

return c_string;
return arv_g_string_free_and_steal(string);
}

/**
Expand Down

0 comments on commit 7daa5e8

Please sign in to comment.