[PATCH weston] logind-util: Use %u for unsigned int in snprintf

Bryce Harrington bryce at osg.samsung.com
Fri Jul 17 14:35:22 PDT 2015


On Fri, Jul 17, 2015 at 03:06:44PM +0300, Pekka Paalanen wrote:
> On Wed, 1 Jul 2015 12:29:00 +0200
> Marek Chalupa <mchqwerty at gmail.com> wrote:
> 
> > sizeof operator returns size_t, which need not to be unsigned int, but can
> > be long (long) unsigned int.
> > So here the correct fix should be either to use %zu (since C99) or cast it
> > to unsigned long and use %lu
> 
>  < SardemFF7> Why has sizeof() anything do to with your patch? "vtnr"
>  is an "unsigned int" and is not a size_t or anything O_o
> 
> ;-)

Yeah looking at it again, I think my original patch was correct.  The
variable is always only an unsigned int, and sizeof's type isn't a
factor.
 
> Thanks,
> pq
> 
> > On Sat, Jun 20, 2015 at 1:28 AM, Bryce Harrington <bryce at osg.samsung.com>
> > wrote:
> > 
> > > Addresses this warning found by Denis Denisov:
> > >
> > >   [src/logind-util.c:702]: (warning) %d in format string (no. 1)
> > >   requires 'int' but the argument type is 'unsigned int'.
> > >
> > > Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> > > ---
> > >  src/logind-util.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/src/logind-util.c b/src/logind-util.c
> > > index 5c95874..006a1ae 100644
> > > --- a/src/logind-util.c
> > > +++ b/src/logind-util.c
> > > @@ -702,7 +702,7 @@ weston_logind_setup_vt(struct weston_logind *wl)
> > >         sigset_t mask;
> > >         struct wl_event_loop *loop;
> > >
> > > -       snprintf(buf, sizeof(buf), "/dev/tty%d", wl->vtnr);
> > > +       snprintf(buf, sizeof(buf), "/dev/tty%u", wl->vtnr);
> > >         buf[sizeof(buf) - 1] = 0;
> > >
> > >         wl->vt = open(buf, O_RDWR|O_CLOEXEC|O_NONBLOCK);
> > > --
> > > 1.9.1
> > >
> > > _______________________________________________
> > > wayland-devel mailing list
> > > wayland-devel at lists.freedesktop.org
> > > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> > >


More information about the wayland-devel mailing list