return false;
}
+
+// ensure error message is terminated with newline and terminated with standard c-string nul
+void scan_and_terminate_str(POOL_MEM &buf, int msglen)
+{
+ if (msglen >= 0){
+ // we will consume at most two chars more
+ buf.check_size(msglen + 2);
+ bool check = msglen > 0 ? buf.c_str()[msglen - 1] != '\n' : true;
+ buf.c_str()[msglen] = check * '\n';
+ buf.c_str()[msglen + 1] = '\0';
+ }
+}
bool scan_parameter_str(const char * cmd, const char *prefix, POOL_MEM ¶m);
inline bool scan_parameter_str(const POOL_MEM &cmd, const char *prefix, POOL_MEM ¶m) { return scan_parameter_str(cmd.c_str(), prefix, param); }
-#endif /* _PLUGINLIB_H_ */
+void scan_and_terminate_str(POOL_MEM &buf, int msglen);
+#endif /* _PLUGINLIB_H_ */
ok(result == testvect1[i].result, testvect1[i].descr);
}
+ struct strvectstruct
+ {
+ const char *input;
+ const char *output;
+ const int msglen;
+ const int len;
+ const char *descr;
+ };
+ const strvectstruct testvect2[] = {
+ { "TEST1****", "TEST1\n\0", 5, 7, "TEST1" },
+ { "TEST2\n****", "TEST2\n\0", 6, 7, "TEST2" },
+ { "TEST3\n\0****", "TEST3\n\0", 7, 7, "TEST3" },
+ { "TEST4\0****", "TEST4\n\0", 6, 7, "TEST4" },
+ { "TEST5\0\n****", "TEST5\n\0", 7, 7, "TEST5" },
+ { "****", "\n\0", 0, 2, "Test empty" },
+ { NULL, NULL, 0, 0, NULL },
+ };
+
+ POOL_MEM ebuf(PM_NAME);
+ for (int i = 0; testvect2[i].input != NULL; i++)
+ {
+ pm_memcpy(ebuf, testvect2[i].input, strlen(testvect2[i].input));
+ scan_and_terminate_str(ebuf, testvect2[i].msglen);
+ ok(memcmp(ebuf.c_str(), testvect2[i].output, testvect2[i].len) == 0, testvect2[i].descr);
+ }
+ // scan_and_terminate_str
+
return report();
}
return -1;
}
- // ensure error message is terminated with newline and
- // terminated with standard c-string nul
- errmsg.c_str()[msglen] = errmsg.c_str()[msglen - 1] != '\n' ? '\n' : '\0';
- errmsg.c_str()[msglen + 1] = '\0';
+ // ensure error message is terminated with newline and terminated with standard c-string nul
+ scan_and_terminate_str(errmsg, msglen);
switch (header.status)
{