#922. Fixing -pS and -pX on MSVC.

This commit is contained in:
Robin Mills 2015-04-28 19:19:59 +00:00
parent a69026c911
commit 84bf485ebe
5 changed files with 24 additions and 24 deletions

View File

@ -415,7 +415,7 @@ namespace Exiv2 {
/*!
@brief format a string in the pattern of \em sprintf \em .
*/
std::string stringFormat(const std::string fmt, ...) const;
std::string stringFormat(const char* format, ...) const;
/*!
@brief format binary for display in \em printStructure() \em .

View File

@ -165,7 +165,7 @@ void push(Jzon::Node& node,const std::string& key,T i)
case Exiv2::tiffFloat:
case Exiv2::tiffDouble:
STORE(node,key,i->value().toFloat());
STORE(node,key,std::atof(value.c_str()) );
break;
case Exiv2::unsignedRational:

View File

@ -352,30 +352,29 @@ namespace Exiv2 {
return ImageFactory::checkMode(imageType_, metadataId);
}
std::string Image::stringFormat(const std::string fmt, ...) const
std::string Image::stringFormat(const char* format, ...) const
{
std::string result;
int need = (int) fmt.size()*4; // initial guess
char* buffer = new char[need]; // allocate a buffer
va_list ap; // variable arg list
int need = (int) std::strlen(format); // initial guess
char* buffer = NULL;
int again = 4;
int rc = -1;
va_start(ap, fmt);
need=vsnprintf(buffer, need, fmt.c_str(), ap);
va_end(ap);
if (need < 0) { // make buffer bigger
delete[] buffer;
need = -need ;
buffer = new char[need+2];
va_start(ap, fmt);
need=vsnprintf(buffer, need, fmt.c_str(), ap);
va_end(ap);
if (rc < 0 && again--) {
if ( buffer ) delete[] buffer;
need *= 2 ;
buffer = new char[need];
if ( buffer ) {
va_list args; // variable arg list
va_start(args, format); // args start after format
rc=vsnprintf(buffer,(unsigned int)need, format, args);
va_end(args); // free the args
}
}
if ( need > 0 ) result = std::string(buffer) ;
delete[] buffer; // free buffer
if ( rc > 0 ) result = std::string(buffer) ;
if ( buffer ) delete[] buffer; // free buffer
return result;
}

View File

@ -148,8 +148,7 @@ namespace Exiv2 {
dataString = binaryToString(buff,blen);
}
if ( option == kpsBasic ) out << stringFormat("%8llu | %5ld | %10s |%8lu | ",address, index++,chType,dOff) << dataString << std::endl;
if ( option == kpsBasic ) out << stringFormat("%8lu | %5ld | %10s |%8lu | ",(uint32_t)address, index++,chType,dOff) << dataString << std::endl;
// for XMP, back up and read the whole block
const char* key = "XML:com.adobe.xmp" ;
size_t start = ::strlen(key);

View File

@ -431,6 +431,8 @@ namespace Exiv2 {
return type == 700 && option == kpsXMP;
}
#define MIN(a,b) ((a)<(b))?(b):(a)
void TiffImage::printStructure(std::ostream& out,Exiv2::printStructureOption_e option)
{
if (io_->open() != 0) throw Error(9, io_->path(), strError());
@ -449,7 +451,7 @@ namespace Exiv2 {
// read header (we already know for certain that we have a Tiff file)
io_->read(dir.pData_, 8);
char c = (char) dir.pData_[0] ;
#if __LITTLE_ENDIAN__
#if __LITTLE_ENDIAN__ || defined(_MSC_VER)
bool bSwap = c == 'M';
#else
bool bSwap = c == 'I';
@ -491,7 +493,7 @@ namespace Exiv2 {
: 1
;
DataBuf buf(size*kount + pad); // allocate a buffer
DataBuf buf(MIN(size*kount + pad,48)); // allocate a buffer
if ( isStringType(type) || count*size > 4 ) { // data is in the directory => read into buffer
size_t restore = io_->tell(); // save
io_->seek(offset,BasicIo::beg); // position