[libvirt] [PATCH v2] glibcompat: Reimplement g_strdup_printf() and g_strdup_vprintf()

Ján Tomko jtomko at redhat.com
Fri Oct 18 10:21:42 UTC 2019


On Fri, Oct 18, 2019 at 12:16:00PM +0200, Peter Krempa wrote:
>On Fri, Oct 18, 2019 at 11:49:05 +0200, Michal Privoznik wrote:
>> These functions don't really abort() on OOM. The fix was merged
>> upstream, but not in the minimal version we require. Provide our
>> own implementation which can be removed once we bump the minimal
>> version.
>>
>> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>> ---
>>
>> v2 of:
>>
>> https://www.redhat.com/archives/libvir-list/2019-October/msg01153.html
>>
>> diff to v1:
>> - moved the code to src/utils/glibcompat.c
>>
>>  src/internal.h           |  1 +
>>  src/libvirt_private.syms |  5 +++++
>>  src/util/Makefile.inc.am |  2 ++
>>  src/util/glibcompat.c    | 48 ++++++++++++++++++++++++++++++++++++++++
>>  src/util/glibcompat.h    | 31 ++++++++++++++++++++++++++
>>  5 files changed, 87 insertions(+)
>>  create mode 100644 src/util/glibcompat.c
>>  create mode 100644 src/util/glibcompat.h
>>

>> +/* Due to a bug in glib, g_strdup_printf() nor g_strdup_vprintf()
>> + * abort on OOM.  It's fixed in glib's upstream. Provide our own
>> + * implementation until the fix get's distributed. */
>> +char *
>> +vir_g_strdup_printf(const char *msg, ...)
>> +{
>> +  va_list args;
>> +  char *ret;
>> +  va_start(args, msg);
>> +  ret = g_strdup_vprintf(msg, args);
>> +  if (!ret)
>> +    abort();
>> +  va_end(args);
>> +  return ret;
>> +}
>> +
>> +
>> +char *
>> +vir_g_strdup_vprintf(const char *msg, va_list args)
>> +{
>> +  char *ret;
>> +  ret = g_strdup_vprintf(msg, args);
>
>So this will become vir_g_strdup_vprintf.. thus become infinite
>recursion.
>

No problem, we can just turn off the warning:
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 7c86fdd3c6..e531eadc1e 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -127,6 +127,9 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     dontwarn="$dontwarn -Woverlength-strings"
     dontwarn="$dontwarn -Wstack-protector"
 
+    # Needed for our g_strdup_vprintf workaround
+    dontwarn="$dontwarn -Winfinite-recursion"
+
     # Get all possible GCC warnings
     gl_MANYWARN_ALL_GCC([maybewarn])
 

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20191018/9957b7bd/attachment-0001.sig>


More information about the libvir-list mailing list