Cleanup conf.c.
authorLinus Nordberg <linus@nordu.net>
Sun, 3 Jul 2011 08:38:53 +0000 (10:38 +0200)
committerLinus Nordberg <linus@nordu.net>
Sun, 3 Jul 2011 08:38:53 +0000 (10:38 +0200)
Don't promote a pointer to a boolean in if clauses.
Compare strcmp to 0.

lib/conf.c

index 9b8e77c..83c2e4b 100644 (file)
@@ -101,37 +101,39 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file)
 
   for (i = 0; i < cfg_size (cfg, "realm"); i++)
     {
-      struct rs_realm *r = rs_calloc (ctx, 1, sizeof(*r));
+      struct rs_realm *r = NULL;
       const char *typestr;
 
-      if (!r)
+      r = rs_calloc (ctx, 1, sizeof(*r));
+      if (r == NULL)
        return rs_err_ctx_push_fl (ctx, RSE_NOMEM, __FILE__, __LINE__, NULL);
-      if (config->realms)
+      if (config->realms != NULL)
        {
          r->next = config->realms->next;
          config->realms->next = r;
        }
       else
+       {
          config->realms = r;
+       }
       cfg_realm = cfg_getnsec (cfg, "realm", i);
-      /* We use a copy of return value of cfg_title since it's a
-        const.  */
+      /* We use a copy of the return value of cfg_title() since it's const.  */
       s = cfg_title (cfg_realm);
       if (s == NULL)
        return rs_err_ctx_push_fl (ctx, RSE_CONFIG, __FILE__, __LINE__,
                                   "missing realm name");
-      r->name = strdup (s);    /* FIXME: Don't strdup.  */
-      if (!r->name)
+      r->name = strdup (s);
+      if (r->name == NULL)
        return rs_err_ctx_push_fl (ctx, RSE_NOMEM, __FILE__, __LINE__, NULL);
 
       typestr = cfg_getstr (cfg_realm, "type");
-      if (!strcmp (typestr, "UDP"))
+      if (strcmp (typestr, "UDP") == 0)
        r->type = RS_CONN_TYPE_UDP;
-      else if (!strcmp (typestr, "TCP"))
+      else if (strcmp (typestr, "TCP") == 0)
        r->type = RS_CONN_TYPE_TCP;
-      else if (!strcmp (typestr, "TLS"))
+      else if (strcmp (typestr, "TLS") == 0)
        r->type = RS_CONN_TYPE_TLS;
-      else if (!strcmp (typestr, "DTLS"))
+      else if (strcmp (typestr, "DTLS") == 0)
        r->type = RS_CONN_TYPE_DTLS;
       else
        return rs_err_ctx_push_fl (ctx, RSE_CONFIG, __FILE__, __LINE__,
@@ -148,7 +150,7 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file)
       for (j = 0; j < cfg_size (cfg_realm, "server"); j++)
        {
          struct rs_peer *p = peer_create (ctx, &r->peers);
-         if (!p)
+         if (p == NULL)
            return rs_err_ctx_push_fl (ctx, RSE_NOMEM, __FILE__, __LINE__,
                                       NULL);
          p->realm = r;
@@ -162,9 +164,9 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file)
        }
     }
 
-  /* Save config object in context, for freeing in
-     rs_context_destroy().  */
-  ctx->config->cfg =  cfg;
+  /* Save config object in context, for freeing in rs_context_destroy().  */
+  ctx->config->cfg = cfg;
+
   return RSE_OK;
 }
 
@@ -174,7 +176,8 @@ rs_conf_find_realm(struct rs_context *ctx, const char *name)
   struct rs_realm *r;
 
   for (r = ctx->config->realms; r; r = r->next)
-    if (!strcmp (r->name, name))
+    if (strcmp (r->name, name) == 0)
        return r;
+
   return NULL;
 }