bug-gnulib
[Top][All Lists]
Advanced

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

Re: scratch_buffer and 'void *' pointer arithmetic


From: Bruno Haible
Subject: Re: scratch_buffer and 'void *' pointer arithmetic
Date: Sat, 16 Dec 2017 04:12:18 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-101-generic; KDE/5.18.0; x86_64; ; )

Paul Eggert wrote:
> On 12/13/2017 01:38 AM, Tim Rühsen wrote:
> > Here is a patch to silence this warning:
> >
> > glob.c: In function 'rpl_glob':
> > glob.c:618:64: warning: pointer of type 'void *' used in arithmetic
> > [-Wpointer-arith]
> >                         err = getpwnam_r (s.data, &pwbuf, s.data + ssize,
> >
> >
> > With Best Regards, Tim
> >
> Thanks, I tweaked it slightly to avoid inserting a cast (as it's better 
> to avoid casts when it's easy), and installed the attached patch into 
> Gnulib, in your name.

... and I've added the ChangeLog entry for it.

But, when we look at the definition

struct scratch_buffer {
  void *data;    /* Pointer to the beginning of the scratch area.  */
  size_t length; /* Allocated space at the data pointer, in bytes.  */
  ...
};

it seems quite natural to do pointer arithmetic on 'data'. Namely, this will
happen each time a scratch_buffer gets booked by several (not just one)
pieces of memory.

Therefore I would suggest to change the type of the 'data' field to 'char *'
in gnulib. I know that in glibc this is not needed, because glibc assumes GCC
and GCC supports 'void *' arithmetic as an extension.

Rationale: 'scratch_buffer' is a module of its own right in gnulib, and
may get more uses, in order to avoid stack overflows.

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]