[Libpst-commits] r56 - trunk

Joseph Nahmias jello at alioth.debian.org
Thu Dec 7 07:02:30 CET 2006


Author: jello
Date: 2006-12-07 07:02:30 +0100 (Thu, 07 Dec 2006)
New Revision: 56

Modified:
   trunk/readpst.c
Log:
rfc2426_escape(): more fixes...

Modified: trunk/readpst.c
===================================================================
--- trunk/readpst.c	2006-12-07 05:45:39 UTC (rev 55)
+++ trunk/readpst.c	2006-12-07 06:02:30 UTC (rev 56)
@@ -1400,8 +1400,10 @@
   int x, y, z;
   DEBUG_ENT("rfc2426_escape");
 
-  if (str == NULL) 
-    return NULL;
+	if (str == NULL) {
+		DEBUG_RET();
+		return NULL;
+  }
     
   // calculate space required to escape all the following characters
   y = chr_count(str, ',')
@@ -1411,18 +1413,21 @@
   z = chr_count(str, '\r');
   x = strlen(str) + y - z;
 
-  if ( (y - z) == 0 )	// resize buffer if needed
-  {
-    buf = (char*) realloc(buf, x + 1); // don't forget room for the NUL
+	if (y == 0 && z == 0) {
+		// there isn't any work required
+		DEBUG_RET();
+		return str;
+	}
+
+  buf = (char*) realloc(buf, x + 1); // don't forget room for the NUL
 	if ( buf == NULL )
 	{
       fprintf(stderr, "Error: rfc2426_escape(): realloc(%d) returned NULL!\n", x + 1);
       exit(1);
 	}
-  }
 
   for ( a = str, b = buf; *a != '\0'; ++a, ++b )
-	switch(*a) {
+	  switch(*a) {
       case ',' :
       case '\\':
       case ';' :
@@ -1436,7 +1441,7 @@
 	      break;
       default:
 	      *b = *a;
-	}
+	  }
   *b = '\0'; // NUL-terminate the string (buf)
 
   DEBUG_RET();




More information about the Libpst-commits mailing list