Bug #1066 » T1066.patch
src/tiffimage.cpp (working copy) | ||
---|---|---|
345 | 345 |
// http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf |
346 | 346 |
static std::string stringFormat(const std::string fmt_str, ...) { |
347 | 347 |
int n = ((int)fmt_str.size()) * 2; /* Reserve two times as much as the length of the fmt_str */ |
348 |
std::unique_ptr<char[]> formatted;
|
|
348 |
char* formatted;
|
|
349 | 349 |
std::string str; |
350 | 350 |
va_list ap; |
351 | 351 |
bool ok = true; |
352 |
while(ok) { |
|
353 |
formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */
|
|
352 |
while (ok) {
|
|
353 |
formatted = new char[n];
|
|
354 | 354 |
strcpy(&formatted[0], fmt_str.c_str()); |
355 | 355 |
va_start(ap, fmt_str); |
356 | 356 |
int final = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap); |
357 | 357 |
va_end(ap); |
358 | 358 |
ok = final < 0 || final >= n; |
359 |
if ( ok ) n += abs(final - n + 1); |
|
359 |
if (ok) { |
|
360 |
n += abs(final - n + 1); |
|
361 |
delete[] formatted; |
|
362 |
} |
|
360 | 363 |
} |
361 |
return std::string(formatted.get()); |
|
364 |
str = std::string(formatted); |
|
365 |
delete[] formatted; |
|
366 |
return str; |
|
362 | 367 |
} |
363 | 368 | |
364 | 369 |
std::string stringValue(byte* buff,size_t size) |