MT#62181 use size_t for offsets and lengths

Change-Id: I8a4630ad1d7fae351f96cd479f28839724903582
mr13.4
Richard Fuchs 1 year ago
parent 7267f879e0
commit b357698a75

@ -628,12 +628,12 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
void XMLRPC2DIServer::xmlrpcval2amargarray(XmlRpcValue& v, AmArg& a,
unsigned int start_index) {
size_t start_index) {
if (v.valid()) {
a.assertArray();
size_t a_array_pos = a.size();
for (int i=start_index; i<v.size();i++) {
for (size_t i=start_index; i<v.size();i++) {
xmlrpcval2amarg(v[i], a[a_array_pos]);
a_array_pos++;
}

@ -151,7 +151,7 @@ class XMLRPC2DIServer
void waitUntilStarted() { running.wait_for(); }
static void xmlrpcval2amargarray(XmlRpcValue& v, AmArg& a,
unsigned int start_index);
size_t start_index);
static void xmlrpcval2amarg(XmlRpcValue& v, AmArg& a);

@ -312,7 +312,7 @@ XmlRpcClient::generateRequest(const char* methodName, XmlRpcValue const& params)
body += PARAMS_TAG;
if (params.getType() == XmlRpcValue::TypeArray)
{
for (int i=0; i<params.size(); ++i) {
for (size_t i=0; i<params.size(); ++i) {
body += PARAM_TAG;
body += params[i].toXml();
body += PARAM_ETAG;
@ -519,7 +519,7 @@ bool
XmlRpcClient::parseResponse(XmlRpcValue& result)
{
// Parse response xml into result
int offset = 0;
size_t offset = 0;
if ( ! XmlRpcUtil::findTag(METHODRESPONSE_TAG,_response,&offset)) {
XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n%s", _response.c_str());
return false;

@ -351,7 +351,7 @@ XmlRpcServer::executeRequest(std::string const& request)
std::string
XmlRpcServer::parseRequest(std::string const& request, XmlRpcValue& params)
{
int offset = 0; // Number of chars parsed from the request
size_t offset = 0; // Number of chars parsed from the request
std::string methodName = XmlRpcUtil::parseTag(METHODNAME_TAG, request, &offset);

@ -96,9 +96,9 @@ void XmlRpcUtil::error(const char* fmt, ...)
// Returns contents between <tag> and </tag>, updates offset to char after </tag>
std::string
XmlRpcUtil::parseTag(const char* tag, std::string const& xml, int* offset)
XmlRpcUtil::parseTag(const char* tag, std::string const& xml, size_t* offset)
{
if (*offset >= int(xml.length())) return std::string();
if (*offset >= xml.length()) return std::string();
size_t istart = xml.find(tag, *offset);
if (istart == std::string::npos) return std::string();
istart += strlen(tag);
@ -107,21 +107,21 @@ XmlRpcUtil::parseTag(const char* tag, std::string const& xml, int* offset)
size_t iend = xml.find(etag, istart);
if (iend == std::string::npos) return std::string();
*offset = int(iend + etag.length());
*offset = iend + etag.length();
return xml.substr(istart, iend-istart);
}
// Returns true if the tag is found and updates offset to the char after the tag
bool
XmlRpcUtil::findTag(const char* tag, std::string const& xml, int* offset)
XmlRpcUtil::findTag(const char* tag, std::string const& xml, size_t* offset)
{
if (*offset >= int(xml.length())) return false;
if (*offset >= xml.length()) return false;
size_t istart = xml.find(tag, *offset);
if (istart == std::string::npos)
return false;
*offset = int(istart + strlen(tag));
*offset = istart + strlen(tag);
return true;
}
@ -129,17 +129,17 @@ XmlRpcUtil::findTag(const char* tag, std::string const& xml, int* offset)
// Returns true if the tag is found at the specified offset (modulo any whitespace)
// and updates offset to the char after the tag
bool
XmlRpcUtil::nextTagIs(const char* tag, std::string const& xml, int* offset)
XmlRpcUtil::nextTagIs(const char* tag, std::string const& xml, size_t* offset)
{
if (*offset >= int(xml.length())) return false;
if (*offset >= xml.length()) return false;
const char* cp = xml.c_str() + *offset;
int nc = 0;
size_t nc = 0;
while (*cp && isspace(*cp)) {
++cp;
++nc;
}
int len = int(strlen(tag));
size_t len = strlen(tag);
if (*cp && (strncmp(cp, tag, len) == 0)) {
*offset += nc + len;
return true;
@ -151,9 +151,9 @@ XmlRpcUtil::nextTagIs(const char* tag, std::string const& xml, int* offset)
// if the next non-whitespace character is not '<'. Ignores parameters and values within
// the tag entity.
std::string
XmlRpcUtil::getNextTag(std::string const& xml, int* offset)
XmlRpcUtil::getNextTag(std::string const& xml, size_t* offset)
{
if (*offset >= int(xml.length())) return std::string();
if (*offset >= xml.length()) return std::string();
const char* cp = xml.c_str() + size_t(*offset);
const char* startcp = cp;
@ -178,7 +178,7 @@ XmlRpcUtil::getNextTag(std::string const& xml, int* offset)
s[s.length()-1] = *cp;
}
*offset += int(cp - startcp + 1);
*offset += cp - startcp + 1;
return s;
}

@ -28,18 +28,18 @@ namespace XmlRpc {
public:
// hokey xml parsing
//! Returns contents between <tag> and </tag>, updates offset to char after </tag>
static std::string parseTag(const char* tag, std::string const& xml, int* offset);
static std::string parseTag(const char* tag, std::string const& xml, size_t* offset);
//! Returns true if the tag is found and updates offset to the char after the tag
static bool findTag(const char* tag, std::string const& xml, int* offset);
static bool findTag(const char* tag, std::string const& xml, size_t* offset);
//! Returns the next tag and updates offset to the char after the tag, or empty string
//! if the next non-whitespace character is not '<'
static std::string getNextTag(std::string const& xml, int* offset);
static std::string getNextTag(std::string const& xml, size_t* offset);
//! Returns true if the tag is found at the specified offset (modulo any whitespace)
//! and updates offset to the char after the tag
static bool nextTagIs(const char* tag, std::string const& xml, int* offset);
static bool nextTagIs(const char* tag, std::string const& xml, size_t* offset);
//! Convert raw text to encoded xml.

@ -84,22 +84,22 @@ namespace XmlRpc {
throw XmlRpcException("type error");
}
void XmlRpcValue::assertArray(int size) const
void XmlRpcValue::assertArray(size_t size) const
{
if (_type != TypeArray)
throw XmlRpcException("type error: expected an array");
else if (int(_value.asArray->size()) < size)
else if (_value.asArray->size() < size)
throw XmlRpcException("range error: array index too large");
}
void XmlRpcValue::assertArray(int size)
void XmlRpcValue::assertArray(size_t size)
{
if (_type == TypeInvalid) {
_type = TypeArray;
_value.asArray = new ValueArray(size);
} else if (_type == TypeArray) {
if (int(_value.asArray->size()) < size)
if (_value.asArray->size() < size)
_value.asArray->resize(size);
} else
throw XmlRpcException("type error: expected an array");
@ -190,13 +190,13 @@ namespace XmlRpc {
// Works for strings, binary data, arrays, and structs.
int XmlRpcValue::size() const
size_t XmlRpcValue::size() const
{
switch (_type) {
case TypeString: return int(_value.asString->size());
case TypeBase64: return int(_value.asBinary->size());
case TypeArray: return int(_value.asArray->size());
case TypeStruct: return int(_value.asStruct->size());
case TypeString: return _value.asString->size();
case TypeBase64: return _value.asBinary->size();
case TypeArray: return _value.asArray->size();
case TypeStruct: return _value.asStruct->size();
default: break;
}
@ -211,15 +211,15 @@ namespace XmlRpc {
// Set the value from xml. The chars at *offset into valueXml
// should be the start of a <value> tag. Destroys any existing value.
bool XmlRpcValue::fromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::fromXml(std::string const& valueXml, size_t* offset)
{
int savedOffset = *offset;
size_t savedOffset = *offset;
invalidate();
if ( ! XmlRpcUtil::nextTagIs(VALUE_TAG, valueXml, offset))
return false; // Not a value, offset not updated
int afterValueOffset = *offset;
size_t afterValueOffset = *offset;
std::string typeTag = XmlRpcUtil::getNextTag(valueXml, offset);
bool result = false;
if (typeTag == BOOLEAN_TAG)
@ -272,7 +272,7 @@ namespace XmlRpc {
// Boolean
bool XmlRpcValue::boolFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::boolFromXml(std::string const& valueXml, size_t* offset)
{
const char* valueStart = valueXml.c_str() + *offset;
char* valueEnd;
@ -282,7 +282,7 @@ namespace XmlRpc {
_type = TypeBoolean;
_value.asBool = (ivalue == 1);
*offset += int(valueEnd - valueStart);
*offset += valueEnd - valueStart;
return true;
}
@ -297,7 +297,7 @@ namespace XmlRpc {
}
// Int
bool XmlRpcValue::intFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::intFromXml(std::string const& valueXml, size_t* offset)
{
const char* valueStart = valueXml.c_str() + *offset;
char* valueEnd;
@ -307,7 +307,7 @@ namespace XmlRpc {
_type = TypeInt;
_value.asInt = int(ivalue);
*offset += int(valueEnd - valueStart);
*offset += valueEnd - valueStart;
return true;
}
@ -325,7 +325,7 @@ namespace XmlRpc {
}
// Double
bool XmlRpcValue::doubleFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::doubleFromXml(std::string const& valueXml, size_t* offset)
{
const char* valueStart = valueXml.c_str() + *offset;
char* valueEnd;
@ -335,7 +335,7 @@ namespace XmlRpc {
_type = TypeDouble;
_value.asDouble = dvalue;
*offset += int(valueEnd - valueStart);
*offset += valueEnd - valueStart;
return true;
}
@ -354,7 +354,7 @@ namespace XmlRpc {
}
// String
bool XmlRpcValue::stringFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::stringFromXml(std::string const& valueXml, size_t* offset)
{
size_t valueEnd = valueXml.find('<', *offset);
if (valueEnd == std::string::npos)
@ -362,7 +362,7 @@ namespace XmlRpc {
_type = TypeString;
_value.asString = new std::string(XmlRpcUtil::xmlDecode(valueXml.substr(*offset, valueEnd-*offset)));
*offset += int(_value.asString->length());
*offset += _value.asString->length();
return true;
}
@ -377,7 +377,7 @@ namespace XmlRpc {
}
// DateTime (stored as a struct tm)
bool XmlRpcValue::timeFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::timeFromXml(std::string const& valueXml, size_t* offset)
{
size_t valueEnd = valueXml.find('<', *offset);
if (valueEnd == std::string::npos)
@ -393,7 +393,7 @@ namespace XmlRpc {
t.tm_isdst = -1;
_type = TypeDateTime;
_value.asTime = new struct tm(t);
*offset += int(stime.length());
*offset += stime.length();
return true;
}
@ -418,7 +418,7 @@ namespace XmlRpc {
// Base64
bool XmlRpcValue::binaryFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::binaryFromXml(std::string const& valueXml, size_t* offset)
{
size_t valueEnd = valueXml.find('<', *offset);
if (valueEnd == std::string::npos)
@ -435,7 +435,7 @@ namespace XmlRpc {
std::back_insert_iterator<BinaryData> ins = std::back_inserter(*(_value.asBinary));
decoder.get(asString.begin(), asString.end(), ins, iostatus);
*offset += int(asString.length());
*offset += asString.length();
return true;
}
@ -460,7 +460,7 @@ namespace XmlRpc {
// Array
bool XmlRpcValue::arrayFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::arrayFromXml(std::string const& valueXml, size_t* offset)
{
if ( ! XmlRpcUtil::nextTagIs(DATA_TAG, valueXml, offset))
return false;
@ -485,8 +485,8 @@ namespace XmlRpc {
xml += ARRAY_TAG;
xml += DATA_TAG;
int s = int(_value.asArray->size());
for (int i=0; i<s; ++i)
size_t s = _value.asArray->size();
for (size_t i=0; i<s; ++i)
xml += _value.asArray->at(i).toXml();
xml += DATA_ETAG;
@ -497,7 +497,7 @@ namespace XmlRpc {
// Struct
bool XmlRpcValue::structFromXml(std::string const& valueXml, int* offset)
bool XmlRpcValue::structFromXml(std::string const& valueXml, size_t* offset)
{
_type = TypeStruct;
_value.asStruct = new ValueStruct;
@ -572,9 +572,9 @@ namespace XmlRpc {
}
case TypeArray:
{
int s = int(_value.asArray->size());
size_t s = _value.asArray->size();
os << '{';
for (int i=0; i<s; ++i)
for (size_t i=0; i<s; ++i)
{
if (i > 0) os << ',';
_value.asArray->at(i).write(os);

@ -75,13 +75,13 @@ namespace XmlRpc {
//! Construct an XmlRpcValue with a binary data value
//! @param value A pointer to data
//! @param nBytes The length of the data pointed to, in bytes
XmlRpcValue(void* value, int nBytes) : _type(TypeBase64)
XmlRpcValue(void* value, size_t nBytes) : _type(TypeBase64)
{
_value.asBinary = new BinaryData((char*)value, ((char*)value)+nBytes);
}
//! Construct from xml, beginning at *offset chars into the string, updates offset
XmlRpcValue(std::string const& xml, int* offset) : _type(TypeInvalid)
XmlRpcValue(std::string const& xml, size_t* offset) : _type(TypeInvalid)
{ if ( ! fromXml(xml,offset)) _type = TypeInvalid; }
//! Copy constructor
@ -148,12 +148,14 @@ namespace XmlRpc {
//! Access the ith value of the array.
//! Throws XmlRpcException if the value is not an array or if the index i is
//! not a valid index for the array.
XmlRpcValue const& operator[](int i) const { assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue const& operator[](size_t i) const { assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue const& operator[](int i) const { assertArray(i+1); return _value.asArray->at(i); }
//! Array value accessor.
//! Access the ith value of the array, growing the array if necessary.
//! Throws XmlRpcException if the value is not an array.
XmlRpcValue& operator[](int i) { assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue& operator[](size_t i) { assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue& operator[](int i) { assertArray(i+1); return _value.asArray->at(i); }
//! Struct entry accessor.
//! Returns the value associated with the given entry, creating one if necessary.
@ -175,16 +177,16 @@ namespace XmlRpc {
Type const &getType() const { return _type; }
//! Return the size for string, base64, array, and struct values.
int size() const;
size_t size() const;
//! Specify the size for array values. Array values will grow beyond this size if needed.
void setSize(int size) { assertArray(size); }
void setSize(size_t size) { assertArray(size); }
//! Check for the existence of a struct member by name.
bool hasMember(const std::string& name) const;
//! Decode xml. Destroys any existing value.
bool fromXml(std::string const& valueXml, int* offset);
bool fromXml(std::string const& valueXml, size_t* offset);
//! Encode the Value in xml
std::string toXml() const;
@ -206,19 +208,19 @@ namespace XmlRpc {
// Type checking
void assertTypeOrInvalid(Type t);
void assertArray(int size) const;
void assertArray(int size);
void assertArray(size_t size) const;
void assertArray(size_t size);
void assertStruct();
// XML decoding
bool boolFromXml(std::string const& valueXml, int* offset);
bool intFromXml(std::string const& valueXml, int* offset);
bool doubleFromXml(std::string const& valueXml, int* offset);
bool stringFromXml(std::string const& valueXml, int* offset);
bool timeFromXml(std::string const& valueXml, int* offset);
bool binaryFromXml(std::string const& valueXml, int* offset);
bool arrayFromXml(std::string const& valueXml, int* offset);
bool structFromXml(std::string const& valueXml, int* offset);
bool boolFromXml(std::string const& valueXml, size_t* offset);
bool intFromXml(std::string const& valueXml, size_t* offset);
bool doubleFromXml(std::string const& valueXml, size_t* offset);
bool stringFromXml(std::string const& valueXml, size_t* offset);
bool timeFromXml(std::string const& valueXml, size_t* offset);
bool binaryFromXml(std::string const& valueXml, size_t* offset);
bool arrayFromXml(std::string const& valueXml, size_t* offset);
bool structFromXml(std::string const& valueXml, size_t* offset);
// XML encoding
std::string boolToXml() const;

Loading…
Cancel
Save