summaryrefslogtreecommitdiff
path: root/librazor
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-06-30 10:46:20 +0100
committerRichard Hughes <richard@hughsie.com>2008-06-30 10:46:20 +0100
commite911090d427fcf3cf57fa57d51c65cf724be770d (patch)
tree97b992368840d25e3a5d9d9cc4ed2e5c1895c6e7 /librazor
parentd66068c79b8bb9173a3fa6dc5baf78ed1c9861de (diff)
the vararg list must be terminated with zero else 64bit machines may crash
On 64 bit systems, the integer 0 is 32 bits and the pointer 0 is 64 bits. The upper 32 bits will not be cleared and the loop will never terminate. Also add the RAZOR_SENTINEL __attribute__ ((__sentinel__(0))) on GCC4 so we catch where we get this wrong automatically. This also fixes the new search functionality from James which was missed in the merge.
Diffstat (limited to 'librazor')
-rw-r--r--librazor/iterator.c4
-rw-r--r--librazor/razor.c12
-rw-r--r--librazor/razor.h16
-rw-r--r--librazor/transaction.c16
4 files changed, 29 insertions, 19 deletions
diff --git a/librazor/iterator.c b/librazor/iterator.c
index b2bddff..6b973b0 100644
--- a/librazor/iterator.c
+++ b/librazor/iterator.c
@@ -112,7 +112,7 @@ razor_package_iterator_create_for_file(struct razor_set *set,
* @package: a %razor_package
*
* Gets the next iteratr along with any vararg data.
- * The vararg must be terminated with zero.
+ * The vararg must be terminated with NULL.
*
* Example: razor_package_iterator_next (pi, package, RAZOR_DETAIL_NAME, &name, 0);
**/
@@ -273,7 +273,7 @@ razor_package_query_add_iterator(struct razor_package_query *pq,
assert (pi != NULL);
packages = pq->set->packages.data;
- while (razor_package_iterator_next(pi, &p, 0)) {
+ while (razor_package_iterator_next(pi, &p, NULL)) {
pq->count += pq->vector[p - packages] ^ 1;
pq->vector[p - packages] = 1;
}
diff --git a/librazor/razor.c b/librazor/razor.c
index d3cab33..6f5b1b5 100644
--- a/librazor/razor.c
+++ b/librazor/razor.c
@@ -394,7 +394,7 @@ razor_set_get_package(struct razor_set *set, const char *package)
assert (package != NULL);
pi = razor_package_iterator_create(set);
- while (razor_package_iterator_next(pi, &p, RAZOR_DETAIL_NAME, &name, 0)) {
+ while (razor_package_iterator_next(pi, &p, RAZOR_DETAIL_NAME, &name, NULL)) {
if (strcmp(package, name) == 0)
break;
}
@@ -476,7 +476,7 @@ razor_package_get_details_varg(struct razor_set *set,
* @package: a %razor_package
*
* Gets details about a package using a varg interface
- * The vararg must be terminated with zero.
+ * The vararg must be terminated with %NULL.
*
* Example: razor_package_get_details (set, package, RAZOR_DETAIL_URL, &url, 0);
**/
@@ -721,12 +721,12 @@ razor_set_diff(struct razor_set *set, struct razor_set *upstream,
RAZOR_DETAIL_NAME, &name1,
RAZOR_DETAIL_VERSION, &version1,
RAZOR_DETAIL_ARCH, &arch1,
- 0);
+ NULL);
razor_package_iterator_next(pi2, &p2,
RAZOR_DETAIL_NAME, &name2,
RAZOR_DETAIL_VERSION, &version2,
RAZOR_DETAIL_ARCH, &arch2,
- 0);
+ NULL);
while (p1 || p2) {
if (p1 && p2) {
@@ -749,13 +749,13 @@ razor_set_diff(struct razor_set *set, struct razor_set *upstream,
RAZOR_DETAIL_NAME, &name1,
RAZOR_DETAIL_VERSION, &version1,
RAZOR_DETAIL_ARCH, &arch1,
- 0);
+ NULL);
if (p2 != NULL && res >= 0)
razor_package_iterator_next(pi2, &p2,
RAZOR_DETAIL_NAME, &name2,
RAZOR_DETAIL_VERSION, &version2,
RAZOR_DETAIL_ARCH, &arch2,
- 0);
+ NULL);
}
razor_package_iterator_destroy(pi1);
diff --git a/librazor/razor.h b/librazor/razor.h
index 9f3c668..488b4ed 100644
--- a/librazor/razor.h
+++ b/librazor/razor.h
@@ -22,6 +22,13 @@
#include <stdint.h>
+/* GCC sentinel */
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define RAZOR_SENTINEL __attribute__ ((__sentinel__(0)));
+#else
+#define RAZOR_SENTINEL
+#endif
+
enum razor_repo_file_type {
RAZOR_REPO_FILE_MAIN,
RAZOR_REPO_FILE_DETAILS,
@@ -29,7 +36,7 @@ enum razor_repo_file_type {
};
enum razor_detail_type {
- RAZOR_DETAIL_NAME = 1, /* 0 is the marker for the vararg */
+ RAZOR_DETAIL_NAME = 1, /* NULL (0 on 32 bit) is the sentinel */
RAZOR_DETAIL_VERSION,
RAZOR_DETAIL_ARCH,
RAZOR_DETAIL_SUMMARY,
@@ -94,7 +101,9 @@ struct razor_package *
razor_set_get_package(struct razor_set *set, const char *package);
void
-razor_package_get_details(struct razor_set *set, struct razor_package *package, ...);
+razor_package_get_details(struct razor_set *set,
+ struct razor_package *package, ...)
+ RAZOR_SENTINEL;
/**
@@ -144,7 +153,8 @@ razor_package_iterator_create_for_file(struct razor_set *set,
const char *filename);
int razor_package_iterator_next(struct razor_package_iterator *pi,
- struct razor_package **package, ...);
+ struct razor_package **package, ...)
+ RAZOR_SENTINEL;
void razor_package_iterator_destroy(struct razor_package_iterator *pi);
struct razor_package_query *
diff --git a/librazor/transaction.c b/librazor/transaction.c
index 9efd5cd..1e91cae 100644
--- a/librazor/transaction.c
+++ b/librazor/transaction.c
@@ -318,7 +318,7 @@ remove_matching_providers(struct razor_transaction *trans,
razor_package_iterator_init_for_property(&pkg_iter, set, p);
while (razor_package_iterator_next(&pkg_iter, &pkg,
RAZOR_DETAIL_NAME, &n,
- RAZOR_DETAIL_VERSION, &v, 0)) {
+ RAZOR_DETAIL_VERSION, &v, NULL)) {
fprintf(stderr, "removing %s-%s\n", n, v);
razor_transaction_remove_package(trans, pkg);
}
@@ -364,7 +364,7 @@ flag_matching_providers(struct razor_transaction *trans,
razor_package_iterator_init_for_property(&pkg_iter, set, p);
while (razor_package_iterator_next(&pkg_iter, &pkg,
RAZOR_DETAIL_NAME, &name,
- RAZOR_DETAIL_VERSION, &version, 0)) {
+ RAZOR_DETAIL_VERSION, &version, NULL)) {
fprintf(stderr, "flagging %s-%s for providing %s matching %s %s\n",
name, version,
@@ -526,7 +526,7 @@ update_unsatisfied_packages(struct razor_transaction *trans)
trans->system.set,
sp);
while (razor_package_iterator_next(&pkg_iter, &pkg,
- RAZOR_DETAIL_NAME, &name, 0)) {
+ RAZOR_DETAIL_NAME, &name, NULL)) {
fprintf(stderr, "updating %s because %s %s %s "
"isn't satisfied\n",
name, spi.pool + sp->name,
@@ -578,7 +578,7 @@ update_conflicted_packages(struct razor_transaction *trans)
sp);
while (razor_package_iterator_next(&pkg_iter, &pkg,
RAZOR_DETAIL_NAME, &name,
- RAZOR_DETAIL_VERSION, &version, 0)) {
+ RAZOR_DETAIL_VERSION, &version, NULL)) {
fprintf(stderr, "updating %s %s because it "
"conflicts with %s\n",
name, version, spi.pool + sp->name);
@@ -668,7 +668,7 @@ flush_scheduled_system_updates(struct razor_transaction *trans)
while (razor_package_iterator_next(pi, &p,
RAZOR_DETAIL_NAME, &name,
- RAZOR_DETAIL_VERSION, &version, 0)) {
+ RAZOR_DETAIL_VERSION, &version, NULL)) {
if (!(trans->system.packages[p - spkgs] & TRANS_PACKAGE_UPDATE))
continue;
@@ -705,7 +705,7 @@ flush_scheduled_upstream_updates(struct razor_transaction *trans)
while (razor_package_iterator_next(pi, &p,
RAZOR_DETAIL_NAME, &name,
- RAZOR_DETAIL_VERSION, &version, 0)) {
+ RAZOR_DETAIL_VERSION, &version, NULL)) {
if (!(trans->upstream.packages[p - upkgs] & TRANS_PACKAGE_UPDATE))
continue;
@@ -754,7 +754,7 @@ describe_unsatisfied(struct razor_set *set, struct razor_property *rp)
while (razor_package_iterator_next(&pi, &pkg,
RAZOR_DETAIL_NAME, &name,
RAZOR_DETAIL_VERSION, &version,
- RAZOR_DETAIL_ARCH, &arch, 0))
+ RAZOR_DETAIL_ARCH, &arch, NULL))
fprintf(stderr, "%s is needed by %s-%s.%s\n",
&pool[rp->name],
name, version, arch);
@@ -763,7 +763,7 @@ describe_unsatisfied(struct razor_set *set, struct razor_property *rp)
while (razor_package_iterator_next(&pi, &pkg,
RAZOR_DETAIL_NAME, &name,
RAZOR_DETAIL_VERSION, &version,
- RAZOR_DETAIL_ARCH, &arch, 0))
+ RAZOR_DETAIL_ARCH, &arch, NULL))
fprintf(stderr, "%s %s %s is needed by %s-%s.%s\n",
&pool[rp->name],
razor_property_relation_to_string(rp),