[libvirt] [PATCH] fix errors in virReportSystemErrorFull
Daniel P. Berrange
berrange at redhat.com
Tue Jan 27 12:20:25 UTC 2009
On Tue, Jan 27, 2009 at 11:28:32AM +0100, Jim Meyering wrote:
> "Daniel P. Berrange" <berrange at redhat.com> 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 :|
More information about the libvir-list
mailing list