[PATCH v9] tests/fcntl.c: add test for print_f_owner_ex

Dmitry V. Levin ldv at altlinux.org
Wed May 2 11:20:25 UTC 2018


On Wed, May 02, 2018 at 06:43:41PM +0800, Zhibin Li wrote:
> On Wed, May 2, 2018 at 6:39 PM, Zhibin Li <08826794brmt at gmail.com> wrote:
[...]
> > +static long
> > +test_f_owner_ex_type_pid(const int cmd, const char *const cmd_name,
> > +                        const int type, const char *const type_name,
> > +                        pid_t pid)
> > +{
> > +       TAIL_ALLOC_OBJECT_CONST_PTR(struct f_owner_ex, fo);
> > +
> > +       fo->type = type;
> > +       fo->pid = pid;
> > +       long rc = invoke_test_syscall(cmd, fo);
> > +       printf("%s(0, %s, {type=%s, pid=%d}) = %s\n",
> > +              TEST_SYSCALL_STR, cmd_name, type_name, fo->pid,
> > sprintrc(rc));
> > +
> > +       void *bad_addr = (void *)(uintptr_t)fo + 1;
> >
> Here should I use (void *)((uintptr_t)fo + 1) instead? It causes no
> difference in this case
> but should I emphasize fo+1 by using seemingly useless brackets?

You should use either
(void *) fo + 1
or
(void *) ((uintptr_t) fo + 1)

People say that void* arithmetics is less portable, but we use it in
strace anyway, so I would choose the 1st variant rather than the 2nd.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180502/6023f2ab/attachment.bin>


More information about the Strace-devel mailing list