Re: [libvirt] [PATCH] fix errors in virReportSystemErrorFull

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 27, 2009 at 11:28:32AM +0100, Jim Meyering wrote:
> "Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
> ...
> > Looking at the whole method again, I think it needs to be re-written to
> > something closer to this:
> 
> Ok, I've adapted that.
> +void virReportSystemErrorFull(virConnectPtr conn,
> +                              int domcode,
> +                              int theerrno,
> +                              const char *filename ATTRIBUTE_UNUSED,
> +                              const char *funcname ATTRIBUTE_UNUSED,
> +                              size_t linenr ATTRIBUTE_UNUSED,
> +                              const char *fmt, ...)
> +{
> +    char strerror_buf[1024];
> +    char msgDetailBuf[1024];
> +
> +    const char *errnoDetail = virStrerror(theerrno, strerror_buf,
> +                                          sizeof(strerror_buf));
> +    const char *msg = virErrorMsg(VIR_ERR_SYSTEM_ERROR, fmt);
> +    const char *msgDetail = NULL;
> 
>      if (fmt) {
> +        va_list args;
> +        int n;
> +
>          va_start(args, fmt);
> -        vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args);
> +        n = vsnprintf(msgDetailBuf, sizeof(msgDetailBuf), fmt, args);
>          va_end(args);
> -    } else {
> -        errorMessage[0] = '\0';
> +
> +        size_t len = strlen (msgDetailBuf);
> +        if (0 <= n && n + 2 + len < sizeof (msgDetailBuf)) {
> +          char *p = msgDetailBuf + n;
> +          stpcpy (stpcpy (p, ": "), errnoDetail);
> +          msgDetail = msgDetailBuf;
> +        }
>      }
> 
> -    if (virAsprintf(&combined, "%s: %s", errorMessage, theerrnostr) < 0)
> -        combined = theerrnostr; /* OOM, so lets just pass the strerror info as best effort */
> +    if (!msgDetailBuf)
> +        msgDetail = errnoDetail;

This should be   if (!msgDetail) - indeed just noticed the compiler
warns on this

cc1: warnings being treated as errors
virterror.c: In function 'virReportSystemErrorFull':
virterror.c:1062: error: the address of 'msgDetailBuf' will always evaluate as 'true'

Dainel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]