[PATCH] libs/light: fix tv_sec fprintf format

Fabrice Fontaine posted 1 patch 3 years, 3 months ago
Test gitlab-ci failed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20210828090709.738512-1-fontaine.fabrice@gmail.com
tools/libs/light/libxl_domain.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] libs/light: fix tv_sec fprintf format
Posted by Fabrice Fontaine 3 years, 3 months ago
Don't assume tv_sec is a unsigned long, it is 64 bits on NetBSD 32 bits.
Use %jd and cast to (intmax_t) instead

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 tools/libs/light/libxl_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domain.c
index c00c36c928..51a6127552 100644
--- a/tools/libs/light/libxl_domain.c
+++ b/tools/libs/light/libxl_domain.c
@@ -1444,7 +1444,7 @@ static int libxl__mark_domid_recent(libxl__gc *gc, uint32_t domid)
         }
     }
 
-    r = fprintf(nf, "%lu %u\n", ctxt.ts.tv_sec, domid);
+    r = fprintf(nf, "%jd %u\n", (intmax_t)ctxt.ts.tv_sec, domid);
     if (r < 0) {
         LOGED(ERROR, domid, "failed to write to '%s'", new);
         goto out;
-- 
2.32.0


Re: [PATCH] libs/light: fix tv_sec fprintf format
Posted by Juergen Gross 3 years, 3 months ago
On 28.08.21 11:07, Fabrice Fontaine wrote:
> Don't assume tv_sec is a unsigned long, it is 64 bits on NetBSD 32 bits.
> Use %jd and cast to (intmax_t) instead
> 
> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> ---
>   tools/libs/light/libxl_domain.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domain.c
> index c00c36c928..51a6127552 100644
> --- a/tools/libs/light/libxl_domain.c
> +++ b/tools/libs/light/libxl_domain.c
> @@ -1444,7 +1444,7 @@ static int libxl__mark_domid_recent(libxl__gc *gc, uint32_t domid)
>           }
>       }
>   
> -    r = fprintf(nf, "%lu %u\n", ctxt.ts.tv_sec, domid);
> +    r = fprintf(nf, "%jd %u\n", (intmax_t)ctxt.ts.tv_sec, domid);

Any reason not to keep the unsigned attribute?


Juergen
Re: [PATCH] libs/light: fix tv_sec fprintf format
Posted by Fabrice Fontaine 3 years, 3 months ago
Le lun. 30 août 2021 à 10:31, Juergen Gross <jgross@suse.com> a écrit :
>
> On 28.08.21 11:07, Fabrice Fontaine wrote:
> > Don't assume tv_sec is a unsigned long, it is 64 bits on NetBSD 32 bits.
> > Use %jd and cast to (intmax_t) instead
> >
> > Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> > ---
> >   tools/libs/light/libxl_domain.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domain.c
> > index c00c36c928..51a6127552 100644
> > --- a/tools/libs/light/libxl_domain.c
> > +++ b/tools/libs/light/libxl_domain.c
> > @@ -1444,7 +1444,7 @@ static int libxl__mark_domid_recent(libxl__gc *gc, uint32_t domid)
> >           }
> >       }
> >
> > -    r = fprintf(nf, "%lu %u\n", ctxt.ts.tv_sec, domid);
> > +    r = fprintf(nf, "%jd %u\n", (intmax_t)ctxt.ts.tv_sec, domid);
>
> Any reason not to keep the unsigned attribute?
Yes, for consistency, I applied the same fix that was merged seven
months ago to libs/light/libxl_create.c:
https://gitlab.com/xen-project/xen/-/commit/a8ac01aa3e3ea5e6a9a1620aa8fa7e9da3458120
>
>
> Juergen
Fabrice

Re: [PATCH] libs/light: fix tv_sec fprintf format
Posted by Ian Jackson 3 years, 3 months ago
Fabrice Fontaine writes ("Re: [PATCH] libs/light: fix tv_sec fprintf format"):
> Le lun. 30 août 2021 à 10:31, Juergen Gross <jgross@suse.com> a écrit :
> >
> > On 28.08.21 11:07, Fabrice Fontaine wrote:
> > > Don't assume tv_sec is a unsigned long, it is 64 bits on NetBSD 32 bits.
> > > Use %jd and cast to (intmax_t) instead
> > >
> > > Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> > > ---
> > >   tools/libs/light/libxl_domain.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domain.c
> > > index c00c36c928..51a6127552 100644
> > > --- a/tools/libs/light/libxl_domain.c
> > > +++ b/tools/libs/light/libxl_domain.c
> > > @@ -1444,7 +1444,7 @@ static int libxl__mark_domid_recent(libxl__gc *gc, uint32_t domid)
> > >           }
> > >       }
> > >
> > > -    r = fprintf(nf, "%lu %u\n", ctxt.ts.tv_sec, domid);
> > > +    r = fprintf(nf, "%jd %u\n", (intmax_t)ctxt.ts.tv_sec, domid);
> >
> > Any reason not to keep the unsigned attribute?
> Yes, for consistency, I applied the same fix that was merged seven
> months ago to libs/light/libxl_create.c:
> https://gitlab.com/xen-project/xen/-/commit/a8ac01aa3e3ea5e6a9a1620aa8fa7e9da3458120

Thanks,

Reviewed-by: Ian Jackson <iwj@xenproject.org>

and pushed.

Ian.