commit 1ec569fd785a1fb9b4addf0eccd0d291e57a8287 parent d4ebfd7c3b98dbeaa6340ba14e1064d96134d537 Author: Chris Bracken <chris@bracken.jp> Date: Fri, 20 Feb 2026 16:30:38 +0900 Add null-assertions for all non-nullable params Diffstat:
33 files changed, 347 insertions(+), 14 deletions(-)
diff --git a/src/format.c b/src/format.c @@ -1,5 +1,6 @@ #include "format.h" +#include <assert.h> #include <err.h> #include <stdlib.h> #include <string.h> @@ -7,6 +8,7 @@ #include <wchar.h> void print_time(FILE* out, time_t time, int timezone_offset) { + assert(out != NULL); // Reject any offset > 24 hours. if (timezone_offset < -1440 || timezone_offset > 1440) { warnx("invalid timezone offset: %d", timezone_offset); @@ -38,6 +40,7 @@ void print_time(FILE* out, time_t time, int timezone_offset) { } void print_time_z(FILE* out, time_t time) { + assert(out != NULL); struct tm tm_buf; struct tm* time_in = gmtime_r(&time, &tm_buf); if (!time_in) { @@ -54,6 +57,7 @@ void print_time_z(FILE* out, time_t time) { /* TODO: add timezone_offset to print_time_short. */ void print_time_short(FILE* out, time_t time) { + assert(out != NULL); struct tm tm_buf; struct tm* time_in = gmtime_r(&time, &tm_buf); if (!time_in) { @@ -69,6 +73,8 @@ void print_time_short(FILE* out, time_t time) { } void print_percent_encoded(FILE* out, const char* str) { + assert(out != NULL); + assert(str != NULL); static const char* hex_chars = "0123456789ABCDEF"; size_t str_len = strlen(str); @@ -85,6 +91,8 @@ void print_percent_encoded(FILE* out, const char* str) { } void print_xml_encoded(FILE* out, const char* str) { + assert(out != NULL); + assert(str != NULL); print_xml_encoded_len(out, str, -1, true); } @@ -92,6 +100,9 @@ void print_xml_encoded_len(FILE* out, const char* str, ssize_t str_len, bool output_crlf) { + assert(out != NULL); + assert(str != NULL); + size_t len = (str_len >= 0) ? (size_t)str_len : strlen(str); for (size_t i = 0; i < len && str[i] != '\0'; i++) { unsigned char c = (unsigned char)str[i]; @@ -130,6 +141,8 @@ void print_xml_encoded_len(FILE* out, } void print_gopher_text(FILE* out, const char* str, bool output_lf) { + assert(out != NULL); + assert(str != NULL); print_gopher_text_len(out, str, -1, output_lf); } @@ -137,6 +150,9 @@ void print_gopher_text_len(FILE* out, const char* str, ssize_t str_len, bool output_lf) { + assert(out != NULL); + assert(str != NULL); + size_t len = (str_len >= 0) ? (size_t)str_len : strlen(str); bool start_of_line = true; for (size_t i = 0; i < len && str[i] != '\0'; i++) { @@ -155,6 +171,9 @@ void print_gopher_text_len(FILE* out, } void print_gopher_link(FILE* out, const char* str) { + assert(out != NULL); + assert(str != NULL); + for (size_t i = 0; str[i] != '\0'; i++) { char c = str[i]; if (c == '|') { @@ -173,6 +192,9 @@ void print_gopher_link_padded(FILE* out, const char* str, size_t width, char pad_char) { + assert(out != NULL); + assert(str != NULL); + if (width == 0) { return; } diff --git a/src/git/commit.c b/src/git/commit.c @@ -1,5 +1,6 @@ #include "git/commit.h" +#include <assert.h> #include <err.h> #include <git2/commit.h> #include <git2/diff.h> @@ -13,6 +14,8 @@ #include "utils.h" GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) { + assert(oid != NULL); + assert(repo != NULL); GitCommit* commit = ecalloc(1, sizeof(GitCommit)); git_commit* gcommit = NULL; if (git_commit_lookup(&gcommit, repo, oid)) { diff --git a/src/git/delta.c b/src/git/delta.c @@ -1,5 +1,6 @@ #include "git/delta.h" +#include <assert.h> #include <git2/diff.h> #include <git2/patch.h> #include <stdlib.h> @@ -28,6 +29,7 @@ static char* gitdelta_graph(const GitDelta* delta, static GitHunkLine* githunkline_create(git_patch* patch, size_t hunk_id, size_t line_id) { + assert(patch != NULL); const git_diff_line* line; if (git_patch_get_line_in_hunk(&line, patch, hunk_id, line_id)) { return NULL; @@ -52,6 +54,7 @@ static void githunkline_free(GitHunkLine* hunk_line) { } static GitHunk* githunk_create(git_patch* patch, size_t hunk_id) { + assert(patch != NULL); const git_diff_hunk* hunk; size_t line_count; if (git_patch_get_hunk(&hunk, &line_count, patch, hunk_id)) { @@ -88,6 +91,7 @@ static void githunk_free(GitHunk* hunk) { } static char status_for_delta(const git_diff_delta* delta) { + assert(delta != NULL); switch (delta->status) { case GIT_DELTA_ADDED: return 'A'; @@ -112,6 +116,7 @@ static char status_for_delta(const git_diff_delta* delta) { } GitDelta* gitdelta_create(git_patch* patch) { + assert(patch != NULL); GitDelta* delta = ecalloc(1, sizeof(GitDelta)); const git_diff_delta* git_delta = git_patch_get_delta(patch); @@ -181,6 +186,7 @@ static char* gitdelta_graph(const GitDelta* delta, size_t length, char c, size_t max_width) { + assert(delta != NULL); size_t changed = delta->addcount + delta->delcount; if (changed > max_width && length > 0) { length = (length * max_width) / changed; @@ -194,9 +200,11 @@ static char* gitdelta_graph(const GitDelta* delta, } char* gitdelta_added_graph(const GitDelta* delta, size_t max_width) { + assert(delta != NULL); return gitdelta_graph(delta, delta->addcount, '+', max_width); } char* gitdelta_deleted_graph(const GitDelta* delta, size_t max_width) { + assert(delta != NULL); return gitdelta_graph(delta, delta->delcount, '-', max_width); } diff --git a/src/git/file.c b/src/git/file.c @@ -1,5 +1,6 @@ #include "git/file.h" +#include <assert.h> #include <stdlib.h> #include <string.h> @@ -14,6 +15,9 @@ GitFile* gitfile_create(FileType type, ssize_t size_bytes, ssize_t size_lines, const char* content) { + assert(display_path != NULL); + assert(repo_path != NULL); + GitFile* file = ecalloc(1, sizeof(GitFile)); file->type = type; file->mode = mode ? estrdup(mode) : NULL; diff --git a/src/git/git.c b/src/git/git.c @@ -1,5 +1,6 @@ #include "git.h" +#include <assert.h> #include <err.h> #include <git2.h> #include <stdlib.h> @@ -47,6 +48,7 @@ static bool gitrepo_walk_tree_files(git_repository* repo, void* user_data); static void libgit2_initialize(Git* git) { + assert(git != NULL); (void)git; /* do not search outside the git repository: GIT_CONFIG_LEVEL_APP is the highest level currently */ @@ -59,11 +61,13 @@ static void libgit2_initialize(Git* git) { } static void libgit2_shutdown(Git* git) { + assert(git != NULL); (void)git; git_libgit2_shutdown(); } Git* gout_git_create(const FileSystem* fs) { + assert(fs != NULL); Git* git = ecalloc(1, sizeof(Git)); git->impl = NULL; git->fs = fs; @@ -99,6 +103,9 @@ static void libgit2_for_repo(Git* git, const char* path, RepoCallback cb, void* user_data) { + assert(git != NULL); + assert(path != NULL); + assert(cb != NULL); git->impl = gitrepo_open_repository(path); git->repo = gitrepo_create_from_repository(git->fs, path, git->impl); cb(git, user_data); @@ -111,6 +118,8 @@ static void libgit2_for_repo(Git* git, static void libgit2_for_each_commit(Git* git, CommitCallback cb, void* user_data) { + assert(git != NULL); + assert(cb != NULL); git_repository* repo = (git_repository*)git->impl; git_oid start_oid; if (oid_for_spec(repo, "HEAD", &start_oid) != 0) { @@ -136,6 +145,9 @@ static void libgit2_for_commit(Git* git, const char* spec, CommitCallback cb, void* user_data) { + assert(git != NULL); + assert(spec != NULL); + assert(cb != NULL); git_repository* repo = (git_repository*)git->impl; git_oid start_oid; if (oid_for_spec(repo, spec, &start_oid) != 0) { @@ -160,6 +172,8 @@ static void libgit2_for_commit(Git* git, static void libgit2_for_each_reference(Git* git, ReferenceCallback cb, void* user_data) { + assert(git != NULL); + assert(cb != NULL); git_repository* repo = (git_repository*)git->impl; git_reference_iterator* it = NULL; if (git_reference_iterator_new(&it, repo) != 0) { @@ -201,6 +215,8 @@ static void libgit2_for_each_reference(Git* git, } static void libgit2_for_each_file(Git* git, FileCallback cb, void* user_data) { + assert(git != NULL); + assert(cb != NULL); git_repository* repo = (git_repository*)git->impl; git_commit* commit = NULL; git_oid id; @@ -225,6 +241,9 @@ static void libgit2_for_each_file(Git* git, FileCallback cb, void* user_data) { /* Utilities */ static int oid_for_spec(git_repository* repo, const char* spec, git_oid* oid) { + assert(repo != NULL); + assert(spec != NULL); + assert(oid != NULL); git_object* obj = NULL; if (git_revparse_single(&obj, repo, spec)) { return -1; @@ -235,7 +254,7 @@ static int oid_for_spec(git_repository* repo, const char* spec, git_oid* oid) { } static size_t string_count_lines(const char* str, ssize_t str_len) { - if (str_len <= 0) { + if (!str || str_len <= 0) { return 0; } size_t lines = 0; @@ -320,6 +339,11 @@ static bool gitrepo_walk_tree_files(git_repository* repo, const char* path, FileCallback cb, void* user_data) { + assert(repo != NULL); + assert(tree != NULL); + assert(path != NULL); + assert(cb != NULL); + for (size_t i = 0; i < git_tree_entrycount(tree); i++) { const git_tree_entry* entry = git_tree_entry_byindex(tree, i); if (!entry) { diff --git a/src/git/reference.c b/src/git/reference.c @@ -1,5 +1,6 @@ #include "git/reference.h" +#include <assert.h> #include <err.h> #include <git2/object.h> #include <git2/oid.h> @@ -14,6 +15,8 @@ GitReference* gitreference_create(git_repository* repo, git_reference* git_ref) { + assert(repo != NULL); + assert(git_ref != NULL); // Resolve git_ref to a direct reference. if (git_reference_type(git_ref) == GIT_REFERENCE_SYMBOLIC) { git_reference* direct_ref = NULL; diff --git a/src/git/repo.c b/src/git/repo.c @@ -1,5 +1,6 @@ #include "git/repo.h" +#include <assert.h> #include <err.h> #include <git2/blob.h> #include <git2/commit.h> @@ -61,6 +62,8 @@ static bool string_ends_with(const char* str, const char* suffix) { } static char* first_line_of_file(const FileSystem* fs, const char* path) { + assert(fs != NULL); + assert(path != NULL); FILE* f = fs->fopen(path, "r"); if (!f) { return estrdup(""); @@ -81,6 +84,7 @@ static char* first_line_of_file(const FileSystem* fs, const char* path) { } static char* gitrepo_name_from_path(const char* repo_path) { + assert(repo_path != NULL); char* path_copy = estrdup(repo_path); const char* filename = basename(path_copy); if (!filename) { @@ -92,6 +96,7 @@ static char* gitrepo_name_from_path(const char* repo_path) { } static char* gitrepo_shortname_from_name(const char* name) { + assert(name != NULL); char* short_name = estrdup(name); if (string_ends_with(short_name, ".git")) { size_t short_name_len = strlen(short_name); @@ -102,6 +107,8 @@ static char* gitrepo_shortname_from_name(const char* name) { } static bool gitrepo_has_blob(git_repository* repo, const char* file) { + assert(repo != NULL); + assert(file != NULL); git_object* obj = NULL; if (git_revparse_single(&obj, repo, file)) { return false; @@ -114,6 +121,8 @@ static bool gitrepo_has_blob(git_repository* repo, const char* file) { static const char* gitrepo_first_matching_file(git_repository* repo, const char** files, size_t files_len) { + assert(repo != NULL); + assert(files != NULL); for (size_t i = 0; i < files_len; i++) { const char* filename = files[i]; if (gitrepo_has_blob(repo, filename)) { @@ -126,6 +135,9 @@ static const char* gitrepo_first_matching_file(git_repository* repo, void gitrepo_load_filesystem_metadata(GitRepo* repo, const FileSystem* fs, const char* path) { + assert(repo != NULL); + assert(fs != NULL); + assert(path != NULL); char* repo_path = fs->realpath(path, NULL); if (!repo_path) { err(1, "realpath: %s", path); @@ -158,6 +170,8 @@ void gitrepo_load_filesystem_metadata(GitRepo* repo, } static void gitrepo_load_git_metadata(GitRepo* repo, git_repository* git_repo) { + assert(repo != NULL); + assert(git_repo != NULL); repo->submodules = estrdup( gitrepo_has_blob(git_repo, "HEAD:.gitmodules") ? ".gitmodules" : ""); repo->readme = @@ -178,6 +192,7 @@ static void gitrepo_load_git_metadata(GitRepo* repo, git_repository* git_repo) { } git_repository* gitrepo_open_repository(const char* path) { + assert(path != NULL); git_repository* repo = NULL; git_repository_open_flag_t kRepoOpenFlags = GIT_REPOSITORY_OPEN_NO_SEARCH; if (git_repository_open_ext(&repo, path, kRepoOpenFlags, NULL)) { @@ -189,6 +204,9 @@ git_repository* gitrepo_open_repository(const char* path) { GitRepo* gitrepo_create_from_repository(const FileSystem* fs, const char* path, void* git_repo) { + assert(fs != NULL); + assert(path != NULL); + assert(git_repo != NULL); GitRepo* repo = ecalloc(1, sizeof(GitRepo)); gitrepo_load_filesystem_metadata(repo, fs, path); gitrepo_load_git_metadata(repo, (git_repository*)git_repo); diff --git a/src/gout.c b/src/gout.c @@ -1,5 +1,6 @@ #include "gout.h" +#include <assert.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -18,6 +19,7 @@ static void reference_callback(const GitReference* ref, void* user_data); static void file_callback(const GitFile* file, void* user_data); GoutOptions* gout_options_create(int argc, const char* argv[]) { + assert(argv != NULL); GoutOptions options = { .repodir = NULL, .log_commit_limit = -1, @@ -98,6 +100,9 @@ void gout_options_free(GoutOptions* options) { } void gout_init(const GoutOptions* options, Git* git) { + assert(options != NULL); + assert(git != NULL); + const char* readonly_paths[] = {options->repodir}; size_t readonly_paths_count = 1; const char* readwrite_paths[2] = {".", NULL}; @@ -115,10 +120,14 @@ void gout_init(const GoutOptions* options, Git* git) { } void gout_run(const GoutOptions* options, Git* git) { + assert(options != NULL); + assert(git != NULL); git->for_repo(git, options->repodir, repo_callback, (void*)options); } static void repo_callback(Git* git, void* user_data) { + assert(git != NULL); + assert(user_data != NULL); const GoutOptions* options = (const GoutOptions*)user_data; RepoWriter* writer = repowriter_create(options->writer_type, git->repo, git->fs); @@ -142,16 +151,22 @@ static void repo_callback(Git* git, void* user_data) { } static void commit_callback(const GitCommit* ci, void* user_data) { + assert(ci != NULL); + assert(user_data != NULL); RepoWriter* writer = (RepoWriter*)user_data; repowriter_add_commit(writer, ci); } static void reference_callback(const GitReference* ref, void* user_data) { + assert(ref != NULL); + assert(user_data != NULL); RepoWriter* writer = (RepoWriter*)user_data; repowriter_add_reference(writer, ref); } static void file_callback(const GitFile* file, void* user_data) { + assert(file != NULL); + assert(user_data != NULL); RepoWriter* writer = (RepoWriter*)user_data; repowriter_add_file(writer, file); } diff --git a/src/gout_index.c b/src/gout_index.c @@ -1,5 +1,6 @@ #include "gout_index.h" +#include <assert.h> #include <err.h> #include <stddef.h> #include <stdlib.h> @@ -13,6 +14,7 @@ static void repo_callback(Git* git, void* user_data); GoutIndexOptions* gout_index_options_create(int argc, const char* argv[]) { + assert(argv != NULL); GoutIndexOptions options = { .repo_dirs = NULL, .repo_dir_count = 0, @@ -56,6 +58,8 @@ void gout_index_options_free(GoutIndexOptions* options) { } void gout_index_init(const GoutIndexOptions* options, Git* git) { + assert(options != NULL); + assert(git != NULL); const char** readonly_paths = options->repo_dirs; size_t readonly_paths_count = options->repo_dir_count; const char* readwrite_paths[1] = {NULL}; @@ -68,6 +72,8 @@ void gout_index_init(const GoutIndexOptions* options, Git* git) { } void gout_index_run(const GoutIndexOptions* options, Git* git) { + assert(options != NULL); + assert(git != NULL); IndexWriter* writer = indexwriter_create(options->writer_type, stdout); if (options->me_url) { indexwriter_set_me_url(writer, options->me_url); @@ -81,6 +87,8 @@ void gout_index_run(const GoutIndexOptions* options, Git* git) { } static void repo_callback(Git* git, void* user_data) { + assert(git != NULL); + assert(user_data != NULL); IndexWriter* writer = (IndexWriter*)user_data; indexwriter_add_repo(writer, git->repo); } diff --git a/src/security.c b/src/security.c @@ -1,5 +1,6 @@ #include "security.h" +#include <assert.h> #include <err.h> #ifdef __OpenBSD__ @@ -21,6 +22,9 @@ void restrict_filesystem_access(const char* readonly_paths[], size_t readonly_paths_count, const char* readwrite_paths[], size_t readwrite_paths_count) { + assert(readonly_paths != NULL || readonly_paths_count == 0); + assert(readwrite_paths != NULL || readwrite_paths_count == 0); + for (size_t i = 0; i < readonly_paths_count; i++) { const char* path = readonly_paths[i]; if (unveil(path, "r") == -1) { diff --git a/src/utils.c b/src/utils.c @@ -1,5 +1,6 @@ #include "utils.h" +#include <assert.h> #include <err.h> #include <errno.h> #include <limits.h> @@ -61,6 +62,7 @@ void* ecalloc(size_t count, size_t size) { } char* estrdup(const char* s) { + assert(s != NULL); char* out_str = strdup(s); if (!out_str) { err(1, "strdup"); @@ -69,6 +71,8 @@ char* estrdup(const char* s) { } size_t estrlcpy(char* dst, const char* src, size_t dsize) { + assert(dst != NULL); + assert(src != NULL); size_t len = strlcpy(dst, src, dsize); if (len >= dsize) { errx(1, "string truncated: '%s'", src); diff --git a/src/writer/atom/atom.c b/src/writer/atom/atom.c @@ -1,5 +1,6 @@ #include "atom.h" +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -15,6 +16,8 @@ struct Atom { }; Atom* atom_create(const GitRepo* repo, FILE* out) { + assert(repo != NULL); + assert(out != NULL); Atom* atom = ecalloc(1, sizeof(Atom)); atom->repo = repo; atom->baseurl = ""; @@ -24,15 +27,21 @@ Atom* atom_create(const GitRepo* repo, FILE* out) { } void atom_free(Atom* atom) { + if (!atom) { + return; + } atom->out = NULL; free(atom); } void atom_set_baseurl(Atom* atom, const char* baseurl) { + assert(atom != NULL); + assert(baseurl != NULL); atom->baseurl = baseurl; } void atom_begin(Atom* atom) { + assert(atom != NULL); fprintf(atom->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(atom->out, "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"); fprintf(atom->out, "<title>"); @@ -52,6 +61,11 @@ void atom_add_commit(Atom* atom, const char* path, const char* content_type, const char* tag) { + assert(atom != NULL); + assert(commit != NULL); + assert(path != NULL); + assert(content_type != NULL); + FILE* out = atom->out; if (atom->remaining_commits == 0) { return; @@ -126,5 +140,6 @@ void atom_add_commit(Atom* atom, } void atom_end(Atom* atom) { + assert(atom != NULL); fprintf(atom->out, "</feed>\n"); } diff --git a/src/writer/cache/cache.c b/src/writer/cache/cache.c @@ -1,5 +1,6 @@ #include "cache.h" +#include <assert.h> #include <err.h> #include <stdlib.h> #include <string.h> @@ -22,6 +23,8 @@ struct Cache { Cache* cache_create(FILE* cache_in, FILE* cache_out, WriteCommitRow write_func) { + assert(cache_out != NULL); + assert(write_func != NULL); Cache* cache = ecalloc(1, sizeof(Cache)); cache->can_add_commits = true; cache->write_commit_row = write_func; @@ -61,10 +64,13 @@ void cache_free(Cache* cache) { } bool cache_can_add_commits(const Cache* cache) { + assert(cache != NULL); return cache->can_add_commits; } void cache_add_commit_row(Cache* cache, const GitCommit* commit) { + assert(cache != NULL); + assert(commit != NULL); // The first row of the file is the last OID. if (!cache->wrote_lastoid_out) { fprintf(cache->cache_out, "%s\n", commit->oid); @@ -81,6 +87,7 @@ void cache_add_commit_row(Cache* cache, const GitCommit* commit) { } void cache_finish(Cache* cache) { + assert(cache != NULL); if (cache->cache_in) { // If we didn't write any records, copy the previous cache lastoid. if (!cache->wrote_lastoid_out) { @@ -102,6 +109,8 @@ void cache_finish(Cache* cache) { } void cache_copy_log(FILE* fcache, FILE* out) { + assert(fcache != NULL); + assert(out != NULL); // Copy the log lines to out. char* line = NULL; size_t len = 0; diff --git a/src/writer/gopher/commit.c b/src/writer/gopher/commit.c @@ -1,5 +1,6 @@ #include "writer/gopher/commit.h" +#include <assert.h> #include <err.h> #include <limits.h> #include <stdbool.h> @@ -39,6 +40,9 @@ GopherCommit* gopher_commit_create(const GitRepo* repo, const FileSystem* fs, const char* oid, const char* title) { + assert(repo != NULL); + assert(fs != NULL); + assert(oid != NULL); GopherCommit* commit = ecalloc(1, sizeof(GopherCommit)); commit->fs = fs; char filename[PATH_MAX]; @@ -71,11 +75,14 @@ void gopher_commit_free(GopherCommit* commit) { } void gopher_commit_begin(GopherCommit* commit) { + assert(commit != NULL); gopher_page_begin(commit->page); } void gopher_commit_add_commit(GopherCommit* commit, const GitCommit* git_commit) { + assert(commit != NULL); + assert(git_commit != NULL); FILE* out = commit->out; gopher_commit_write_summary(commit, git_commit); @@ -102,12 +109,14 @@ void gopher_commit_set_diff_limits(GopherCommit* commit, uint64_t max_files, uint64_t max_deltas, uint64_t max_delta_lines) { + assert(commit != NULL); commit->max_files = max_files; commit->max_deltas = max_deltas; commit->max_delta_lines = max_delta_lines; } void gopher_commit_end(GopherCommit* commit) { + assert(commit != NULL); gopher_page_end(commit->page); } diff --git a/src/writer/gopher/fileblob.c b/src/writer/gopher/fileblob.c @@ -1,5 +1,6 @@ #include "writer/gopher/fileblob.h" +#include <assert.h> #include <err.h> #include <libgen.h> #include <limits.h> @@ -22,6 +23,9 @@ struct GopherFileBlob { GopherFileBlob* gopher_fileblob_create(const GitRepo* repo, const FileSystem* fs, const char* path) { + assert(repo != NULL); + assert(fs != NULL); + assert(path != NULL); if (!is_safe_repo_path(path)) { errx(1, "unsafe path: %s", path); } @@ -78,10 +82,13 @@ void gopher_fileblob_free(GopherFileBlob* blob) { } void gopher_fileblob_begin(GopherFileBlob* blob) { + assert(blob != NULL); gopher_page_begin(blob->page); } void gopher_fileblob_add_file(GopherFileBlob* blob, const GitFile* file) { + assert(blob != NULL); + assert(file != NULL); FILE* out = blob->out; char path[PATH_MAX]; @@ -104,10 +111,10 @@ void gopher_fileblob_add_file(GopherFileBlob* blob, const GitFile* file) { return; } + assert(file->content != NULL); size_t i = 0; - const char* content = file->content; - const char* end = content + file->size_bytes; - const char* cur_line = content; + const char* end = file->content + file->size_bytes; + const char* cur_line = file->content; while (cur_line < end) { const char* next_line = memchr(cur_line, '\n', end - cur_line); size_t len = (next_line ? next_line : end) - cur_line; @@ -126,5 +133,6 @@ void gopher_fileblob_add_file(GopherFileBlob* blob, const GitFile* file) { } void gopher_fileblob_end(GopherFileBlob* blob) { + assert(blob != NULL); gopher_page_end(blob->page); } diff --git a/src/writer/gopher/files.c b/src/writer/gopher/files.c @@ -1,5 +1,6 @@ #include "writer/gopher/files.h" +#include <assert.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -17,6 +18,8 @@ struct GopherFiles { }; GopherFiles* gopher_files_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); GopherFiles* files = ecalloc(1, sizeof(GopherFiles)); files->repo = repo; files->fs = fs; @@ -40,6 +43,7 @@ void gopher_files_free(GopherFiles* files) { } void gopher_files_begin(GopherFiles* files) { + assert(files != NULL); FILE* out = files->out; gopher_page_begin(files->page); fprintf(out, "%-10.10s ", "Mode"); @@ -48,6 +52,8 @@ void gopher_files_begin(GopherFiles* files) { } void gopher_files_add_file(GopherFiles* files, const GitFile* file) { + assert(files != NULL); + assert(file != NULL); FILE* out = files->out; fprintf(out, "[1|%s", file->mode); fprintf(out, " "); @@ -67,5 +73,6 @@ void gopher_files_add_file(GopherFiles* files, const GitFile* file) { } void gopher_files_end(GopherFiles* files) { + assert(files != NULL); gopher_page_end(files->page); } diff --git a/src/writer/gopher/index_writer.c b/src/writer/gopher/index_writer.c @@ -1,5 +1,6 @@ #include "writer/gopher/index_writer.h" +#include <assert.h> #include <stdio.h> #include <stdlib.h> @@ -12,6 +13,7 @@ struct GopherIndexWriter { }; GopherIndexWriter* gopher_indexwriter_create(FILE* out) { + assert(out != NULL); GopherIndexWriter* writer = ecalloc(1, sizeof(GopherIndexWriter)); writer->index = gopher_repoindex_create(out); return writer; @@ -27,14 +29,18 @@ void gopher_indexwriter_free(GopherIndexWriter* writer) { } void gopher_indexwriter_begin(GopherIndexWriter* writer) { + assert(writer != NULL); gopher_repoindex_begin(writer->index); } void gopher_indexwriter_add_repo(GopherIndexWriter* writer, const GitRepo* repo) { + assert(writer != NULL); + assert(repo != NULL); gopher_repoindex_add_repo(writer->index, repo); } void gopher_indexwriter_end(GopherIndexWriter* writer) { + assert(writer != NULL); gopher_repoindex_end(writer->index); } diff --git a/src/writer/gopher/log.c b/src/writer/gopher/log.c @@ -1,5 +1,6 @@ #include "writer/gopher/log.h" +#include <assert.h> #include <err.h> #include <stdint.h> #include <stdlib.h> @@ -33,6 +34,8 @@ static const mode_t kReadWriteAll = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; GopherLog* gopher_log_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); GopherLog* log = ecalloc(1, sizeof(GopherLog)); log->repo = repo; log->fs = fs; @@ -68,6 +71,8 @@ void gopher_log_free(GopherLog* log) { } void gopher_log_set_cachefile(GopherLog* log, const char* cachefile) { + assert(log != NULL); + assert(cachefile != NULL); log->cache_path = estrdup(cachefile); log->temp_cache_path = estrdup(kTempCachePath); @@ -86,14 +91,17 @@ void gopher_log_set_cachefile(GopherLog* log, const char* cachefile) { } void gopher_log_set_commit_limit(GopherLog* log, size_t count) { + assert(log != NULL); log->remaining_commits = count; } bool gopher_log_can_add_commits(const GopherLog* log) { + assert(log != NULL); return !log->cache || cache_can_add_commits(log->cache); } void gopher_log_begin(GopherLog* log) { + assert(log != NULL); FILE* out = log->out; gopher_page_begin(log->page); fprintf(out, "%-16.16s ", "Date"); @@ -102,6 +110,8 @@ void gopher_log_begin(GopherLog* log) { } void gopher_log_add_commit(GopherLog* log, const GitCommit* commit) { + assert(log != NULL); + assert(commit != NULL); if (log->cache) { cache_add_commit_row(log->cache, commit); } else if (log->remaining_commits > 0) { @@ -113,6 +123,7 @@ void gopher_log_add_commit(GopherLog* log, const GitCommit* commit) { } void gopher_log_end(GopherLog* log) { + assert(log != NULL); FILE* out = log->out; if (log->cache) { cache_finish(log->cache); @@ -150,6 +161,8 @@ void gopher_log_end(GopherLog* log) { } static void write_commit_row(FILE* out, const GitCommit* commit) { + assert(out != NULL); + assert(commit != NULL); fprintf(out, "[1|"); print_time_short(out, commit->author_time); fprintf(out, " "); diff --git a/src/writer/gopher/page.c b/src/writer/gopher/page.c @@ -1,5 +1,6 @@ #include "writer/gopher/page.h" +#include <assert.h> #include <stdbool.h> #include <stdlib.h> @@ -19,6 +20,11 @@ GopherPage* gopher_page_create(FILE* out, const FileSystem* fs, const char* title, const char* relpath) { + assert(out != NULL); + assert(repo != NULL); + assert(fs != NULL); + assert(title != NULL); + assert(relpath != NULL); GopherPage* page = ecalloc(1, sizeof(GopherPage)); page->out = out; page->repo = repo; @@ -40,6 +46,7 @@ void gopher_page_free(GopherPage* page) { } void gopher_page_begin(GopherPage* page) { + assert(page != NULL); FILE* out = page->out; print_gopher_text(out, page->title, false); const char* short_name = page->repo->short_name; @@ -84,7 +91,6 @@ void gopher_page_begin(GopherPage* page) { } void gopher_page_end(GopherPage* page) { - if (!page) { - return; - } + assert(page != NULL); + (void)page; } diff --git a/src/writer/gopher/refs.c b/src/writer/gopher/refs.c @@ -1,5 +1,6 @@ #include "writer/gopher/refs.h" +#include <assert.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -36,6 +37,9 @@ static void gopher_refstable_end(GopherRefsTable* table); static GopherRefsTable* gopher_refstable_create(const char* title, const char* id, FILE* out) { + assert(title != NULL); + assert(id != NULL); + assert(out != NULL); GopherRefsTable* table = ecalloc(1, sizeof(GopherRefsTable)); table->title = estrdup(title); table->id = estrdup(id); @@ -55,6 +59,7 @@ static void gopher_refstable_free(GopherRefsTable* table) { } static void gopher_refstable_begin(GopherRefsTable* table) { + assert(table != NULL); FILE* out = table->out; fprintf(out, "%s\n", table->title); fprintf(out, " %-32.32s", "Name"); @@ -64,6 +69,8 @@ static void gopher_refstable_begin(GopherRefsTable* table) { static void gopher_refstable_add_ref(GopherRefsTable* table, const GitReference* ref) { + assert(table != NULL); + assert(ref != NULL); GitCommit* commit = ref->commit; FILE* out = table->out; @@ -77,11 +84,14 @@ static void gopher_refstable_add_ref(GopherRefsTable* table, } static void gopher_refstable_end(GopherRefsTable* table) { + assert(table != NULL); FILE* out = table->out; fprintf(out, "\n"); } GopherRefs* gopher_refs_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); GopherRefs* refs = ecalloc(1, sizeof(GopherRefs)); refs->repo = repo; refs->fs = fs; @@ -109,10 +119,13 @@ void gopher_refs_free(GopherRefs* refs) { } void gopher_refs_begin(GopherRefs* refs) { + assert(refs != NULL); gopher_page_begin(refs->page); } void gopher_refs_add_ref(GopherRefs* refs, const GitReference* ref) { + assert(refs != NULL); + assert(ref != NULL); switch (ref->type) { case kReftypeBranch: if (!refs->branches) { @@ -138,6 +151,7 @@ void gopher_refs_add_ref(GopherRefs* refs, const GitReference* ref) { } void gopher_refs_end(GopherRefs* refs) { + assert(refs != NULL); if (refs->branches) { gopher_refstable_end(refs->branches); gopher_refstable_free(refs->branches); diff --git a/src/writer/gopher/repo_index.c b/src/writer/gopher/repo_index.c @@ -1,5 +1,6 @@ #include "writer/gopher/repo_index.h" +#include <assert.h> #include <stdlib.h> #include "format.h" @@ -10,6 +11,7 @@ struct GopherRepoIndex { }; GopherRepoIndex* gopher_repoindex_create(FILE* out) { + assert(out != NULL); GopherRepoIndex* index = ecalloc(1, sizeof(GopherRepoIndex)); index->out = out; return index; @@ -24,6 +26,7 @@ void gopher_repoindex_free(GopherRepoIndex* index) { } void gopher_repoindex_begin(GopherRepoIndex* index) { + assert(index != NULL); FILE* out = index->out; fprintf(out, "Repositories\n\n"); fprintf(out, "%-20.20s ", "Name"); @@ -32,6 +35,8 @@ void gopher_repoindex_begin(GopherRepoIndex* index) { } void gopher_repoindex_add_repo(GopherRepoIndex* index, const GitRepo* repo) { + assert(index != NULL); + assert(repo != NULL); FILE* out = index->out; fprintf(out, "[1|"); print_gopher_link_padded(out, repo->short_name, 20, ' '); @@ -45,8 +50,6 @@ void gopher_repoindex_add_repo(GopherRepoIndex* index, const GitRepo* repo) { } void gopher_repoindex_end(GopherRepoIndex* index) { - // Stop the compiler from complaining about unused parameter. - if (!index) { - return; - } + assert(index != NULL); + (void)index; } diff --git a/src/writer/gopher/repo_writer.c b/src/writer/gopher/repo_writer.c @@ -1,5 +1,6 @@ #include "writer/gopher/repo_writer.h" +#include <assert.h> #include <err.h> #include <limits.h> #include <stdio.h> @@ -32,6 +33,8 @@ struct GopherRepoWriter { GopherRepoWriter* gopher_repowriter_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); GopherRepoWriter* writer = ecalloc(1, sizeof(GopherRepoWriter)); writer->repo = repo; writer->fs = fs; @@ -78,21 +81,27 @@ void gopher_repowriter_free(GopherRepoWriter* writer) { void gopher_repowriter_set_log_cachefile(GopherRepoWriter* writer, const char* cachefile) { + assert(writer != NULL); + assert(cachefile != NULL); gopher_log_set_cachefile(writer->log, cachefile); } void gopher_repowriter_set_log_commit_limit(GopherRepoWriter* writer, size_t count) { + assert(writer != NULL); gopher_log_set_commit_limit(writer->log, count); } void gopher_repowriter_set_baseurl(GopherRepoWriter* writer, const char* baseurl) { + assert(writer != NULL); + assert(baseurl != NULL); atom_set_baseurl(writer->atom, baseurl); atom_set_baseurl(writer->tags, baseurl); } void gopher_repowriter_begin(GopherRepoWriter* writer) { + assert(writer != NULL); writer->fs->mkdir("commit", S_IRWXU | S_IRWXG | S_IRWXO); writer->fs->mkdir("file", S_IRWXU | S_IRWXG | S_IRWXO); @@ -105,6 +114,8 @@ void gopher_repowriter_begin(GopherRepoWriter* writer) { void gopher_repowriter_add_commit(GopherRepoWriter* writer, const GitCommit* git_commit) { + assert(writer != NULL); + assert(git_commit != NULL); char filename[PATH_MAX]; int r = snprintf(filename, sizeof(filename), "%s.gph", git_commit->oid); if (r < 0 || (size_t)r >= sizeof(filename)) { @@ -127,6 +138,8 @@ void gopher_repowriter_add_commit(GopherRepoWriter* writer, void gopher_repowriter_add_reference(GopherRepoWriter* writer, const GitReference* ref) { + assert(writer != NULL); + assert(ref != NULL); gopher_refs_add_ref(writer->refs, ref); if (ref->type == kReftypeTag) { GitCommit* commit = ref->commit; @@ -142,6 +155,8 @@ void gopher_repowriter_add_reference(GopherRepoWriter* writer, } void gopher_repowriter_add_file(GopherRepoWriter* writer, const GitFile* file) { + assert(writer != NULL); + assert(file != NULL); gopher_files_add_file(writer->files, file); GopherFileBlob* blob = @@ -153,6 +168,7 @@ void gopher_repowriter_add_file(GopherRepoWriter* writer, const GitFile* file) { } void gopher_repowriter_end(GopherRepoWriter* writer) { + assert(writer != NULL); gopher_refs_end(writer->refs); gopher_log_end(writer->log); atom_end(writer->atom); diff --git a/src/writer/html/commit.c b/src/writer/html/commit.c @@ -1,5 +1,6 @@ #include "writer/html/commit.h" +#include <assert.h> #include <err.h> #include <limits.h> #include <stdbool.h> @@ -42,6 +43,9 @@ HtmlCommit* html_commit_create(const GitRepo* repo, const FileSystem* fs, const char* oid, const char* title) { + assert(repo != NULL); + assert(fs != NULL); + assert(oid != NULL); HtmlCommit* commit = ecalloc(1, sizeof(HtmlCommit)); commit->fs = fs; char filename[PATH_MAX]; @@ -74,10 +78,13 @@ void html_commit_free(HtmlCommit* commit) { } void html_commit_begin(HtmlCommit* commit) { + assert(commit != NULL); html_page_begin(commit->page); } void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit) { + assert(commit != NULL); + assert(git_commit != NULL); FILE* out = commit->out; html_commit_write_summary(commit, git_commit); @@ -104,12 +111,14 @@ void html_commit_set_diff_limits(HtmlCommit* commit, uint64_t max_files, uint64_t max_deltas, uint64_t max_delta_lines) { + assert(commit != NULL); commit->max_files = max_files; commit->max_deltas = max_deltas; commit->max_delta_lines = max_delta_lines; } void html_commit_end(HtmlCommit* commit) { + assert(commit != NULL); html_page_end(commit->page); } diff --git a/src/writer/html/fileblob.c b/src/writer/html/fileblob.c @@ -1,5 +1,6 @@ #include "writer/html/fileblob.h" +#include <assert.h> #include <err.h> #include <libgen.h> #include <limits.h> @@ -22,6 +23,9 @@ struct HtmlFileBlob { HtmlFileBlob* html_fileblob_create(const GitRepo* repo, const FileSystem* fs, const char* path) { + assert(repo != NULL); + assert(fs != NULL); + assert(path != NULL); if (!is_safe_repo_path(path)) { errx(1, "unsafe path: %s", path); } @@ -78,10 +82,13 @@ void html_fileblob_free(HtmlFileBlob* blob) { } void html_fileblob_begin(HtmlFileBlob* blob) { + assert(blob != NULL); html_page_begin(blob->page); } void html_fileblob_add_file(HtmlFileBlob* blob, const GitFile* file) { + assert(blob != NULL); + assert(file != NULL); FILE* out = blob->out; fprintf(out, "<p> "); @@ -107,10 +114,10 @@ void html_fileblob_add_file(HtmlFileBlob* blob, const GitFile* file) { fprintf(out, "<pre id=\"blob\">\n"); + assert(file->content != NULL); size_t i = 0; - const char* content = file->content; - const char* end = content + file->size_bytes; - const char* cur_line = content; + const char* end = file->content + file->size_bytes; + const char* cur_line = file->content; while (cur_line < end) { const char* next_line = memchr(cur_line, '\n', end - cur_line); size_t len = (next_line ? next_line : end) - cur_line; @@ -131,5 +138,6 @@ void html_fileblob_add_file(HtmlFileBlob* blob, const GitFile* file) { } void html_fileblob_end(HtmlFileBlob* blob) { + assert(blob != NULL); html_page_end(blob->page); } diff --git a/src/writer/html/files.c b/src/writer/html/files.c @@ -1,5 +1,6 @@ #include "writer/html/files.h" +#include <assert.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -17,6 +18,8 @@ struct HtmlFiles { }; HtmlFiles* html_files_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); HtmlFiles* files = ecalloc(1, sizeof(HtmlFiles)); files->repo = repo; files->fs = fs; @@ -40,6 +43,7 @@ void html_files_free(HtmlFiles* files) { } void html_files_begin(HtmlFiles* files) { + assert(files != NULL); html_page_begin(files->page); fprintf(files->out, "<table id=\"files\"><thead>\n" @@ -52,6 +56,8 @@ void html_files_begin(HtmlFiles* files) { } void html_files_add_file(HtmlFiles* files, const GitFile* file) { + assert(files != NULL); + assert(file != NULL); FILE* out = files->out; fprintf(out, "<tr><td>%s</td>", file->mode); @@ -77,6 +83,7 @@ void html_files_add_file(HtmlFiles* files, const GitFile* file) { } void html_files_end(HtmlFiles* files) { + assert(files != NULL); fprintf(files->out, "</tbody></table>"); html_page_end(files->page); } diff --git a/src/writer/html/index_writer.c b/src/writer/html/index_writer.c @@ -1,5 +1,6 @@ #include "writer/html/index_writer.h" +#include <assert.h> #include <stdio.h> #include <stdlib.h> @@ -12,6 +13,7 @@ struct HtmlIndexWriter { }; HtmlIndexWriter* html_indexwriter_create(FILE* out) { + assert(out != NULL); HtmlIndexWriter* writer = ecalloc(1, sizeof(HtmlIndexWriter)); writer->index = html_repoindex_create(out); return writer; @@ -27,17 +29,23 @@ void html_indexwriter_free(HtmlIndexWriter* writer) { } void html_indexwriter_set_me_url(HtmlIndexWriter* writer, const char* url) { + assert(writer != NULL); + assert(url != NULL); html_repoindex_set_me_url(writer->index, url); } void html_indexwriter_begin(HtmlIndexWriter* writer) { + assert(writer != NULL); html_repoindex_begin(writer->index); } void html_indexwriter_add_repo(HtmlIndexWriter* writer, const GitRepo* repo) { + assert(writer != NULL); + assert(repo != NULL); html_repoindex_add_repo(writer->index, repo); } void html_indexwriter_end(HtmlIndexWriter* writer) { + assert(writer != NULL); html_repoindex_end(writer->index); } diff --git a/src/writer/html/log.c b/src/writer/html/log.c @@ -1,5 +1,6 @@ #include "writer/html/log.h" +#include <assert.h> #include <stdint.h> #include <stdlib.h> @@ -33,6 +34,8 @@ static const mode_t kReadWriteAll = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; HtmlLog* html_log_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); HtmlLog* log = ecalloc(1, sizeof(HtmlLog)); log->repo = repo; log->fs = fs; @@ -68,6 +71,8 @@ void html_log_free(HtmlLog* log) { } void html_log_set_cachefile(HtmlLog* log, const char* cachefile) { + assert(log != NULL); + assert(cachefile != NULL); log->cache_path = estrdup(cachefile); log->temp_cache_path = estrdup(kTempCachePath); @@ -86,14 +91,17 @@ void html_log_set_cachefile(HtmlLog* log, const char* cachefile) { } void html_log_set_commit_limit(HtmlLog* log, size_t count) { + assert(log != NULL); log->remaining_commits = count; } bool html_log_can_add_commits(const HtmlLog* log) { + assert(log != NULL); return !log->cache || cache_can_add_commits(log->cache); } void html_log_begin(HtmlLog* log) { + assert(log != NULL); html_page_begin(log->page); fprintf(log->out, "<table id=\"log\"><thead>\n" @@ -109,6 +117,8 @@ void html_log_begin(HtmlLog* log) { } void html_log_add_commit(HtmlLog* log, const GitCommit* commit) { + assert(log != NULL); + assert(commit != NULL); if (log->cache) { cache_add_commit_row(log->cache, commit); } else if (log->remaining_commits > 0) { @@ -120,6 +130,7 @@ void html_log_add_commit(HtmlLog* log, const GitCommit* commit) { } void html_log_end(HtmlLog* log) { + assert(log != NULL); FILE* out = log->out; if (log->cache) { cache_finish(log->cache); @@ -157,6 +168,8 @@ void html_log_end(HtmlLog* log) { } static void write_commit_row(FILE* out, const GitCommit* commit) { + assert(out != NULL); + assert(commit != NULL); fprintf(out, "<tr><td>"); print_time_short(out, commit->author_time); fprintf(out, "</td><td>"); diff --git a/src/writer/html/page.c b/src/writer/html/page.c @@ -1,5 +1,6 @@ #include "writer/html/page.h" +#include <assert.h> #include <stdlib.h> #include "format.h" @@ -18,6 +19,11 @@ HtmlPage* html_page_create(FILE* out, const FileSystem* fs, const char* title, const char* relpath) { + assert(out != NULL); + assert(repo != NULL); + assert(fs != NULL); + assert(title != NULL); + assert(relpath != NULL); HtmlPage* page = ecalloc(1, sizeof(HtmlPage)); page->out = out; page->repo = repo; @@ -39,6 +45,7 @@ void html_page_free(HtmlPage* page) { } void html_page_begin(HtmlPage* page) { + assert(page != NULL); FILE* out = page->out; fprintf( out, @@ -138,5 +145,6 @@ void html_page_begin(HtmlPage* page) { } void html_page_end(HtmlPage* page) { + assert(page != NULL); fprintf(page->out, "</div>\n</body>\n</html>\n"); } diff --git a/src/writer/html/refs.c b/src/writer/html/refs.c @@ -1,5 +1,6 @@ #include "writer/html/refs.h" +#include <assert.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -36,6 +37,9 @@ static void html_refstable_end(HtmlRefsTable* table); static HtmlRefsTable* html_refstable_create(const char* title, const char* id, FILE* out) { + assert(title != NULL); + assert(id != NULL); + assert(out != NULL); HtmlRefsTable* table = ecalloc(1, sizeof(HtmlRefsTable)); table->title = estrdup(title); table->id = estrdup(id); @@ -55,6 +59,7 @@ static void html_refstable_free(HtmlRefsTable* table) { } static void html_refstable_begin(HtmlRefsTable* table) { + assert(table != NULL); fprintf(table->out, "<h2>%s</h2>", table->title); fprintf(table->out, "<table id=\"%s\">", table->id); fprintf(table->out, @@ -69,6 +74,8 @@ static void html_refstable_begin(HtmlRefsTable* table) { static void html_refstable_add_ref(HtmlRefsTable* table, const GitReference* ref) { + assert(table != NULL); + assert(ref != NULL); GitCommit* commit = ref->commit; fprintf(table->out, "<tr><td>"); print_xml_encoded(table->out, ref->shorthand); @@ -80,10 +87,13 @@ static void html_refstable_add_ref(HtmlRefsTable* table, } static void html_refstable_end(HtmlRefsTable* table) { + assert(table != NULL); fprintf(table->out, "</tbody></table><br/>\n"); } HtmlRefs* html_refs_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); HtmlRefs* refs = ecalloc(1, sizeof(HtmlRefs)); refs->repo = repo; refs->fs = fs; @@ -111,10 +121,13 @@ void html_refs_free(HtmlRefs* refs) { } void html_refs_begin(HtmlRefs* refs) { + assert(refs != NULL); html_page_begin(refs->page); } void html_refs_add_ref(HtmlRefs* refs, const GitReference* ref) { + assert(refs != NULL); + assert(ref != NULL); switch (ref->type) { case kReftypeBranch: if (!refs->branches) { @@ -140,6 +153,7 @@ void html_refs_add_ref(HtmlRefs* refs, const GitReference* ref) { } void html_refs_end(HtmlRefs* refs) { + assert(refs != NULL); if (refs->branches) { html_refstable_end(refs->branches); html_refstable_free(refs->branches); diff --git a/src/writer/html/repo_index.c b/src/writer/html/repo_index.c @@ -1,5 +1,6 @@ #include "writer/html/repo_index.h" +#include <assert.h> #include <stdlib.h> #include "format.h" @@ -11,6 +12,7 @@ struct HtmlRepoIndex { }; HtmlRepoIndex* html_repoindex_create(FILE* out) { + assert(out != NULL); HtmlRepoIndex* index = ecalloc(1, sizeof(HtmlRepoIndex)); index->out = out; index->me_url = NULL; @@ -26,10 +28,12 @@ void html_repoindex_free(HtmlRepoIndex* index) { } void html_repoindex_set_me_url(HtmlRepoIndex* index, const char* url) { + assert(index != NULL); index->me_url = url; } void html_repoindex_begin(HtmlRepoIndex* index) { + assert(index != NULL); FILE* out = index->out; fprintf( out, @@ -63,6 +67,8 @@ void html_repoindex_begin(HtmlRepoIndex* index) { } void html_repoindex_add_repo(HtmlRepoIndex* index, const GitRepo* repo) { + assert(index != NULL); + assert(repo != NULL); FILE* out = index->out; fprintf(out, "<tr><td><a href=\""); print_percent_encoded(out, repo->short_name); @@ -80,6 +86,7 @@ void html_repoindex_add_repo(HtmlRepoIndex* index, const GitRepo* repo) { } void html_repoindex_end(HtmlRepoIndex* index) { + assert(index != NULL); FILE* out = index->out; fprintf(out, "</tbody>\n</table>\n</div>\n</body>\n</html>\n"); } diff --git a/src/writer/html/repo_writer.c b/src/writer/html/repo_writer.c @@ -1,5 +1,6 @@ #include "writer/html/repo_writer.h" +#include <assert.h> #include <err.h> #include <limits.h> #include <stdio.h> @@ -32,6 +33,8 @@ struct HtmlRepoWriter { HtmlRepoWriter* html_repowriter_create(const GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); HtmlRepoWriter* writer = ecalloc(1, sizeof(HtmlRepoWriter)); writer->repo = repo; writer->fs = fs; @@ -78,20 +81,26 @@ void html_repowriter_free(HtmlRepoWriter* writer) { void html_repowriter_set_log_cachefile(HtmlRepoWriter* writer, const char* cachefile) { + assert(writer != NULL); + assert(cachefile != NULL); html_log_set_cachefile(writer->log, cachefile); } void html_repowriter_set_log_commit_limit(HtmlRepoWriter* writer, size_t count) { + assert(writer != NULL); html_log_set_commit_limit(writer->log, count); } void html_repowriter_set_baseurl(HtmlRepoWriter* writer, const char* baseurl) { + assert(writer != NULL); + assert(baseurl != NULL); atom_set_baseurl(writer->atom, baseurl); atom_set_baseurl(writer->tags, baseurl); } void html_repowriter_begin(HtmlRepoWriter* writer) { + assert(writer != NULL); writer->fs->mkdir("commit", S_IRWXU | S_IRWXG | S_IRWXO); writer->fs->mkdir("file", S_IRWXU | S_IRWXG | S_IRWXO); @@ -104,6 +113,8 @@ void html_repowriter_begin(HtmlRepoWriter* writer) { void html_repowriter_add_commit(HtmlRepoWriter* writer, const GitCommit* git_commit) { + assert(writer != NULL); + assert(git_commit != NULL); char filename[PATH_MAX]; int r = snprintf(filename, sizeof(filename), "%s.html", git_commit->oid); if (r < 0 || (size_t)r >= sizeof(filename)) { @@ -126,6 +137,8 @@ void html_repowriter_add_commit(HtmlRepoWriter* writer, void html_repowriter_add_reference(HtmlRepoWriter* writer, const GitReference* ref) { + assert(writer != NULL); + assert(ref != NULL); html_refs_add_ref(writer->refs, ref); if (ref->type == kReftypeTag) { GitCommit* commit = ref->commit; @@ -141,6 +154,8 @@ void html_repowriter_add_reference(HtmlRepoWriter* writer, } void html_repowriter_add_file(HtmlRepoWriter* writer, const GitFile* file) { + assert(writer != NULL); + assert(file != NULL); html_files_add_file(writer->files, file); HtmlFileBlob* blob = @@ -152,6 +167,7 @@ void html_repowriter_add_file(HtmlRepoWriter* writer, const GitFile* file) { } void html_repowriter_end(HtmlRepoWriter* writer) { + assert(writer != NULL); html_refs_end(writer->refs); html_log_end(writer->log); atom_end(writer->atom); diff --git a/src/writer/index_writer.c b/src/writer/index_writer.c @@ -1,5 +1,6 @@ #include "writer/index_writer.h" +#include <assert.h> #include <err.h> #include <stdlib.h> @@ -30,6 +31,7 @@ static IndexWriter* gopherindexwriter_create(FILE* out); static void gopherindexwriter_free(IndexWriter* writer); IndexWriter* indexwriter_create(IndexWriterType type, FILE* out) { + assert(out != NULL); switch (type) { case kIndexWriterTypeHtml: return htmlindexwriter_create(out); @@ -55,20 +57,26 @@ void indexwriter_free(IndexWriter* writer) { } void indexwriter_set_me_url(IndexWriter* writer, const char* url) { + assert(writer != NULL); + assert(url != NULL); if (writer->set_me_url) { writer->set_me_url(writer->impl, url); } } void indexwriter_begin(IndexWriter* writer) { + assert(writer != NULL); writer->begin(writer->impl); } void indexwriter_add_repo(IndexWriter* writer, const GitRepo* repo) { + assert(writer != NULL); + assert(repo != NULL); writer->add_repo(writer->impl, repo); } void indexwriter_end(IndexWriter* writer) { + assert(writer != NULL); writer->end(writer->impl); } diff --git a/src/writer/repo_writer.c b/src/writer/repo_writer.c @@ -1,5 +1,6 @@ #include "writer/repo_writer.h" +#include <assert.h> #include <err.h> #include <stdlib.h> @@ -44,6 +45,8 @@ static void gopherrepowriter_free(RepoWriter* writer); RepoWriter* repowriter_create(RepoWriterType type, GitRepo* repo, const FileSystem* fs) { + assert(repo != NULL); + assert(fs != NULL); switch (type) { case kRepoWriterTypeHtml: return htmlrepowriter_create(repo, fs); @@ -69,34 +72,47 @@ void repowriter_free(RepoWriter* writer) { } void repowriter_set_log_cachefile(RepoWriter* writer, const char* cachefile) { + assert(writer != NULL); + assert(cachefile != NULL); writer->set_log_cachefile(writer->impl, cachefile); } void repowriter_set_log_commit_limit(RepoWriter* writer, size_t count) { + assert(writer != NULL); writer->set_log_commit_limit(writer->impl, count); } void repowriter_set_baseurl(RepoWriter* writer, const char* baseurl) { + assert(writer != NULL); + assert(baseurl != NULL); writer->set_baseurl(writer->impl, baseurl); } void repowriter_begin(RepoWriter* writer) { + assert(writer != NULL); writer->begin(writer->impl); } void repowriter_add_commit(RepoWriter* writer, const GitCommit* commit) { + assert(writer != NULL); + assert(commit != NULL); writer->add_commit(writer->impl, commit); } void repowriter_add_reference(RepoWriter* writer, const GitReference* ref) { + assert(writer != NULL); + assert(ref != NULL); writer->add_reference(writer->impl, ref); } void repowriter_add_file(RepoWriter* writer, const GitFile* file) { + assert(writer != NULL); + assert(file != NULL); writer->add_file(writer->impl, file); } void repowriter_end(RepoWriter* writer) { + assert(writer != NULL); writer->end(writer->impl); }