Use "==0" instead of "!strcmp" etc
[openssl.git] / apps / srp.c
index b984c14c97ab3088e4fec6d1897011a987bacd40..111f829ca648707d40ebc289b987491422eea728 100644 (file)
@@ -88,14 +88,14 @@ static int get_index(CA_DB *db, char *id, char type)
         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
             if (pp[DB_srptype][0] == DB_SRP_INDEX
-                && !strcmp(id, pp[DB_srpid]))
+                && strcmp(id, pp[DB_srpid]) == 0)
                 return i;
     } else
         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
 
             if (pp[DB_srptype][0] != DB_SRP_INDEX
-                && !strcmp(id, pp[DB_srpid]))
+                && strcmp(id, pp[DB_srpid]) == 0)
                 return i;
         }
 
@@ -138,7 +138,7 @@ static int update_index(CA_DB *db, char **row)
     char **irow;
     int i;
 
-    irow = app_malloc(sizeof(char *) * (DB_NUMBER + 1), "row pointers");
+    irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
     for (i = 0; i < DB_NUMBER; i++) {
         irow[i] = row[i];
         row[i] = NULL;
@@ -384,10 +384,8 @@ int srp_main(int argc, char **argv)
                            errorline, configfile);
             goto end;
         }
-        if (tofree) {
-            OPENSSL_free(tofree);
-            tofree = NULL;
-        }
+        OPENSSL_free(tofree);
+        tofree = NULL;
 
         /* Lets get the config section we are using */
         if (section == NULL) {
@@ -436,7 +434,7 @@ int srp_main(int argc, char **argv)
 
         if (pp[DB_srptype][0] == DB_SRP_INDEX) {
             maxgN = i;
-            if (gNindex < 0 && gN != NULL && !strcmp(gN, pp[DB_srpid]))
+            if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)
                 gNindex = i;
 
             print_index(db, i, verbose > 1);
@@ -519,26 +517,16 @@ int srp_main(int argc, char **argv)
                 row[DB_srpgN] = BUF_strdup(gNid);
 
                 if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
-                    || !row[DB_srpverifier] || !row[DB_srpsalt] || (userinfo
-                                                                    &&
-                                                                    (!(row
-                                                                       [DB_srpinfo]
-                                                                       =
-                                                                       BUF_strdup
-                                                                       (userinfo))))
+                    || !row[DB_srpverifier] || !row[DB_srpsalt]
+                    || (userinfo &&
+                         (!(row [DB_srpinfo] = BUF_strdup (userinfo))))
                     || !update_index(db, row)) {
-                    if (row[DB_srpid])
-                        OPENSSL_free(row[DB_srpid]);
-                    if (row[DB_srpgN])
-                        OPENSSL_free(row[DB_srpgN]);
-                    if (row[DB_srpinfo])
-                        OPENSSL_free(row[DB_srpinfo]);
-                    if (row[DB_srptype])
-                        OPENSSL_free(row[DB_srptype]);
-                    if (row[DB_srpverifier])
-                        OPENSSL_free(row[DB_srpverifier]);
-                    if (row[DB_srpsalt])
-                        OPENSSL_free(row[DB_srpsalt]);
+                    OPENSSL_free(row[DB_srpid]);
+                    OPENSSL_free(row[DB_srpgN]);
+                    OPENSSL_free(row[DB_srpinfo]);
+                    OPENSSL_free(row[DB_srptype]);
+                    OPENSSL_free(row[DB_srpverifier]);
+                    OPENSSL_free(row[DB_srpsalt]);
                     goto end;
                 }
                 doupdatedb = 1;
@@ -676,17 +664,13 @@ int srp_main(int argc, char **argv)
 
     if (verbose)
         BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
-    if (tofree)
-        OPENSSL_free(tofree);
+    OPENSSL_free(tofree);
     if (ret)
         ERR_print_errors(bio_err);
     if (randfile)
         app_RAND_write_file(randfile);
-    if (conf)
-        NCONF_free(conf);
-    if (db)
-        free_index(db);
-
+    NCONF_free(conf);
+    free_index(db);
     OBJ_cleanup();
     return (ret);
 }