<commit_before>#include "libexifget.h"
#include "exif_print.h"
#include "exifget_options.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define USAGE_FMT "Usage: %s [photo_file]\n"

void
print_help();

int
main(int argc, char *argv[])
{
    char *file_name;
    exifget_data_t *data;
    int err;
    struct ifd_entry entry;
    int retval;
    extern char *optarg;
    extern int optind;
    int opt;
    struct exifget_options opts;
    char *delineated_tags;
    int i;

    if (argc < 2) {
        printf(USAGE_FMT, argv[0]);
        exit(EXIT_FAILURE);
    }
    
    delineated_tags = NULL;

    exifget_options_init(&opts);
    while ((opt = getopt(argc, argv, "ht:")) != -1) {
        switch(opt) {
        case 'h':
            print_help(argv);
            exit(EXIT_SUCCESS);
            break;
        case 't':
            delineated_tags = strdup(optarg);
            break;
        default:
            /* Do nothing */
            break;
        }
    }

    file_name = argv[optind];
    err = exifget_open(file_name, &data);
    exifget_options_set_tags(data, &opts, optarg);
    if (err != EXIFGET_ENOERR) {
        exifget_perror(err);
        exit(EXIT_FAILURE);
    }
    while ((retval = exifget_next_ifd_entry(data, &entry)) == 0) {
        retval = exifget_ifd_entry_value_load(data, &entry);
        if (retval != EXIFGET_ENOERR) {
            break;
        }
        if (opts.flags & EXIFGET_FLAG_TAGS) {
            for (i = 0; i < opts.num_tags; i++) {
                if (opts.tags[i] == entry.tag) {
                    print_ifd_entry(data, &entry);
                }
            }
        } else {
            print_ifd_entry(data, &entry);
        }
        exifget_ifd_entry_value_unload(&entry);
    }
    if (retval > 0) {
        err = retval;
        exifget_perror(err);
        exit(EXIT_FAILURE);
    }
    exifget_close(data);

    exifget_options_destroy(&opts);
    if (delineated_tags != NULL) {<commit_msg>Fix a null pointer dereference<commit_after>#include "libexifget.h"
#include "exif_print.h"
#include "exifget_options.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define USAGE_FMT "Usage: %s [photo_file]\n"

void
print_help();

int
main(int argc, char *argv[])
{
    char *file_name;
    exifget_data_t *data;
    int err;
    struct ifd_entry entry;
    int retval;
    extern char *optarg;
    extern int optind;
    int opt;
    struct exifget_options opts;
    char *delineated_tags;
    int i;

    if (argc < 2) {
        printf(USAGE_FMT, argv[0]);
        exit(EXIT_FAILURE);
    }
    
    delineated_tags = NULL;

    exifget_options_init(&opts);
    while ((opt = getopt(argc, argv, "ht:")) != -1) {
        switch(opt) {
        case 'h':
            print_help(argv);
            exit(EXIT_SUCCESS);
            break;
        case 't':
            delineated_tags = strdup(optarg);
            break;
        default:
            /* Do nothing */
            break;
        }
    }

    file_name = argv[optind];
    err = exifget_open(file_name, &data);
    if (err != EXIFGET_ENOERR) {
        exifget_perror(err);
        exit(EXIT_FAILURE);
    }

    /* Set up Options */
    if (delineated_tags != NULL) {
        exifget_options_set_tags(data, &opts, delineated_tags);
    }

    while ((retval = exifget_next_ifd_entry(data, &entry)) == 0) {
        retval = exifget_ifd_entry_value_load(data, &entry);
        if (retval != EXIFGET_ENOERR) {
            break;
        }
        if (opts.flags & EXIFGET_FLAG_TAGS) {
            for (i = 0; i < opts.num_tags; i++) {
                if (opts.tags[i] == entry.tag) {
                    print_ifd_entry(data, &entry);
                }
            }
        } else {
            print_ifd_entry(data, &entry);
        }
        exifget_ifd_entry_value_unload(&entry);
    }
    if (retval > 0) {
        err = retval;
        exifget_perror(err);
        exit(EXIT_FAILURE);
    }
    exifget_close(data);

    exifget_options_destroy(&opts);
    if (delineated_tags != NULL) {
{'fraction_non_alphanumeric': 0.1255517410495341, 'fraction_numerical': 0.0029426189308484553, 'mean_word_length': 2.00811209439528, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3977892', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1454, 'n_words': 284}