commit 736ef9601a4019d733987df67d39baf5d7cfd65e
parent cfb22288e9fa5eb53a06984486038c06c3918565
Author: bpaul <bpaul@bpaul.xyz>
Date: Fri, 20 Feb 2026 23:40:06 +1000
code review (i'm horrified by what i saw)
Diffstat:
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/main.c b/main.c
@@ -66,9 +66,10 @@ fsize(FILE *f) {
char *
add_path(const char *dir, const char *name) {
+ /* +2 because i wanted to add a '/' to the end of something apparently... */
size_t len = strlen(dir) + strlen(name) + 2;
char *buf = malloc(len);
- memcpy(buf, dir, len);
+ memcpy(buf, dir, strlen(dir) + 1);
strcat(buf, name);
@@ -107,6 +108,9 @@ iterate(DIR *d, const char *curdir) {
/* Only want files which have a .links file */
if (access(link, F_OK) != 0) {
+ free(buf);
+ free(link);
+ free(html);
goto skip;
}
@@ -137,6 +141,7 @@ iterate(DIR *d, const char *curdir) {
/* Read ascii file and add links when needed */
FILE *f = fopen(buf, "r");
FILE *htmlf = fopen(html, "w");
+ /* WHAT AM I LOOKING AT??? */
char *c = malloc(1);
len = fsize(f);
int x = 1, y = 1;
@@ -187,7 +192,10 @@ iterate(DIR *d, const char *curdir) {
free(buf);
free(link);
+ free(html);
free(links_buf);
+ free(entries);
+ free(c);
} else if (entry->d_type == DT_DIR) {
/* For directories, reiterate */
@@ -199,6 +207,7 @@ iterate(DIR *d, const char *curdir) {
DIR *newd;
if ((newd = opendir((buf))) == NULL) {
perror("opendir");
+ free(buf);
return;
}
@@ -225,8 +234,10 @@ main(int argc, char **argv) {
puts("That is not a valid directory");
exit(0);
}
+ /* IS THIS SAFE???? atp i don't want to know... */
strcat(argv[1], "/");
iterate(d, argv[1]);
+ closedir(d);
return 0;
}