Re: question about virConnectGetAllDomainStats and virTypedParameter

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

 




10 июня 2015 г. 17:15 пользователь "Michal Privoznik" <mprivozn@xxxxxxxxxx> написал:
>
> On 10.06.2015 08:52, Vasiliy Tolstov wrote:
> > I'm try to implement virConnectGetAllDomainStats for php binding api,
> > but have one issue with VIR_TYPED_PARAM_STRING:
> >
> > code part:
> >         retval = virConnectGetAllDomainStats(conn->conn, stats,
> > &retstats, flags);
> >         for (i=0; i < retval; i++) {
> >                 zval *arr2;
> >                 ALLOC_INIT_ZVAL(arr2);
> >                 array_init(arr2);
> >                 for (j = 0; j < retstats[i]->nparams; j++) {
> >                         params = retstats[i]->params[j];
> >                         switch (params.type) {
> >                         case VIR_TYPED_PARAM_INT:
> >                                 add_assoc_long(arr2, params.field,
> > params.value.i);
> >                         case VIR_TYPED_PARAM_UINT:
> >                                 add_assoc_long(arr2, params.field,
> > params.value.ui);
> >                         case VIR_TYPED_PARAM_LLONG:
> >                                 add_assoc_long(arr2, params.field,
> > params.value.l);
> >                         case VIR_TYPED_PARAM_ULLONG:
> >                                 add_assoc_long(arr2, params.field,
> > params.value.ul);
> >                         case VIR_TYPED_PARAM_DOUBLE:
> >                                 add_assoc_double(arr2, params.field,
> > params.value.d);
> >                         case VIR_TYPED_PARAM_BOOLEAN:
> >                                 add_assoc_bool(arr2, params.field,
> > params.value.b);
> >                         case VIR_TYPED_PARAM_STRING:
> >                                 add_assoc_string_ex(arr2,
> > params.field, strlen(params.field)+1, strdup(params.value.s),
> > strlen(params.value.s)+1); // SEGFAULT HAPPENING
> >                         }
> >                 }
> >
> > gdb shows:
> >     return_value_used=<optimized out>) at libvirt-php.c:2505
> >         arr2 = 0x7ffff7fd72b8
> >         conn = <optimized out>
> >         zconn = 0x7ffff7fd7140
> >         retval = <optimized out>
> >         flags = <optimized out>
> >         stats = <optimized out>
> >         name = <optimized out>
> >         i = <optimized out>
> >         j = <optimized out>
> >         params = {field = "state.state", '\000' <repeats 68 times>,
> > type = 1, value = {i = 5, ui = 5, l = 5, ul = 5, d =
> > 2.4703282292062327e-323, b = 5 '\005',
> >             s = 0x5 <Address 0x5 out of bounds>}}
> >         retstats = 0x101d870
> >
> > What i'm doing wrong?
> >
>
> The switch() items needs to end with break; Otherwise add_assoc_*() will
> be called that not correspond to the type. As in your example - the type
> is INT, and you are seeing the error in strdup().
>
> Unfortunately, my mind was too slow when reviewing your patch, so I've
> pushed it without spotting it. I'm pushing the obvious fix right now.
>
> Michal

Thanks, after golang I'm forget about breaks in switches.

--
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]