--- file_not_specified_in_diff +++ file_not_specified_in_diff @@ -, +, @@ --- libs/icu/icu-4.4/tools/pkgdata/pkgdata.cpp +++ libs/icu/icu-4.4/tools/pkgdata/pkgdata.cpp @@ -95,6 +95,7 @@ #endif #define LARGE_BUFFER_MAX_SIZE 2048 +#define MEDIUM_BUFFER_MAX_SIZE 1024 #define SMALL_BUFFER_MAX_SIZE 512 static void loadLists(UPKGOptions *o, UErrorCode *status); @@ -561,42 +562,53 @@ char gencFilePath[SMALL_BUFFER_MAX_SIZE] = ""; char version_major[10] = ""; UBool reverseExt = FALSE; + unsigned currentBufferSize = MEDIUM_BUFFER_MAX_SIZE; /* Initialize pkgdataFlags */ pkgDataFlags = (char**)uprv_malloc(sizeof(char*) * PKGDATA_FLAGS_SIZE); - if (pkgDataFlags != NULL) { - for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) { - pkgDataFlags[i] = (char*)uprv_malloc(sizeof(char) * SMALL_BUFFER_MAX_SIZE); - if (pkgDataFlags[i] != NULL) { - pkgDataFlags[i][0] = 0; - } else { - fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); - return -1; +#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) + /* If we run out of space, allocate more */ + do { +#endif + if (pkgDataFlags != NULL) { + for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) { + pkgDataFlags[i] = (char*)uprv_malloc(sizeof(char) * currentBufferSize); + if (pkgDataFlags[i] != NULL) { + pkgDataFlags[i][0] = 0; + } else { + fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); + return -1; + } } + } else { + fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); + return -1; } - } else { - fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); - return -1; - } - if(o->verbose) { - fprintf(stdout, "# pkgDataFlags="); - for(int32_t i=0;i0)?',':' ',pkgDataFlags[i]); - } - fprintf(stdout, "\n"); - } + if(o->verbose) { + fprintf(stdout, "# pkgDataFlags="); + for(int32_t i=0;i0)?',':' ',pkgDataFlags[i]); + } + fprintf(stdout, "\n"); + } #ifndef WINDOWS_WITH_MSVC - /* Read in options file. */ - if(o->verbose) { - fprintf(stdout, "# Reading options file %s\n", o->options); - } - parseFlagsFile(o->options, pkgDataFlags, SMALL_BUFFER_MAX_SIZE, (int32_t)PKGDATA_FLAGS_SIZE, &status); - if (U_FAILURE(status)) { - fprintf(stderr,"Unable to open or read \"%s\" option file. status = %s\n", o->options, u_errorName(status)); - return -1; - } + /* Read in options file. */ + if(o->verbose) { + fprintf(stdout, "# Reading options file %s\n", o->options); + } + parseFlagsFile(o->options, pkgDataFlags, currentBufferSize, (int32_t)PKGDATA_FLAGS_SIZE, &status); + if (status == U_BUFFER_OVERFLOW_ERROR) { + for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) { + uprv_free(pkgDataFlags[i]); + } + currentBufferSize *= 2; + } else if (U_FAILURE(status)) { + fprintf(stderr,"Unable to open or read \"%s\" option file. status = %s\n", o->options, u_errorName(status)); + return -1; + } + } while (status == U_BUFFER_OVERFLOW_ERROR); /* Get the version major number. */ if (o->version != NULL) {