summaryrefslogtreecommitdiff
path: root/librazor
diff options
context:
space:
mode:
Diffstat (limited to 'librazor')
-rw-r--r--librazor/iterator.c33
-rw-r--r--librazor/razor.c40
-rw-r--r--librazor/root.c17
-rw-r--r--librazor/rpm.c11
-rw-r--r--librazor/transaction.c14
5 files changed, 115 insertions, 0 deletions
diff --git a/librazor/iterator.c b/librazor/iterator.c
index 1169630..5a870cc 100644
--- a/librazor/iterator.c
+++ b/librazor/iterator.c
@@ -20,6 +20,8 @@
#define _GNU_SOURCE
#include <string.h>
+#include <assert.h>
+
#include "razor-internal.h"
#include "razor.h"
@@ -48,6 +50,8 @@ razor_package_iterator_create(struct razor_set *set)
{
struct razor_package_iterator *pi;
+ assert (set != NULL);
+
pi = zalloc(sizeof *pi);
pi->set = set;
pi->end = set->packages.data + set->packages.size;
@@ -61,6 +65,10 @@ razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
struct razor_set *set,
struct razor_property *property)
{
+ assert (pi != NULL);
+ assert (set != NULL);
+ assert (property != NULL);
+
memset(pi, 0, sizeof *pi);
pi->set = set;
pi->index = list_first(&property->packages, &set->package_pool);
@@ -72,6 +80,9 @@ razor_package_iterator_create_for_property(struct razor_set *set,
{
struct list *index;
+ assert (set != NULL);
+ assert (property != NULL);
+
index = list_first(&property->packages, &set->package_pool);
return razor_package_iterator_create_with_index(set, index);
}
@@ -83,6 +94,9 @@ razor_package_iterator_create_for_file(struct razor_set *set,
struct razor_entry *entry;
struct list *index;
+ assert (set != NULL);
+ assert (filename != NULL);
+
entry = razor_set_find_entry(set, set->files.data, filename);
if (entry == NULL)
return razor_package_iterator_create_empty(set);
@@ -102,6 +116,8 @@ razor_package_iterator_next(struct razor_package_iterator *pi,
int valid;
struct razor_package *p, *packages;
+ assert (pi != NULL);
+
if (pi->package) {
p = pi->package++;
valid = p < pi->end;
@@ -129,6 +145,8 @@ razor_package_iterator_next(struct razor_package_iterator *pi,
RAZOR_EXPORT void
razor_package_iterator_destroy(struct razor_package_iterator *pi)
{
+ assert (pi != NULL);
+
if (pi->free_index)
free(pi->index);
@@ -141,6 +159,9 @@ razor_property_iterator_create(struct razor_set *set,
{
struct razor_property_iterator *pi;
+ assert (set != NULL);
+ assert (package != NULL);
+
pi = zalloc(sizeof *pi);
pi->set = set;
@@ -166,6 +187,8 @@ razor_property_iterator_next(struct razor_property_iterator *pi,
int valid;
struct razor_property *p, *properties;
+ assert (pi != NULL);
+
if (pi->property) {
p = pi->property++;
valid = p < pi->end;
@@ -208,6 +231,8 @@ razor_package_query_create(struct razor_set *set)
struct razor_package_query *pq;
int count;
+ assert (set != NULL);
+
pq = zalloc(sizeof *pq);
pq->set = set;
count = set->packages.size / sizeof(struct razor_package);
@@ -222,6 +247,9 @@ razor_package_query_add_package(struct razor_package_query *pq,
{
struct razor_package *packages;
+ assert (pq != NULL);
+ assert (p != NULL);
+
packages = pq->set->packages.data;
pq->count += pq->vector[p - packages] ^ 1;
pq->vector[p - packages] = 1;
@@ -234,6 +262,9 @@ razor_package_query_add_iterator(struct razor_package_query *pq,
struct razor_package *packages, *p;
const char *name, *version, *arch;
+ assert (pq != NULL);
+ assert (pi != NULL);
+
packages = pq->set->packages.data;
while (razor_package_iterator_next(pi, &p, &name, &version, &arch)) {
pq->count += pq->vector[p - packages] ^ 1;
@@ -249,6 +280,8 @@ razor_package_query_finish(struct razor_package_query *pq)
struct list *index;
int i, j;
+ assert (pq != NULL);
+
set = pq->set;
if (pq->count > 0)
index = zalloc(pq->count * sizeof *index);
diff --git a/librazor/razor.c b/librazor/razor.c
index 78a1182..88ff7a7 100644
--- a/librazor/razor.c
+++ b/librazor/razor.c
@@ -32,6 +32,7 @@
#include <errno.h>
#include <ctype.h>
#include <fnmatch.h>
+#include <assert.h>
#include "razor-internal.h"
#include "razor.h"
@@ -127,6 +128,9 @@ razor_set_open_details(struct razor_set *set, const char *filename)
struct array *array;
int fd;
+ assert (set != NULL);
+ assert (filename != NULL);
+
fd = open(filename, O_RDONLY);
if (fstat(fd, &stat) < 0)
return -1;
@@ -157,6 +161,9 @@ razor_set_open_files(struct razor_set *set, const char *filename)
struct array *array;
int fd;
+ assert (set != NULL);
+ assert (filename != NULL);
+
fd = open(filename, O_RDONLY);
if (fstat(fd, &stat) < 0)
return -1;
@@ -186,6 +193,8 @@ razor_set_destroy(struct razor_set *set)
struct array *a;
int i;
+ assert (set != NULL);
+
if (set->header) {
for (i = 0; set->header->sections[i].type; i++)
;
@@ -340,6 +349,9 @@ razor_versioncmp(const char *s1, const char *s2)
long n1, n2;
int res;
+ assert (s1 != NULL);
+ assert (s2 != NULL);
+
n1 = strtol(s1, (char **) &p1, 10);
n2 = strtol(s2, (char **) &p2, 10);
@@ -377,6 +389,9 @@ razor_set_get_package(struct razor_set *set, const char *package)
struct razor_package *p;
const char *name, *version, *arch;
+ assert (set != NULL);
+ assert (package != NULL);
+
pi = razor_package_iterator_create(set);
while (razor_package_iterator_next(pi, &p, &name, &version, &arch)) {
if (strcmp(package, name) == 0)
@@ -395,6 +410,9 @@ razor_package_get_details(struct razor_set *set,
{
const char *pool = set->details_string_pool.data;
+ assert (set != NULL);
+ assert (package != NULL);
+
if (summary != NULL)
*summary = &pool[package->summary];
if (description != NULL)
@@ -408,6 +426,8 @@ razor_package_get_details(struct razor_set *set,
RAZOR_EXPORT const char *
razor_property_relation_to_string(struct razor_property *p)
{
+ assert (p != NULL);
+
switch (p->flags & RAZOR_PROPERTY_RELATION_MASK) {
case RAZOR_PROPERTY_LESS:
return "<";
@@ -432,6 +452,8 @@ razor_property_relation_to_string(struct razor_property *p)
RAZOR_EXPORT const char *
razor_property_type_to_string(struct razor_property *p)
{
+ assert (p != NULL);
+
switch (p->flags & RAZOR_PROPERTY_TYPE_MASK) {
case RAZOR_PROPERTY_REQUIRES:
return "requires";
@@ -454,6 +476,10 @@ razor_set_find_entry(struct razor_set *set,
const char *n, *pool = set->file_string_pool.data;
int len;
+ assert (set != NULL);
+ assert (dir != NULL);
+ assert (pattern != NULL);
+
e = (struct razor_entry *) set->files.data + dir->start;
do {
n = pool + e->name;
@@ -498,6 +524,8 @@ razor_set_list_files(struct razor_set *set, const char *pattern)
struct razor_entry *e;
char buffer[512], *p, *base;
+ assert (set != NULL);
+
if (pattern == NULL || !strcmp (pattern, "/")) {
buffer[0] = '\0';
list_dir(set, set->files.data, buffer, NULL);
@@ -585,6 +613,9 @@ razor_set_list_package_files(struct razor_set *set, const char *name)
uint32_t end;
char buffer[512];
+ assert (set != NULL);
+ assert (name != NULL);
+
package = razor_set_get_package(set, name);
/* TODO: we should return the error to the caller */
if (!package)
@@ -610,6 +641,9 @@ razor_set_diff(struct razor_set *set, struct razor_set *upstream,
const char *name1, *name2, *version1, *version2, *arch1, *arch2;
int res;
+ assert (set != NULL);
+ assert (upstream != NULL);
+
pi1 = razor_package_iterator_create(set);
pi2 = razor_package_iterator_create(upstream);
@@ -663,6 +697,9 @@ razor_set_create_remove_iterator(struct razor_set *set,
struct razor_package_query *query;
struct razor_package_iterator *pi;
+ assert (set != NULL);
+ assert (next != NULL);
+
query = razor_package_query_create(set);
razor_set_diff(next, set, add_new_package, query);
@@ -683,6 +720,9 @@ razor_set_create_install_iterator(struct razor_set *set,
struct razor_package_query *query;
struct razor_package_iterator *pi;
+ assert (set != NULL);
+ assert (next != NULL);
+
query = razor_package_query_create(next);
razor_set_diff(set, next, add_new_package, query);
diff --git a/librazor/root.c b/librazor/root.c
index cff1994..d574539 100644
--- a/librazor/root.c
+++ b/librazor/root.c
@@ -24,6 +24,8 @@
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
+#include <assert.h>
+
#include "razor.h"
#include "razor-internal.h"
@@ -49,6 +51,8 @@ razor_root_create(const char *root)
struct razor_set *set;
char path[PATH_MAX], details_path[PATH_MAX], files_path[PATH_MAX];
+ assert (root != NULL);
+
if (stat(root, &buf) < 0) {
if (mkdir(root, 0777) < 0) {
fprintf(stderr,
@@ -100,6 +104,8 @@ razor_root_open(const char *root)
{
struct razor_root *image;
+ assert (root != NULL);
+
image = malloc(sizeof *image);
if (image == NULL)
return NULL;
@@ -140,6 +146,8 @@ razor_root_open_read_only(const char *root)
{
char path[PATH_MAX];
+ assert (root != NULL);
+
snprintf(path, sizeof path, "%s%s/%s",
root, razor_root_path, system_repo_filename);
@@ -149,12 +157,16 @@ razor_root_open_read_only(const char *root)
RAZOR_EXPORT struct razor_set *
razor_root_get_system_set(struct razor_root *root)
{
+ assert (root != NULL);
+
return root->system;
}
RAZOR_EXPORT int
razor_root_close(struct razor_root *root)
{
+ assert (root != NULL);
+
razor_set_destroy(root->system);
unlink(root->new_path);
close(root->fd);
@@ -166,6 +178,9 @@ razor_root_close(struct razor_root *root)
RAZOR_EXPORT void
razor_root_update(struct razor_root *root, struct razor_set *next)
{
+ assert (root != NULL);
+ assert (next != NULL);
+
razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN);
root->next = next;
@@ -178,6 +193,8 @@ razor_root_update(struct razor_root *root, struct razor_set *next)
RAZOR_EXPORT int
razor_root_commit(struct razor_root *root)
{
+ assert (root != NULL);
+
/* Make it so. */
rename(root->new_path, root->path);
printf("renamed %s to %s\n", root->new_path, root->path);
diff --git a/librazor/rpm.c b/librazor/rpm.c
index 7eb5b01..9435354 100644
--- a/librazor/rpm.c
+++ b/librazor/rpm.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <arpa/inet.h>
#include <zlib.h>
+#include <assert.h>
#include "razor.h"
#include "razor-internal.h"
@@ -357,6 +358,8 @@ razor_rpm_open(const char *filename)
const char *name;
int fd;
+ assert (filename != NULL);
+
rpm = malloc(sizeof *rpm);
if (rpm == NULL)
return NULL;
@@ -713,6 +716,9 @@ razor_rpm_install(struct razor_rpm *rpm, const char *root)
char *path;
size_t filesize;
+ assert (rpm != NULL);
+ assert (root != NULL);
+
installer.rpm = rpm;
installer.root = root;
@@ -771,6 +777,8 @@ razor_rpm_close(struct razor_rpm *rpm)
{
int err;
+ assert (rpm != NULL);
+
free(rpm->dirs);
err = munmap(rpm->map, rpm->size);
free(rpm);
@@ -786,6 +794,9 @@ razor_importer_add_rpm(struct razor_importer *importer, struct razor_rpm *rpm)
const uint32_t *epoch;
char evr[128], buf[16];
+ assert (importer != NULL);
+ assert (rpm != NULL);
+
name = razor_rpm_get_indirect(rpm, RPMTAG_NAME, NULL);
epoch = razor_rpm_get_indirect(rpm, RPMTAG_EPOCH, NULL);
version = razor_rpm_get_indirect(rpm, RPMTAG_VERSION, NULL);
diff --git a/librazor/transaction.c b/librazor/transaction.c
index 0e8342d..11ccc74 100644
--- a/librazor/transaction.c
+++ b/librazor/transaction.c
@@ -32,6 +32,7 @@
#include <errno.h>
#include <ctype.h>
#include <fnmatch.h>
+#include <assert.h>
#include "razor-internal.h"
#include "razor.h"
@@ -188,6 +189,9 @@ RAZOR_EXPORT void
razor_transaction_install_package(struct razor_transaction *trans,
struct razor_package *package)
{
+ assert (trans != NULL);
+ assert (package != NULL);
+
transaction_set_install_package(&trans->upstream, package);
trans->changes++;
}
@@ -196,6 +200,9 @@ RAZOR_EXPORT void
razor_transaction_remove_package(struct razor_transaction *trans,
struct razor_package *package)
{
+ assert (trans != NULL);
+ assert (package != NULL);
+
transaction_set_remove_package(&trans->system, package);
trans->changes++;
}
@@ -206,6 +213,9 @@ razor_transaction_update_package(struct razor_transaction *trans,
{
struct razor_package *spkgs, *upkgs, *end;
+ assert (trans != NULL);
+ assert (package != NULL);
+
spkgs = trans->system.set->packages.data;
upkgs = trans->upstream.set->packages.data;
end = trans->system.set->packages.data +
@@ -532,6 +542,8 @@ razor_transaction_update_all(struct razor_transaction *trans)
struct razor_package *p;
int i, count;
+ assert (trans != NULL);
+
count = trans->system.set->packages.size / sizeof *p;
for (i = 0; i < count; i++)
trans->system.packages[i] |= TRANS_PACKAGE_UPDATE;
@@ -868,6 +880,8 @@ razor_transaction_finish(struct razor_transaction *trans)
RAZOR_EXPORT void
razor_transaction_destroy(struct razor_transaction *trans)
{
+ assert (trans != NULL);
+
transaction_set_release(&trans->system);
transaction_set_release(&trans->upstream);
free(trans);