change all length agruments and return types to size_t or ssize_t

This commit is contained in:
2018-06-11 14:19:21 +02:00
parent 7cdf39d61c
commit 0c5227dfc5

View File

@ -38,8 +38,8 @@
class RegexpConverter : public StreamFormatConverter class RegexpConverter : public StreamFormatConverter
{ {
int parse (const StreamFormat& fmt, StreamBuffer&, const char*&, bool); int parse (const StreamFormat& fmt, StreamBuffer&, const char*&, bool);
long scanString(const StreamFormat& fmt, const char*, char*, unsigned long&); ssize_t scanString(const StreamFormat& fmt, const char*, char*, unsigned long&);
long scanPseudo(const StreamFormat& fmt, StreamBuffer& input, long& cursor); ssize_t scanPseudo(const StreamFormat& fmt, StreamBuffer& input, size_t& cursor);
bool printPseudo(const StreamFormat& fmt, StreamBuffer& output); bool printPseudo(const StreamFormat& fmt, StreamBuffer& output);
}; };
@ -56,7 +56,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
{ {
error("Subexpression index %ld too big (>9)\n", fmt.prec); error("Subexpression index %ld too big (>9)\n", fmt.prec);
return false; return false;
} }
StreamBuffer pattern; StreamBuffer pattern;
while (*source != '/') while (*source != '/')
@ -81,10 +81,10 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
} }
source++; source++;
debug("regexp = \"%s\"\n", pattern.expand()()); debug("regexp = \"%s\"\n", pattern.expand()());
const char* errormsg; const char* errormsg;
int eoffset; int eoffset;
pcre* code = pcre_compile(pattern(), 0, pcre* code = pcre_compile(pattern(), 0,
&errormsg, &eoffset, NULL); &errormsg, &eoffset, NULL);
if (!code) if (!code)
{ {
@ -96,7 +96,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
if (fmt.flags & alt_flag) if (fmt.flags & alt_flag)
{ {
StreamBuffer subst; StreamBuffer subst;
debug("check for subst in \"%s\"\n", StreamBuffer(source).expand()()); debug("check for subst in \"%s\"\n", StreamBuffer(source).expand()());
while (*source != '/') while (*source != '/')
{ {
if (!*source) { if (!*source) {
@ -115,9 +115,9 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
return string_format; return string_format;
} }
long RegexpConverter:: ssize_t RegexpConverter::
scanString(const StreamFormat& fmt, const char* input, scanString(const StreamFormat& fmt, const char* input,
char* value, unsigned long& size) char* value, size_t& size)
{ {
int ovector[30]; int ovector[30];
int rc; int rc;
@ -126,10 +126,10 @@ scanString(const StreamFormat& fmt, const char* input,
pcre* code = extract<pcre*>(info); pcre* code = extract<pcre*>(info);
int length = fmt.width > 0 ? fmt.width : strlen(input); int length = fmt.width > 0 ? fmt.width : strlen(input);
int subexpr = fmt.prec > 0 ? fmt.prec : 0; int subexpr = fmt.prec > 0 ? fmt.prec : 0;
debug("input = \"%s\"\n", input); debug("input = \"%s\"\n", input);
debug("length=%d\n", length); debug("length=%d\n", length);
rc = pcre_exec(code, NULL, input, length, 0, 0, ovector, 30); rc = pcre_exec(code, NULL, input, length, 0, 0, ovector, 30);
debug("pcre_exec match \"%.*s\" result = %d\n", length, input, rc); debug("pcre_exec match \"%.*s\" result = %d\n", length, input, rc);
if ((subexpr && rc <= subexpr) || rc < 0) if ((subexpr && rc <= subexpr) || rc < 0)
@ -152,7 +152,7 @@ scanString(const StreamFormat& fmt, const char* input,
memcpy(value, input + ovector[subexpr*2], l); memcpy(value, input + ovector[subexpr*2], l);
value[l] = '\0'; value[l] = '\0';
size = l+1; // update number of bytes written to value size = l+1; // update number of bytes written to value
return ovector[1]; // consume input until end of match return ovector[1]; // consume input until end of match
} }
static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, long start) static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, long start)
@ -172,14 +172,14 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, long start)
debug("regsubst buffer=\"%s\", start=%ld, length=%ld, subst = \"%s\"\n", debug("regsubst buffer=\"%s\", start=%ld, length=%ld, subst = \"%s\"\n",
buffer.expand()(), start, length, subst); buffer.expand()(), start, length, subst);
for (c = 0, n = 1; c < length; n++) for (c = 0, n = 1; c < length; n++)
{ {
rc = pcre_exec(code, NULL, buffer(start+c), length-c, 0, 0, ovector, 30); rc = pcre_exec(code, NULL, buffer(start+c), length-c, 0, 0, ovector, 30);
debug("pcre_exec match \"%.*s\" result = %d\n", (int)(length-c), buffer(start+c), rc); debug("pcre_exec match \"%.*s\" result = %d\n", (int)(length-c), buffer(start+c), rc);
if (rc < 0) // no match if (rc < 0) // no match
return; return;
if (!(fmt.flags & sign_flag) && n < fmt.prec) // without + flag if (!(fmt.flags & sign_flag) && n < fmt.prec) // without + flag
{ {
// do not yet replace this match // do not yet replace this match
@ -229,8 +229,8 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, long start)
} }
} }
long RegexpConverter:: ssize_t RegexpConverter::
scanPseudo(const StreamFormat& fmt, StreamBuffer& input, long& cursor) scanPseudo(const StreamFormat& fmt, StreamBuffer& input, ssize_t& cursor)
{ {
/* re-write input buffer */ /* re-write input buffer */
regsubst(fmt, input, cursor); regsubst(fmt, input, cursor);