LDB:tools - change counters to be unsigned
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Fri, 6 Nov 2009 17:35:17 +0000 (18:35 +0100)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sat, 6 Mar 2010 10:35:17 +0000 (11:35 +0100)
In most cases we do count LDB objects which are enumerated within the "unsigned"
type. Therefore no need to use "signed" counters.

source4/lib/ldb/tools/cmdline.c
source4/lib/ldb/tools/ldbadd.c
source4/lib/ldb/tools/ldbdel.c
source4/lib/ldb/tools/ldbedit.c
source4/lib/ldb/tools/ldbsearch.c
source4/lib/ldb/tools/ldbtest.c

index f2becb17af403079a905f5482b683181cb963d16..869d5ca8c30309b38e4602dc911e4fab128c688e 100644 (file)
@@ -347,8 +347,8 @@ failed:
  */
 int handle_controls_reply(struct ldb_control **reply, struct ldb_control **request)
 {
  */
 int handle_controls_reply(struct ldb_control **reply, struct ldb_control **request)
 {
-       int i, j;
-               int ret = 0;
+       unsigned int i, j;
+       int ret = 0;
 
        if (reply == NULL || request == NULL) return -1;
        
 
        if (reply == NULL || request == NULL) return -1;
        
index e618ab52f735443b078817c56a88879158954f3a..0dd35cc1b3c815d052262cdb9f140e1ce33b950f 100644 (file)
@@ -35,7 +35,7 @@
 #include "tools/cmdline.h"
 #include "ldbutil.h"
 
 #include "tools/cmdline.h"
 #include "ldbutil.h"
 
-static int failures;
+static unsigned int failures;
 static struct ldb_cmdline *options;
 
 static void usage(void)
 static struct ldb_cmdline *options;
 
 static void usage(void)
@@ -50,7 +50,7 @@ static void usage(void)
 /*
   add records from an opened file
 */
 /*
   add records from an opened file
 */
-static int process_file(struct ldb_context *ldb, FILE *f, int *count)
+static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count)
 {
        struct ldb_ldif *ldif;
        int ret = LDB_SUCCESS;
 {
        struct ldb_ldif *ldif;
        int ret = LDB_SUCCESS;
@@ -93,7 +93,8 @@ static int process_file(struct ldb_context *ldb, FILE *f, int *count)
 int main(int argc, const char **argv)
 {
        struct ldb_context *ldb;
 int main(int argc, const char **argv)
 {
        struct ldb_context *ldb;
-       int i, ret=0, count=0;
+       unsigned int i, count = 0;
+       int ret=0;
 
        ldb = ldb_init(NULL, NULL);
 
 
        ldb = ldb_init(NULL, NULL);
 
index 1b8adf714c9e44cb6d9dba5a828709af7bd29d3c..04884e1becb6df87f5db2389b2e28178a9e6c2b5 100644 (file)
@@ -43,7 +43,8 @@ static int dn_cmp(struct ldb_message **msg1, struct ldb_message **msg2)
 
 static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls)
 {
 
 static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls)
 {
-       int ret, i, total=0;
+       int ret;
+       unsigned int i, total=0;
        const char *attrs[] = { NULL };
        struct ldb_result *res;
        
        const char *attrs[] = { NULL };
        struct ldb_result *res;
        
index ecadf0f61c1266c70b413910ea566dc2c468f679..4c5683cd835f9c8c615ec3acb7faa3c5f05e7de0 100644 (file)
@@ -88,10 +88,10 @@ static int modify_record(struct ldb_context *ldb,
 */
 static struct ldb_message *msg_find(struct ldb_context *ldb,
                                    struct ldb_message **msgs,
 */
 static struct ldb_message *msg_find(struct ldb_context *ldb,
                                    struct ldb_message **msgs,
-                                   int count,
+                                   unsigned int count,
                                    struct ldb_dn *dn)
 {
                                    struct ldb_dn *dn)
 {
-       int i;
+       unsigned int i;
        for (i=0;i<count;i++) {
                if (ldb_dn_compare(dn, msgs[i]->dn) == 0) {
                        return msgs[i];
        for (i=0;i<count;i++) {
                if (ldb_dn_compare(dn, msgs[i]->dn) == 0) {
                        return msgs[i];
@@ -104,10 +104,10 @@ static struct ldb_message *msg_find(struct ldb_context *ldb,
   merge the changes in msgs2 into the messages from msgs1
 */
 static int merge_edits(struct ldb_context *ldb,
   merge the changes in msgs2 into the messages from msgs1
 */
 static int merge_edits(struct ldb_context *ldb,
-                      struct ldb_message **msgs1, int count1,
-                      struct ldb_message **msgs2, int count2)
+                      struct ldb_message **msgs1, unsigned int count1,
+                      struct ldb_message **msgs2, unsigned int count2)
 {
 {
-       int i;
+       unsigned int i;
        struct ldb_message *msg;
        int ret = 0;
        int adds=0, modifies=0, deletes=0;
        struct ldb_message *msg;
        int ret = 0;
        int adds=0, modifies=0, deletes=0;
@@ -171,9 +171,9 @@ static int merge_edits(struct ldb_context *ldb,
   save a set of messages as ldif to a file
 */
 static int save_ldif(struct ldb_context *ldb, 
   save a set of messages as ldif to a file
 */
 static int save_ldif(struct ldb_context *ldb, 
-                    FILE *f, struct ldb_message **msgs, int count)
+                    FILE *f, struct ldb_message **msgs, unsigned int count)
 {
 {
-       int i;
+       unsigned int i;
 
        fprintf(f, "# editing %d records\n", count);
 
 
        fprintf(f, "# editing %d records\n", count);
 
@@ -194,8 +194,8 @@ static int save_ldif(struct ldb_context *ldb,
 /*
   edit the ldb search results in msgs using the user selected editor
 */
 /*
   edit the ldb search results in msgs using the user selected editor
 */
-static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int count1,
-                  const char *editor)
+static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1,
+                  unsigned int count1, const char *editor)
 {
        int fd, ret;
        FILE *f;
 {
        int fd, ret;
        FILE *f;
@@ -203,7 +203,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun
        char *cmd;
        struct ldb_ldif *ldif;
        struct ldb_message **msgs2 = NULL;
        char *cmd;
        struct ldb_ldif *ldif;
        struct ldb_message **msgs2 = NULL;
-       int count2 = 0;
+       unsigned int count2 = 0;
 
        /* write out the original set of messages to a temporary
           file */
 
        /* write out the original set of messages to a temporary
           file */
index af0c12a84c9d3e6ba69a1d2762228336a469814b..327a75ed8d3221310a55a8b27daac3509764d421 100644 (file)
@@ -54,15 +54,15 @@ struct search_context {
        struct ldb_control **req_ctrls;
 
        int sort;
        struct ldb_control **req_ctrls;
 
        int sort;
-       int num_stored;
+       unsigned int num_stored;
        struct ldb_message **store;
        struct ldb_message **store;
-       int refs_stored;
+       unsigned int refs_stored;
        char **refs_store;
 
        char **refs_store;
 
-       int entries;
-       int refs;
+       unsigned int entries;
+       unsigned int refs;
 
 
-       int pending;
+       unsigned int pending;
        int status;
 };
 
        int status;
 };
 
@@ -240,7 +240,7 @@ again:
                goto again;
 
        if (sctx->sort && (sctx->num_stored != 0 || sctx->refs != 0)) {
                goto again;
 
        if (sctx->sort && (sctx->num_stored != 0 || sctx->refs != 0)) {
-               int i;
+               unsigned int i;
 
                if (sctx->num_stored) {
                        LDB_TYPESAFE_QSORT(sctx->store, sctx->num_stored, ldb, do_compare_msg);
 
                if (sctx->num_stored) {
                        LDB_TYPESAFE_QSORT(sctx->store, sctx->num_stored, ldb, do_compare_msg);
index adc6ec8115920e4226271b299fce02252420cbaa..1c877c761a1dc1bb9f4abc0a6673e349b5992f4e 100644 (file)
@@ -52,10 +52,10 @@ static double _end_timer(void)
 
 static void add_records(struct ldb_context *ldb,
                        struct ldb_dn *basedn,
 
 static void add_records(struct ldb_context *ldb,
                        struct ldb_dn *basedn,
-                       int count)
+                       unsigned int count)
 {
        struct ldb_message msg;
 {
        struct ldb_message msg;
-       int i;
+       unsigned int i;
 
 #if 0
         if (ldb_lock(ldb, "transaction") != 0) {
 
 #if 0
         if (ldb_lock(ldb, "transaction") != 0) {
@@ -141,10 +141,10 @@ static void add_records(struct ldb_context *ldb,
 
 static void modify_records(struct ldb_context *ldb,
                           struct ldb_dn *basedn,
 
 static void modify_records(struct ldb_context *ldb,
                           struct ldb_dn *basedn,
-                          int count)
+                          unsigned int count)
 {
        struct ldb_message msg;
 {
        struct ldb_message msg;
-       int i;
+       unsigned int i;
 
        for (i=0;i<count;i++) {
                struct ldb_message_element el[3];
 
        for (i=0;i<count;i++) {
                struct ldb_message_element el[3];
@@ -194,9 +194,9 @@ static void modify_records(struct ldb_context *ldb,
 
 static void delete_records(struct ldb_context *ldb,
                           struct ldb_dn *basedn,
 
 static void delete_records(struct ldb_context *ldb,
                           struct ldb_dn *basedn,
-                          int count)
+                          unsigned int count)
 {
 {
-       int i;
+       unsigned int i;
 
        for (i=0;i<count;i++) {
                struct ldb_dn *dn;
 
        for (i=0;i<count;i++) {
                struct ldb_dn *dn;
@@ -217,9 +217,10 @@ static void delete_records(struct ldb_context *ldb,
        printf("\n");
 }
 
        printf("\n");
 }
 
-static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn, int nrecords, int nsearches)
+static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn,
+                      unsigned int nrecords, unsigned int nsearches)
 {
 {
-       int i;
+       unsigned int i;
 
        for (i=0;i<nsearches;i++) {
                int uid = (i * 700 + 17) % (nrecords * 2);
 
        for (i=0;i<nsearches;i++) {
                int uid = (i * 700 + 17) % (nrecords * 2);
@@ -250,7 +251,8 @@ static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn, int nreco
        printf("\n");
 }
 
        printf("\n");
 }
 
-static void start_test(struct ldb_context *ldb, int nrecords, int nsearches)
+static void start_test(struct ldb_context *ldb, unsigned int nrecords,
+                      unsigned int nsearches)
 {
        struct ldb_dn *basedn;
 
 {
        struct ldb_dn *basedn;
 
@@ -411,7 +413,9 @@ int main(int argc, const char **argv)
        printf("Testing with num-records=%d and num-searches=%d\n", 
               options->num_records, options->num_searches);
 
        printf("Testing with num-records=%d and num-searches=%d\n", 
               options->num_records, options->num_searches);
 
-       start_test(ldb, options->num_records, options->num_searches);
+       start_test(ldb,
+                  (unsigned int) options->num_records,
+                  (unsigned int) options->num_searches);
 
        start_test_index(&ldb);
 
 
        start_test_index(&ldb);