Skip to content

Commit

Permalink
Add better pointer check.
Browse files Browse the repository at this point in the history
  • Loading branch information
BasicAcid committed Dec 25, 2023
1 parent f6868c1 commit e3c40b7
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions tagger.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#include <string.h>
#include <getopt.h>

// Keep this global?
char *BASEREGEX = "+.*+@.*";
int MAXTAGNB = 30;
const char *BASEREGEX = "+.*+@.*";
const int MAXTAGNB = 30;

struct FileTuple
{
Expand Down Expand Up @@ -60,26 +59,35 @@ remove_duplicates_llist(struct TagNode *head)
}
}


void
extract_tags(const char *filename, char *tags)
{
const char *start = strchr(filename, '+');
const char *end = strchr(start + 1, '+');

if(start && end)
if(start)
{
size_t tag_len = (size_t)(end - start - 1);
strncpy(tags, start + 1, tag_len);
tags[tag_len] = '\0'; // Null-termination.
const char *end = strchr(start + 1, '+');

if(end)
{
size_t tag_len = (size_t)(end - start - 1);
strncpy(tags, start + 1, tag_len);
tags[tag_len] = '\0'; // Null-termination.
}
else
{
fprintf(stderr, "Error (extract_tags): 'end' is a NULL pointer.\n");
exit(EXIT_FAILURE);
}
}
else
{
fprintf(stderr, "Error (extract_tags): 'start' or 'end' is a NULL pointer.\n");
fprintf(stderr, "Error (extract_tags): 'start' is a NULL pointer.\n");
exit(EXIT_FAILURE);
}
}


void
search_files(const char *path, regex_t *regex, struct FileTuple **matches, int *match_count)
{
Expand Down

0 comments on commit e3c40b7

Please sign in to comment.