[PATCH] Octstr function call sometime barf when called with NULL data

"Oded Arbel" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi list.

While some Octstr functions handle NULLs gracefully, others (especially the formating ones) do not behave so gentlemen-like. this patch will cause NULLs received instead of Octstr* in some cases not to panic the box but instead be handled in a predictable manner.

--
Oded Arbel
m-Wise mobile solutions
[email protected]

+972-9-9581711 (116)
+972-67-340014

::..
Don't hate yourself in the morning, sleep until noon. 



 <<octstr.patch>>
octstr.patch (application/octet-stream, 884 B)
--- gateway/gwlib/octstr.c	2002-04-28 12:28:33.000000000 +0300
+++ gateway/gwlib/octstr.c	2002-06-06 15:01:58.000000000 +0300
@@ -354,6 +354,8 @@
 char *octstr_get_cstr_real(Octstr *ostr, const char *file, long line, 
     	    	    	   const char *func)
 {
+    if (!ostr)
+      return "<NULL>";
     seems_valid_real(ostr, file, line, func);
     if (ostr->len == 0)
         return "";
@@ -1973,12 +1975,16 @@
 
     case 'S':
         new = octstr_duplicate(va_arg(VALST(args), Octstr *));
+        if (!new)
+	    new = octstr_imm("<NULL>");
         if (format->has_prec)
             octstr_truncate(new, format->prec);
         break;
 
     case 'E':
         new = octstr_duplicate(va_arg(VALST(args), Octstr *));
+        if (!new)
+	    new = octstr_imm("<NULL>");
 	octstr_url_encode(new);
 	/*
 	 * note: we use blind truncate - encoded character can get cut half-way.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.