commit 6a04dedb33120780e1f3083540c287c5855497c3
parent 1de90aa4cf92803490a661d82f59b1c40f756fec
Author: aabacchus <ben@bvnf.space>
Date: Sun, 23 Apr 2023 16:10:05 +0100
use assert
Diffstat:
4 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/checksum.c b/src/checksum.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <blake3.h>
#include <stdio.h>
#include <stdlib.h>
@@ -53,8 +54,7 @@ file_checksum(FILE *f) {
* is present (must download first) */
char *
source_generate_checksum(struct source *s) {
- if (s == NULL || s->type == SRC_INVAL)
- die("source struct not initialised");
+ assert(s);
if (s->type != SRC_HTTP && s->type != SRC_FILE)
return NULL; /* checksum not needed */
@@ -70,11 +70,7 @@ source_generate_checksum(struct source *s) {
/* returns 1 if all good, 0 if there is a checksum mismatch. */
int
verify_checksums(struct pkg *p) {
- if (p == NULL) {
- mylog("No sources");
- return 1;
- }
-
+ assert(p);
FILE *f = pkg_open_file(p->pkg_path, "checksums", "r");
if (f == NULL) {
if (p->n_need_checksums == 0)
@@ -83,6 +79,8 @@ verify_checksums(struct pkg *p) {
die2(p->pkg, "checksums needed but no checksum file");
}
+ assert(p->s);
+
char *buf = NULL;
size_t bufn = 0;
ssize_t n;
diff --git a/src/source.c b/src/source.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -10,8 +11,7 @@
* needed (eg git sources or local files in repo) */
static char *
source_get_cache(char *pkg, char *pkg_path, struct source *s, struct env *e) {
- if (s == NULL || s->type == SRC_INVAL)
- die("source struct not initialised");
+ assert(s);
switch (s->type) {
case SRC_HTTP:
diff --git a/src/source.h b/src/source.h
@@ -4,7 +4,6 @@
#include "ckiss.h"
enum pkg_source_types {
- SRC_INVAL = 0,
SRC_HTTP,
SRC_GIT,
SRC_FILE,
diff --git a/src/utils.c b/src/utils.c
@@ -361,6 +361,8 @@ setup_env(void) {
void
destroy_env(struct env *e) {
+ if (e == NULL)
+ return;
for (int i = 0; e->hooks && e->hooks[i] != NULL; i++)
free(e->hooks[i]);
free(e->hooks);