This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] readline/util.c: use '%d' instead of 'ld' to avoid compiling warning


On Fri, May 30, 2014 at 08:11:41AM +0800, Chen Gang wrote:
> getpid() will return 'pid_t' which is always 'int', so need use '%d'
> instead of '%ld' in sprintf().

Please do not copy many lists and/or maintainers.  This patch should
have gone just to gdb-patches@sourceware.org, since readline belongs
to the gdb project.

Also, gdb and binutils generally require patches to be supplied with a
ChangeLog entry.  See other posts on the mailing list.

Now, on to the substance of your patch.  It's wrong to claim that
"pid_t" is always "int".  I know of systems that use or used to use
"short".  In fact
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
says

"The implementation shall support one or more programming environments
in which the widths of blksize_t, pid_t, size_t, ssize_t, and
suseconds_t are no greater than the width of type long."

So the correct patch would be to cast the return of getpid() to long,
continuing to use '%ld' in the format string.

> The related warning (cross-compile aarch64):
> 
>   ../../binutils-gdb/readline/util.c: In function â_rl_tropenâ:
>   ../../binutils-gdb/readline/util.c:510:3: warning: format â%ldâ expects argument of type âlong intâ, but argument 3 has type â__pid_tâ [-Wformat]

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]