[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
Tomasz Kojm
tkojm at clamav.net
Sun Apr 4 01:04:41 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 1ffccbda0a99321986c48c114ce5ede98b0f43a1
Author: Tomasz Kojm <tkojm at clamav.net>
Date: Wed Sep 9 22:43:25 2009 +0200
integrate reentrant and non-recursive qsort
diff --git a/libclamav/matcher-bm.c b/libclamav/matcher-bm.c
index 87ca7fa..7c8eda6 100644
--- a/libclamav/matcher-bm.c
+++ b/libclamav/matcher-bm.c
@@ -200,7 +200,7 @@ int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, int
if(info.exeinfo.section)
free(info.exeinfo.section);
- qsort(data->offtab, data->cnt, sizeof(uint32_t), qcompare);
+ cli_qsort(data->offtab, data->cnt, sizeof(uint32_t), qcompare);
return CL_SUCCESS;
}
diff --git a/libclamav/others.c b/libclamav/others.c
index b947d50..b5ae1fa 100644
--- a/libclamav/others.c
+++ b/libclamav/others.c
@@ -986,4 +986,3 @@ int cli_bitset_test(bitset_t *bs, unsigned long bit_offset)
}
return (bs->bitset[char_offset] & ((unsigned char)1 << bit_offset));
}
-
diff --git a/libclamav/others.h b/libclamav/others.h
index 1c3f58f..9f318dc 100644
--- a/libclamav/others.h
+++ b/libclamav/others.h
@@ -411,6 +411,7 @@ int cli_checklimits(const char *, cli_ctx *, unsigned long, unsigned long, unsig
int cli_updatelimits(cli_ctx *, unsigned long);
unsigned long cli_getsizelimit(cli_ctx *, unsigned long);
int cli_matchregex(const char *str, const char *regex);
+void cli_qsort(void *basep, size_t nelems, size_t size, int (*comp)(const void *, const void *));
/* symlink behaviour */
#define CLI_FTW_FOLLOW_FILE_SYMLINK 0x01
diff --git a/libclamav/others_common.c b/libclamav/others_common.c
index fde41b8..151e26f 100644
--- a/libclamav/others_common.c
+++ b/libclamav/others_common.c
@@ -677,7 +677,7 @@ static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb
closedir(dd);
if (entries) {
- qsort(entries, entries_cnt, sizeof(*entries), ftw_compare);
+ cli_qsort(entries, entries_cnt, sizeof(*entries), ftw_compare);
for (i = 0; i < entries_cnt; i++) {
struct dirent_data *entry = &entries[i];
ret = handle_entry(entry, flags, maxdepth-1, callback, data, pathchk);
@@ -835,3 +835,83 @@ int cli_regcomp(regex_t *preg, const char *pattern, int cflags)
}
return cli_regcomp_real(preg, pattern, cflags);
}
+
+/* Public domain qsort implementation by Raymond Gardner and Paul Edwards */
+#define SWAP(a, b) (qsort_swap((char *)(a), (char *)(b), size))
+#define COMP(a, b) ((*comp)((void *)(a), (void *)(b)))
+#define T 7 /* subfiles of T or fewer elements will
+ * be sorted by a simple insertion sort
+ * T must be at least 3
+ */
+
+static void qsort_swap(char *a, char *b, size_t nbytes)
+{
+ char tmp;
+
+ do {
+ tmp = *a;
+ *a++ = *b;
+ *b++ = tmp;
+ } while(--nbytes);
+}
+
+void cli_qsort(void *basep, size_t nelems, size_t size, int (*comp)(const void *, const void *))
+{
+ char *stack[40], **sp;
+ char *i, *j, *limit;
+ size_t thresh;
+ char *base;
+
+ base = (char *) basep;
+ thresh = T * size;
+ sp = stack;
+ limit = base + nelems * size;
+ while(1) {
+ if(limit - base > thresh) {
+ SWAP(((((size_t) (limit - base)) / size) / 2) * size + base, base);
+ i = base + size;
+ j = limit - size;
+ if(COMP(i, j) > 0)
+ SWAP(i, j);
+ if(COMP(base, j) > 0)
+ SWAP(base, j);
+ if(COMP(i, base) > 0)
+ SWAP(i, base);
+ while(1) {
+ do
+ i += size;
+ while(COMP(i, base) < 0);
+ do
+ j -= size;
+ while(COMP(j, base) > 0);
+ if(i > j)
+ break;
+ SWAP(i, j);
+ }
+ SWAP(base, j);
+ if(j - base > limit - i) {
+ sp[0] = base;
+ sp[1] = j;
+ base = i;
+ } else {
+ sp[0] = i;
+ sp[1] = limit;
+ limit = j;
+ }
+ sp += 2;
+ } else {
+ for(j = base, i = j + size; i < limit; j = i, i += size)
+ for(; COMP(j, j + size) > 0; j -= size) {
+ SWAP(j, j+size);
+ if(j == base)
+ break;
+ }
+ if(sp != stack) {
+ sp -= 2;
+ base = sp[0];
+ limit = sp[1];
+ } else
+ break;
+ }
+ }
+}
diff --git a/libclamav/readdb.c b/libclamav/readdb.c
index 5e1e5f8..c333904 100644
--- a/libclamav/readdb.c
+++ b/libclamav/readdb.c
@@ -2130,7 +2130,7 @@ static void cli_md5db_build(struct cli_matcher* root)
root->soff_len = cli_hashset_toarray(&root->md5_sizes_hs, &root->soff);
#endif
cli_hashset_destroy(&root->md5_sizes_hs);
- qsort(root->soff, root->soff_len, sizeof(uint32_t), scomp);
+ cli_qsort(root->soff, root->soff_len, sizeof(uint32_t), scomp);
}
}
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list