Project

General

Profile

Bug #1066 » T1066.patch

Thomas Beutlich, 25 Apr 2015 22:11

View differences:

src/tiffimage.cpp (working copy)
48 48
#include <iostream>
49 49
#include <iomanip>
50 50
#include <cassert>
51
#include <memory>
52 51
#include <cstdarg>
53 52

  
54 53
/* --------------------------------------------------------------------------
......
345 344
    // http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
346 345
    static std::string stringFormat(const std::string fmt_str, ...) {
347 346
		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;
347
		char* formatted;
349 348
		std::string str;
350 349
		va_list     ap;
351 350
		bool        ok = true;
352
		while(ok) {
353
			formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */
351
		do {
352
			formatted = new char[n];
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);
357 356
			va_end(ap);
358 357
			ok = final < 0 || final >= n;
359
			if ( ok ) n += abs(final - n + 1);
360
		}
361
		return std::string(formatted.get());
358
			if (ok) {
359
				n += abs(final - n + 1);
360
			}
361
			else {
362
				str = std::string(formatted);
363
			}
364
			delete[] formatted;
365
		} while (ok);	
366
		return str;
362 367
    }
363 368

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