Skip to content

Commit

Permalink
Test Fuzzer hatchet style
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Jun 15, 2024
1 parent a8f252a commit 805afb8
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions src/spss/readstat_sav_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ static readstat_error_t parse_mr_line(const char *line, mr_set_t *result) {
}

static readstat_error_t sav_read_multiple_response_sets(size_t data_len, sav_ctx_t *ctx) {
return READSTAT_OK; // hatchet
readstat_error_t retval = READSTAT_OK;

char *mr_string = readstat_malloc(data_len + 1);
Expand Down Expand Up @@ -1886,36 +1887,37 @@ readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path,
ck_str_hash_insert(current_varinfo->name, current_varinfo, var_dict);
}
}
for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
mr_set_t mr = ctx->mr_sets[i];
for (size_t j = 0; j < mr.num_subvars; j++) {
char* sv_name_upper = malloc(strlen(mr.subvariables[j]) + 1);
if (sv_name_upper == NULL) {
retval = READSTAT_ERROR_MALLOC;
goto cleanup;
}
sv_name_upper[strlen(mr.subvariables[j])] = '\0';
for (int c = 0; mr.subvariables[j][c] != '\0'; c++) {
sv_name_upper[c] = toupper((unsigned char) mr.subvariables[j][c]);
}
spss_varinfo_t *info = (spss_varinfo_t *)ck_str_hash_lookup(sv_name_upper, var_dict);
if (info) {
free(mr.subvariables[j]);
// mr.subvariables[j] = NULL;
if ((mr.subvariables[j] = readstat_malloc(strlen(info->longname) + 1)) == NULL) {
retval = READSTAT_ERROR_MALLOC;
goto cleanup;
}
// mr.subvariables[j][strlen(info->longname)] = '\0';
strcpy(mr.subvariables[j], info->longname);
// mr.subvariables[j] = info->longname;
}
free(sv_name_upper);
// sv_name_upper = NULL;
}
}
if (var_dict)
ck_hash_table_free(var_dict);
// Hatchet !!!
// for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
// mr_set_t mr = ctx->mr_sets[i];
// for (size_t j = 0; j < mr.num_subvars; j++) {
// char* sv_name_upper = malloc(strlen(mr.subvariables[j]) + 1);
// if (sv_name_upper == NULL) {
// retval = READSTAT_ERROR_MALLOC;
// goto cleanup;
// }
// sv_name_upper[strlen(mr.subvariables[j])] = '\0';
// for (int c = 0; mr.subvariables[j][c] != '\0'; c++) {
// sv_name_upper[c] = toupper((unsigned char) mr.subvariables[j][c]);
// }
// spss_varinfo_t *info = (spss_varinfo_t *)ck_str_hash_lookup(sv_name_upper, var_dict);
// if (info) {
// free(mr.subvariables[j]);
// // mr.subvariables[j] = NULL;
// if ((mr.subvariables[j] = readstat_malloc(strlen(info->longname) + 1)) == NULL) {
// retval = READSTAT_ERROR_MALLOC;
// goto cleanup;
// }
// // mr.subvariables[j][strlen(info->longname)] = '\0';
// strcpy(mr.subvariables[j], info->longname);
// // mr.subvariables[j] = info->longname;
// }
// free(sv_name_upper);
// // sv_name_upper = NULL;
// }
// }
// if (var_dict)
// ck_hash_table_free(var_dict);

metadata.multiple_response_sets_length = ctx->multiple_response_sets_length;
metadata.mr_sets = ctx->mr_sets;
Expand Down

0 comments on commit 805afb8

Please sign in to comment.