diff src/libstrfunc.c @ 36:6fe121a971c9 stable-0-5-7

valgrind fixes
author carl
date Thu, 09 Aug 2007 15:46:34 -0700
parents b88ceb81dba2
children f6db1f060a95
line wrap: on
line diff
--- a/src/libstrfunc.c	Sun Jul 15 14:25:34 2007 -0700
+++ b/src/libstrfunc.c	Thu Aug 09 15:46:34 2007 -0700
@@ -6,9 +6,6 @@
 #include <stdlib.h>
 #include "libstrfunc.h"
 
-char *_sf_b64_buf=NULL;
-size_t _sf_b64_len=0;
-
 
 static unsigned char _sf_uc_ib[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/==";
 
@@ -26,44 +23,41 @@
 #endif
   //register void *dte=data + size;
   register int nc=0;
-  
+
   if ( data == NULL || size == 0 )
-    return NULL;
-  
-  ou=output=(char *)malloc(size / 3 * 4 + (size / 50) + 5);
+	return NULL;
+
+  ou=output=(char *)malloc(size / 3 * 4 + (size / 57) + 5);
   if(!output)
-    return NULL;
-  
+	return NULL;
+
   while((char *)dte - (char *)p >= 3) {
-    *ou = _sf_uc_ib[ *p >> 2 ];
-    ou[1] = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ];
-    ou[2] = _sf_uc_ib[ ((p[1] & 0x0F) << 2) | (p[2] >> 6) ];
-    ou[3] = _sf_uc_ib[ p[2] & 0x3F ];
-    
-    p+=3;
-    ou+=4;
-    
-    nc+=4;
-    if(!(nc % 76)) *ou++='\n';
+	unsigned char x = p[0];
+	unsigned char y = p[1];
+	unsigned char z = p[2];
+	ou[0] = _sf_uc_ib[ x >> 2 ];
+	ou[1] = _sf_uc_ib[ ((x & 0x03) << 4) | (y >> 4) ];
+	ou[2] = _sf_uc_ib[ ((y & 0x0F) << 2) | (z >> 6) ];
+	ou[3] = _sf_uc_ib[ z & 0x3F ];
+	p+=3;
+	ou+=4;
+	nc+=4;
+	if(!(nc % 76)) *ou++='\n';
   };
   if((char *)dte - (char *)p == 2) {
-    *ou++ = _sf_uc_ib[ *p >> 2 ];
-    *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ];
-    *ou++ = _sf_uc_ib[ ((p[1] & 0x0F) << 2) ];
-    *ou++ = '=';
+	*ou++ = _sf_uc_ib[ *p >> 2 ];
+	*ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ];
+	*ou++ = _sf_uc_ib[ ((p[1] & 0x0F) << 2) ];
+	*ou++ = '=';
   } else if((char *)dte - (char *)p == 1) {
-    *ou++ = _sf_uc_ib[ *p >> 2 ];
-    *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) ];
-    *ou++ = '=';
-    *ou++ = '=';
+	*ou++ = _sf_uc_ib[ *p >> 2 ];
+	*ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) ];
+	*ou++ = '=';
+	*ou++ = '=';
   };
-  
+
   *ou=0;
-  
-  _sf_b64_len = (ou - output);
-  
-  if(_sf_b64_buf)
-    free(_sf_b64_buf);
-  return _sf_b64_buf=output;
+
+  return output;
 };