- if(currentIndex+value->length+1 <= mappingDataCapacity){
- /* write the length */
- if(mappingLength > _SPREP_MAX_INDEX_TOP_LENGTH ){
- /* the cast here is safe since we donot expect the length to be > 65535 */
- mappingData[currentIndex++] = (uint16_t) mappingLength;
- }
- /* copy the contents to mappindData array */
- uprv_memmove(mappingData+currentIndex, value->mapping, value->length*U_SIZEOF_UCHAR);
- currentIndex += value->length;
-
- }else{
- /* realloc */
- UChar* newMappingData = (uint16_t*) uprv_malloc(U_SIZEOF_UCHAR * mappingDataCapacity*2);
- if(newMappingData == NULL){
- fprintf(stderr, "Could not realloc the mapping data!\n");
- exit(U_MEMORY_ALLOCATION_ERROR);
- }
- uprv_memmove(newMappingData, mappingData, U_SIZEOF_UCHAR * mappingDataCapacity);
- mappingDataCapacity *= 2;
- uprv_free(mappingData);
- mappingData = newMappingData;
- /* write the length */
- if(mappingLength > _SPREP_MAX_INDEX_TOP_LENGTH ){
- /* the cast here is safe since we donot expect the length to be > 65535 */
- mappingData[currentIndex++] = (uint16_t) mappingLength;
- }
- /* continue copying */
- uprv_memmove(mappingData+currentIndex, value->mapping, value->length*U_SIZEOF_UCHAR);
- currentIndex += value->length;
+ /* write the length */
+ if(mappingLength > _SPREP_MAX_INDEX_TOP_LENGTH ){
+ /* the cast here is safe since we donot expect the length to be > 65535 */
+ mappingData[currentIndex++] = (uint16_t) mappingLength;
+ }
+ /* copy the contents to mappindData array */
+ uprv_memmove(mappingData+currentIndex, value->mapping, value->length*U_SIZEOF_UCHAR);
+ currentIndex += value->length;
+ if (currentIndex > mappingDataCapacity) {
+ /* If this happens there is a bug in the computation of the mapping data size in storeMapping() */
+ fprintf(stderr, "gensprep, fatal error at %s, %d. Aborting.\n", __FILE__, __LINE__);
+ exit(U_INTERNAL_PROGRAM_ERROR);