[patch] ftpd: no pid_t to long cast

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch] ftpd: no pid_t to long cast

Fritjof Bornebusch
Is it really necessary to cast pid_t values to long, only
for printing?

--f.


Index: ftpd.c
===================================================================
RCS file: /cvs/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.213
diff -u -r1.213 ftpd.c
--- ftpd.c 16 Mar 2016 15:41:10 -0000 1.213
+++ ftpd.c 2 Apr 2016 15:27:45 -0000
@@ -517,7 +517,7 @@
  }
 
  /* set this here so klogin can use it... */
- (void)snprintf(ttyline, sizeof(ttyline), "ftp%ld", (long)getpid());
+ (void)snprintf(ttyline, sizeof(ttyline), "ftp%d", getpid());
 
  set_slave_signals();
 
Index: monitor.c
===================================================================
RCS file: /cvs/src/libexec/ftpd/monitor.c,v
retrieving revision 1.23
diff -u -r1.23 monitor.c
--- monitor.c 16 Nov 2015 17:31:14 -0000 1.23
+++ monitor.c 2 Apr 2016 15:27:45 -0000
@@ -216,8 +216,8 @@
  if (slave_pid == -1)
  fatalx("fork of user-privileged slave failed");
 
- snprintf(ttyline, sizeof(ttyline), "ftp%ld",
-    slave_pid == 0 ? (long)getpid() : (long)slave_pid);
+ snprintf(ttyline, sizeof(ttyline), "ftp%d",
+    slave_pid == 0 ? getpid() : slave_pid);
 
  if (slave_pid == 0) {
  /* User privileged slave */

Reply | Threaded
Open this post in threaded view
|

Re: [patch] ftpd: no pid_t to long cast

Otto Moerbeek
On Sat, Apr 02, 2016 at 05:32:02PM +0200, [hidden email] wrote:

> Is it really necessary to cast pid_t values to long, only
> for printing?

yes, pid_t may be long, as defined by posix,

        -Otto

>
> --f.
>
>
> Index: ftpd.c
> ===================================================================
> RCS file: /cvs/src/libexec/ftpd/ftpd.c,v
> retrieving revision 1.213
> diff -u -r1.213 ftpd.c
> --- ftpd.c 16 Mar 2016 15:41:10 -0000 1.213
> +++ ftpd.c 2 Apr 2016 15:27:45 -0000
> @@ -517,7 +517,7 @@
>   }
>  
>   /* set this here so klogin can use it... */
> - (void)snprintf(ttyline, sizeof(ttyline), "ftp%ld", (long)getpid());
> + (void)snprintf(ttyline, sizeof(ttyline), "ftp%d", getpid());
>  
>   set_slave_signals();
>  
> Index: monitor.c
> ===================================================================
> RCS file: /cvs/src/libexec/ftpd/monitor.c,v
> retrieving revision 1.23
> diff -u -r1.23 monitor.c
> --- monitor.c 16 Nov 2015 17:31:14 -0000 1.23
> +++ monitor.c 2 Apr 2016 15:27:45 -0000
> @@ -216,8 +216,8 @@
>   if (slave_pid == -1)
>   fatalx("fork of user-privileged slave failed");
>  
> - snprintf(ttyline, sizeof(ttyline), "ftp%ld",
> -    slave_pid == 0 ? (long)getpid() : (long)slave_pid);
> + snprintf(ttyline, sizeof(ttyline), "ftp%d",
> +    slave_pid == 0 ? getpid() : slave_pid);
>  
>   if (slave_pid == 0) {
>   /* User privileged slave */