You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jim Jagielski <ji...@jaguNET.com> on 1998/03/18 00:39:19 UTC
Re: cvs commit: apache-1.3/src/main http_main.c
marc@hyperreal.org wrote:
>
> marc 98/03/17 15:24:16
>
> Modified: src/main http_main.c
> Log:
> Fix warning on Solaris. Using a long format should be safer for
> everything. I think.
>
> char buf[20];
>
> - ap_snprintf(buf, sizeof(buf), ".%u", getpid());
> + ap_snprintf(buf, sizeof(buf), ".%lu", getpid());
> lock_fname = pstrcat(p, server_root_relative(p, lock_fname), buf, NULL);
> }
Wouldn't it make even more sense to cast it?
ap_snprintf(buf, sizeof(buf), ".%lu", (unsigned long)getpid());
--
===========================================================================
Jim Jagielski ||| jim@jaguNET.com ||| http://www.jaguNET.com/
"That's no ordinary rabbit... that's the most foul,
cruel and bad-tempered rodent you ever laid eyes on"
Re: cvs commit: apache-1.3/src/main http_main.c
Posted by Marc Slemko <ma...@worldgate.com>.
On Tue, 17 Mar 1998, Ben Laurie wrote:
> Jim Jagielski wrote:
> >
> > marc@hyperreal.org wrote:
> > >
> > > marc 98/03/17 15:24:16
> > >
> > > Modified: src/main http_main.c
> > > Log:
> > > Fix warning on Solaris. Using a long format should be safer for
> > > everything. I think.
> > >
> > > char buf[20];
> > >
> > > - ap_snprintf(buf, sizeof(buf), ".%u", getpid());
> > > + ap_snprintf(buf, sizeof(buf), ".%lu", getpid());
> > > lock_fname = pstrcat(p, server_root_relative(p, lock_fname), buf, NULL);
> > > }
> >
> > Wouldn't it make even more sense to cast it?
> >
> > ap_snprintf(buf, sizeof(buf), ".%lu", (unsigned long)getpid());
>
> Whilst I think it unlikely that we'll ever run on DOS (16) the latter
> would work there and the former wouldn't :-)
Grumble.
But what if we have 32 bit longs and 64 bit PIDs? Guess that isn't too
likely on most systems; 64 bits for moth would be more likely.
I don't like casting it because that hides loss of data. We could...
erm... make it a function that took an unsigned long, then as long as
getpid's return type was smaller than or equal to a u_long we would be ok,
otherwise we should get a warning. But that is lame.
Re: cvs commit: apache-1.3/src/main http_main.c
Posted by Ben Laurie <be...@algroup.co.uk>.
Jim Jagielski wrote:
>
> marc@hyperreal.org wrote:
> >
> > marc 98/03/17 15:24:16
> >
> > Modified: src/main http_main.c
> > Log:
> > Fix warning on Solaris. Using a long format should be safer for
> > everything. I think.
> >
> > char buf[20];
> >
> > - ap_snprintf(buf, sizeof(buf), ".%u", getpid());
> > + ap_snprintf(buf, sizeof(buf), ".%lu", getpid());
> > lock_fname = pstrcat(p, server_root_relative(p, lock_fname), buf, NULL);
> > }
>
> Wouldn't it make even more sense to cast it?
>
> ap_snprintf(buf, sizeof(buf), ".%lu", (unsigned long)getpid());
Whilst I think it unlikely that we'll ever run on DOS (16) the latter
would work there and the former wouldn't :-)
Cheers,
Ben.
--
Ben Laurie |Phone: +44 (181) 735 0686| Apache Group member
Freelance Consultant |Fax: +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd, |Apache-SSL author http://www.apache-ssl.org/
London, England. |"Apache: TDG" http://www.ora.com/catalog/apache
Re: cvs commit: apache-1.3/src/main http_main.c
Posted by Dean Gaudet <dg...@arctic.org>.
Casts hide bugs.
The best way to solve this is:
#define PRINTF_A_PID_T "%lu"
or some othersuch similar thing. The "bug" is that the printf argument
doesn't adapt to the pid_t type.
Dean
On Tue, 17 Mar 1998, Jim Jagielski wrote:
> marc@hyperreal.org wrote:
> >
> > marc 98/03/17 15:24:16
> >
> > Modified: src/main http_main.c
> > Log:
> > Fix warning on Solaris. Using a long format should be safer for
> > everything. I think.
> >
> > char buf[20];
> >
> > - ap_snprintf(buf, sizeof(buf), ".%u", getpid());
> > + ap_snprintf(buf, sizeof(buf), ".%lu", getpid());
> > lock_fname = pstrcat(p, server_root_relative(p, lock_fname), buf, NULL);
> > }
>
>
> Wouldn't it make even more sense to cast it?
>
> ap_snprintf(buf, sizeof(buf), ".%lu", (unsigned long)getpid());
>
> --
> ===========================================================================
> Jim Jagielski ||| jim@jaguNET.com ||| http://www.jaguNET.com/
> "That's no ordinary rabbit... that's the most foul,
> cruel and bad-tempered rodent you ever laid eyes on"
>