Hylafax Mailing List Archives

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [hylafax-users] Having a problem with hfaxd and faxwatch



Here is a difference of Str.c++ and Str.h that seems to hide the
segfault problem.  It's not really a good long term solution though.
Anyone have ideas for a better fix?

Kris

==== util/Str.c++ (text) ====


@@ -818,3 +818,69 @@
 {
     return fxTempStr(a, strlen(a), b.data, b.slength-1);
 }
+
+	void* fxStr::malloc(size_t strSize)
+	{
+		const int sun = sizeof(unsigned);
+		strSize = ((strSize+sun-1)/sun)*sun;
+		
+		char* junk = (char*)::malloc(strSize+3*sun);
+		*(unsigned*)junk = strSize;
+		junk += sun;
+		*(unsigned*)junk = 0xa5c3a5c3;
+		junk += sun;
+		junk += strSize;
+		*(unsigned*)junk = 0xc3a5c3a5;
+
+		return junk-strSize;
+	}
+
+	void fxStr::free(void* freeMem)
+	{
+		const int sun = sizeof(unsigned);
+		char* unFreeMem = (char*)freeMem;
+
+		unFreeMem -= 2*sun;
+
+		unsigned strSize = *(unsigned*)unFreeMem;
+
+		unFreeMem += sun;
+
+		if (0xa5c3a5c3 != *(unsigned*)unFreeMem)
+		{
+			raise(SIGSEGV);
+		}
+
+		unFreeMem += sun;
+		unFreeMem += strSize;
+
+		if (0xc3a5c3a5 != *(unsigned*)unFreeMem)
+		{
+			raise(SIGSEGV);
+		}
+
+		unFreeMem -= strSize+2*sun;
+
+		::free(unFreeMem);
+	}
+
+	void* fxStr::realloc(void* reMem, size_t strSize)
+	{
+		char* reJunk = (char*)malloc(strSize);
+		
+		const int sun = sizeof(unsigned);
+		char* cReMem = (char*)reMem;
+
+		cReMem -= 2*sun;
+
+		unsigned reStrSize = *(unsigned*)cReMem;
+
+		reStrSize = reStrSize > strSize ? strSize : reStrSize;
+
+		memcpy(reJunk, reMem, reStrSize);
+
+		free(reMem);
+
+		return reJunk;
+	}
+



==== util/Str.h (text) ====


@@ -28,6 +28,7 @@
 
 #include "stdlib.h"
 #include "stdarg.h"
+#include "signal.h"
 #include "Obj.h"
 
 // Temporary strings are generated by the concatenation operators.
@@ -244,5 +245,9 @@
     int findEndBuffer(const char *, u_int buflen) const;
     int findBuffer(const char *buf, u_int buflen) const;
     void bracketBuffer(const char *, u_int buflen, int &, int &) const;
+
+	static void* realloc(void* reMem, size_t strSize);
+	static void* malloc(size_t strSize);
+	static void free(void* freeMem);
 };
 #endif /* _Str_ */

____________________ HylaFAX(tm) Users Mailing List _______________________
  To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
 On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null
  *To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*



Home
Report any problems to webmaster@hylafax.org

HylaFAX is a trademark of Silicon Graphics Corporation.
Internet connectivity for hylafax.org is provided by:
VirtuALL Private Host Services