int StrBufRemove_token(StrBuf *Source, int parmnum, char separator)
{
int ReducedBy;
- char *d, *s; /* dest, source */
+ char *d, *s, *end; /* dest, source */
int count = 0;
/* Find desired @parameter */
+ end = Source->buf + Source->BufUsed;
d = Source->buf;
- while (count < parmnum) {
+ while ((count < parmnum) &&
+ (d <= end))
+ {
/* End of string, bail! */
if (!*d) {
d = NULL;
}
d++;
}
- if (!d) return 0; /* @Parameter not found */
+ if ((d == NULL) || (d >= end))
+ return 0; /* @Parameter not found */
/* Find next @parameter */
s = d;
- while (*s && *s != separator) {
+ while ((*s && *s != separator) &&
+ (s <= end))
+ {
s++;
}
if (*s == separator)
}
+static void TestStrBufRemove_token_NotThere(void)
+{
+ StrBuf *Test = NewStrBufPlain(HKEY(" 127.0.0.1"));
+ StrBufRemove_token(Test, 0, ',');
+ TestRevalidateStrBuf(Test);
+ FreeStrBuf(&Test);
+}
/*
Some samples from the original...
*/
+
+
+
static void AddStrBufSimlpeTests(void)
{
CU_pSuite pGroup = NULL;
pTest = CU_add_test(pGroup, "TestNextLine_twolines", TestNextLine_twolines);
pTest = CU_add_test(pGroup, "TestNextLine_LongLine", TestNextLine_LongLine);
+ pGroup = CU_add_suite("TestStrBufRemove_token", NULL, NULL);
+ pTest = CU_add_test(pGroup, "TestStrBufRemove_token_NotThere", TestStrBufRemove_token_NotThere);
}