[Aptitude-svn-commit] r4291 - in branches/aptitude-0.3/aptitude: . src/generic/util

Daniel Burrows dburrows at costa.debian.org
Mon Sep 26 20:04:20 UTC 2005


Author: dburrows
Date: Mon Sep 26 20:04:17 2005
New Revision: 4291

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/util/util.cc
Log:
Fix get_homedir

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Mon Sep 26 20:04:17 2005
@@ -1,5 +1,10 @@
 2005-09-26  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/util/util.cc:
+
+	  Correct get_homedir(): it was using the non-array form of delete
+	  on arrays (remember, auto_ptr doesn't work on arrays...).
+
 	* src/generic/util/util.cc, src/generic/util/util.h:
 
 	  Write a safe strftime wrapper.

Modified: branches/aptitude-0.3/aptitude/src/generic/util/util.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/util/util.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/util/util.cc	Mon Sep 26 20:04:17 2005
@@ -150,12 +150,19 @@
 
 #ifdef _SC_GETPW_R_SIZE_MAX
   long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
-  auto_ptr<char> buf(new char[bufsize]);
+  char *buf = new char[bufsize];
 
-  if(getpwuid_r(myuid, &pwbuf, buf.get(), bufsize, &useless) != 0)
-    return "";
+  if(getpwuid_r(myuid, &pwbuf, buf, bufsize, &useless) != 0)
+    {
+      delete[] buf;
+      return "";
+    }
   else
-    return pwbuf.pw_dir;
+    {
+      string rval = pwbuf.pw_dir;
+      delete[] buf;
+      return rval;
+    }
 #else
   long bufsize = 512;
   bool done = false;
@@ -165,12 +172,19 @@
   // to directly determine the largest possible password structure.
   while(bufsize < 512 * 512)
     {
-      auto_ptr<char> buf(new char[bufsize]);
+      char *buf = new char[bufsize];
 
-      if(getpwuid_r(myuid, &pwbuf, buf.get(), bufsize, &useless) == 0)
-	return pwbuf.pw_dir;
+      if(getpwuid_r(myuid, &pwbuf, buf, bufsize, &useless) == 0)
+	{
+	  string rval = pwbuf.pw_dir;
+	  delete[] buf;
+	  return rval;
+	}
       else
-	bufsize *= 2;
+	{
+	  delete[] buf;
+	  bufsize *= 2;
+	}
     }
 
   return "";



More information about the Aptitude-svn-commit mailing list