Project

General

Profile

Bug #1066 » T1066.patch

Thomas Beutlich, 25 Apr 2015 21:48

View differences:

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 = new char[n];
349 349
		std::string str;
350 350
		va_list     ap;
351 351
		bool        ok = true;
352 352
		while(ok) {
353
			formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */
354 353
			strcpy(&formatted[0], fmt_str.c_str());
355 354
			va_start(ap, fmt_str);
356 355
			int final = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap);
......
358 357
			ok = final < 0 || final >= n;
359 358
			if ( ok ) n += abs(final - n + 1);
360 359
		}
361
		return std::string(formatted.get());
360
		str = std::string(formatted);
361
		delete[] formatted;
362
		return str;
362 363
    }
363 364

  
364 365
    std::string stringValue(byte* buff,size_t size)
(1-1/3)