This is the mail archive of the cygwin-patches mailing list for the Cygwin 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] gethostbyname2 again


----- Original Message ----- 
From: "Christopher Faylor" <cgf-use-the-mailinglist-please>
To: <cygwin-patches>
Sent: Friday, March 06, 2009 12:44 AM
Subject: Re: [Patch] gethostbyname2 again


| On Tue, Mar 03, 2009 at 12:50:21PM -0500, Pierre A. Humblet wrote:
| >
| >To avoid real-time checks, I could do as what dup_ent does, and have 4 versions
| >of the realloc_ent function, one main one with dst and sz arguments (that one
| >would be called by dup_ent without any  run-time checks) and 3 (actually only
| >1 is needed for now) that invoke the main one with the correct dst based on the
| >type of the src argument . The src argument would be null but would have the
| >right type! That seems to meet your wishes. OK?
| 
| Yes.

OK, here it the patch for realloc_ent. See also attachement.
The third chunk (the change to dup_ent) is not essential.

In addition in the patch that Corinna sent on March 3, the line
+  ret = (hostent *) realloc_ent (sz, unionent::t_hostent);
should be changed to
ret = realloc_ent (sz,  (hostent *) NULL);

In the Changelog the line
  (dup_ent): Remove dst argument and call realloc_ent.
should either be deleted or "Remove dst argument and c" should
be replaced by "C".

Pierre

Index: net.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/net.cc,v
retrieving revision 1.249
diff -u -p -r1.249 net.cc
--- net.cc 3 Mar 2009 11:44:17 -0000 1.249
+++ net.cc 6 Mar 2009 14:28:46 -0000
@@ -264,6 +264,25 @@ struct pservent
 
 static const char *entnames[] = {"host", "proto", "serv"};
 
+static unionent *
+realloc_ent (unionent *&dst, int sz)
+{
+   /* Allocate the storage needed.  Allocate a rounded size to attempt to force
+      reuse of this buffer so that a poorly-written caller will not be using
+      a freed buffer. */
+   unsigned rsz = 256 * ((sz + 255) / 256);
+   unionent * ptr;
+   if ((ptr = (unionent *) realloc (dst, rsz)))
+     dst = ptr;
+   return ptr;
+}
+
+static inline hostent *
+realloc_ent (int sz, hostent * )
+{
+   return (hostent *) realloc_ent (_my_tls.locals.hostent_buf, sz);
+}
+
 /* Generic "dup a {host,proto,serv}ent structure" function.
    This is complicated because we need to be able to free the
    structure at any point and we can't rely on the pointer contents
@@ -355,13 +374,8 @@ dup_ent (unionent *&dst, unionent *src, 
  }
     }
 
-  /* Allocate the storage needed.  Allocate a rounded size to attempt to force
-     reuse of this buffer so that a poorly-written caller will not be using
-     a freed buffer. */
-  unsigned rsz = 256 * ((sz + 255) / 256);
-  dst = (unionent *) realloc (dst, rsz);
-
-  if (dst)
+  /* Allocate the storage needed.  */
+  if (realloc_ent (dst, sz))
     {
       memset (dst, 0, sz);
       /* This field is common to all *ent structures but named differently

Attachment: realloc_ent.diff
Description: Binary data


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