On Wed, Aug 20, 2025 at 07:57:47AM +1000, Richard Henderson wrote:
> On 8/20/25 06:27, Daniel P. Berrangé wrote:
> > +char *qmessage_context(int flags)
> > +{
> > +    g_autofree char *timestr = NULL;
> > +
> > +    if ((flags & QMESSAGE_CONTEXT_SKIP_MONITOR) &&
> > +        monitor_cur()) {
> > +        return g_strdup("");
> 
> In the event we want no context, we really should avoid memory allocation too.

Yes, won't not be too hard to check for NULL in the caller.

> > +    }
> > +
> > +    if (message_format & QMESSAGE_FORMAT_TIMESTAMP) {
> > +        g_autoptr(GDateTime) dt = g_date_time_new_now_utc();
> > +        timestr = g_date_time_format_iso8601(dt);
> > +    }
> > +
> > +    return g_strdup_printf("%s%s",
> > +                           timestr ? timestr : "",
> > +                           timestr ? " " : "");
> 
> g_strdup_printf isn't the nicest string concatenation tool.

A GString would make it easier. Though typically that would involve
an allocation of GSTring struct, I guess we could be sneaky and stack
allocate the struct.

> And again, there's a no-context path.



With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Reply via email to