Skip to content

Commit

Permalink
Fixes writer option max annotation does not work issue. (amazon-ion#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheqianh authored Dec 1, 2021
1 parent 593fb50 commit f7d33b0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ionc/ion_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ iERR _ion_writer_open_helper(ION_WRITER **p_pwriter, ION_STREAM *stream, ION_WRI
writer_type = ion_type_text_writer;
}

IONCHECK(ion_temp_buffer_init(pwriter, &pwriter->temp_buffer, ION_WRITER_TEMP_BUFFER_DEFAULT));
// calculate annotations size by writer option's max_annotation_count field
SIZE temp_buffer_size = p_options->max_annotation_count * sizeof(ION_SYMBOL) + ION_WRITER_TEMP_BUFFER_DEFAULT;
IONCHECK(ion_temp_buffer_init(pwriter, &pwriter->temp_buffer, temp_buffer_size));

// allocate a temp pool we can reset from time to time
IONCHECK( _ion_writer_allocate_temp_pool( pwriter ));
Expand Down Expand Up @@ -1094,7 +1096,9 @@ iERR _ion_writer_add_annotation_helper(ION_WRITER *pwriter, ION_STRING *annotati
ASSERT(annotation->length >= 0);

if (!pwriter->annotations) {
IONCHECK(_ion_writer_set_max_annotation_count_helper(pwriter, DEFAULT_ANNOTATION_LIMIT));
int final_max_annotation_count = (pwriter->options.max_annotation_count > DEFAULT_ANNOTATION_LIMIT)
? pwriter->options.max_annotation_count : DEFAULT_ANNOTATION_LIMIT;
IONCHECK(_ion_writer_set_max_annotation_count_helper(pwriter, final_max_annotation_count));
}
else if (pwriter->annotation_curr >= pwriter->annotation_count) FAILWITH(IERR_TOO_MANY_ANNOTATIONS);

Expand Down

0 comments on commit f7d33b0

Please sign in to comment.