handle NULL and empty strings correctly
authorJan Pospíšil <honik@ntc.zcu.cz>
Tue, 12 Jun 2007 14:13:17 +0000 (14:13 +0000)
committerJan Pospíšil <honik@ntc.zcu.cz>
Tue, 12 Jun 2007 14:13:17 +0000 (14:13 +0000)
org.glite.lb.common/src/escape.c
org.glite.lb.common/src/events_parse.c.T

index 09285ad..a681837 100644 (file)
@@ -16,7 +16,7 @@
  * 
  * \fn char *edg_wll_LogEscape(const char *str)
  * \param str          a string to escape
- * \return             new (allocated) escaped string
+ * \return             new (allocated) escaped string (is is empty "" if str is NULL)
  * \brief in given string escape all ULM_QM, ULM_BS and ULM_LF by ULM_BS
  *
  * Calls: malloc, strlen
@@ -33,7 +33,7 @@ unsigned int i,j;
 size_t size;
 char *ret;
 
-if (str == NULL) return NULL;
+if (str == NULL) return strdup("");
 if ((size = strlen(str)) == 0) return strdup("");
 
 ret = (char*) malloc(1+2*size*sizeof(char));
@@ -66,7 +66,7 @@ return ret;
  * 
  * \fn char *edg_wll_LogUnescape(const char *str)
  * \param str          a string to unescape
- * \return             new (allocated) unescaped string
+ * \return             new (allocated) unescaped string or NULL (if str NULL or empty)
  * \brief in given string unescape all escaped ULM_QM, ULM_BS and ULM_LF
  *
  * Calls: malloc, strlen
@@ -86,6 +86,8 @@ char *ret;
 if (str == NULL) return NULL;
 
 size  = strlen(str);
+if (size == 0) return NULL;
+
 ret = (char*) malloc(1+size*sizeof(char));
 
 /*
index f656175..5fa592d 100644 (file)
@@ -148,7 +148,7 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
                        my $c = "$t".ucfirst(${fn});
                        gen "\tthis->$tl.$fn = edg_wll_StringTo${c}(value);";
                } else {
-                       gen "\t";
+                       gen "\tif(strlen(value) > 0) ";
                        gen $f->fromString('value',"this->$tl.$fn");
                }
                gen "\n".$indent.$indent."break;\n";