Improved error handling, cleaned up messages, fixed minor bugs.
[trust_router.git] / common / tr_name.c
index 00757d4..0e15595 100644 (file)
@@ -64,14 +64,17 @@ TR_NAME *tr_dup_name (TR_NAME *from)
 {
   TR_NAME *to;
 
-  if (to = malloc(sizeof(TR_NAME))) {
+  if (!from) {
+    return NULL;
+  }
+
+  if (NULL != (to = malloc(sizeof(TR_NAME)))) {
     to->len = from->len;
-    if (to->buf = malloc(to->len+1)) {
+    if (NULL != (to->buf = malloc(to->len+1))) {
       strncpy(to->buf, from->buf, from->len);
       to->buf[to->len] = 0;    /* NULL terminate for debugging printf()s */
     }
   }
-
   return to;
 }