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

Re: [libvirt] [PATCH 2/2] virNetServerClientNewPostExecRestart: Avoid align problems



On 05/05/16 09:30, Michal Privoznik wrote:
> I've noticed this while trying to compile libvirt on my arm box.
> 
>   CC       rpc/libvirt_net_rpc_server_la-virnetserverclient.lo
> rpc/virnetserverclient.c: In function 'virNetServerClientNewPostExecRestart':
> rpc/virnetserverclient.c:516:45: error: cast increases required alignment of target type [-Werror=cast-align]
>                                              (long long *) &timestamp) < 0) {
>                                              ^
> cc1: all warnings being treated as errors
> 
> Problem is, @timestap is defined as time_t which is 32 bits long,
> and we are typecasting it to long long which is 64bits long.
> Solution is to make @timestamp type of long long. But that could
> overflow when passing the variable to
> virNetServerClientNewInternal(). Well, we can do this and hope to
> find a better solution for this till 19 January 2038 (yes, time_t
> on my arm box is signed long int).
> 

Hmm, why don't we then represent the timestamp as long long in the first
place, rather than having it as time_t. That way, no overflow as you
mention could happen and the only problem for your machine then would be
to cope with the 32bit timestamp time function returns, which will break
libvirt and anything else anyway, but at least in an expected manner.

Erik

> Signed-off-by: Michal Privoznik <mprivozn redhat com>
> ---
>  src/rpc/virnetserverclient.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
> index d3a3a18..271930f 100644
> --- a/src/rpc/virnetserverclient.c
> +++ b/src/rpc/virnetserverclient.c
> @@ -472,7 +472,7 @@ virNetServerClientPtr virNetServerClientNewPostExecRestart(virJSONValuePtr objec
>      bool readonly;
>      unsigned int nrequests_max;
>      unsigned long long id;
> -    time_t timestamp;
> +    long long timestamp;
>  
>      if (virJSONValueObjectGetNumberInt(object, "auth", &auth) < 0) {
>          virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> @@ -511,8 +511,7 @@ virNetServerClientPtr virNetServerClientNewPostExecRestart(virJSONValuePtr objec
>      if (!virJSONValueObjectHasKey(object, "conn_time")) {
>          timestamp = 0;
>      } else {
> -        if (virJSONValueObjectGetNumberLong(object, "conn_time",
> -                                            (long long *) &timestamp) < 0) {
> +        if (virJSONValueObjectGetNumberLong(object, "conn_time", &timestamp) < 0) {
>              virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
>                             _("Malformed conn_time field in JSON "
>                               "state document"));
> 


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