}
DEF_TEST(strunescape) {
- char buffer[16];
+ char buffer[32] = {0};
int status;
- strncpy(buffer, "foo\\tbar", sizeof(buffer));
+ strncpy(buffer, "foo\\tbar", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status == 0);
EXPECT_EQ_STR("foo\tbar", buffer);
- strncpy(buffer, "\\tfoo\\r\\n", sizeof(buffer));
+ strncpy(buffer, "\\tfoo\\r\\n", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status == 0);
EXPECT_EQ_STR("\tfoo\r\n", buffer);
- strncpy(buffer, "With \\\"quotes\\\"", sizeof(buffer));
+ strncpy(buffer, "With \\\"quotes\\\"", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status == 0);
EXPECT_EQ_STR("With \"quotes\"", buffer);
/* Backslash before null byte */
- strncpy(buffer, "\\tbackslash end\\", sizeof(buffer));
+ strncpy(buffer, "\\tbackslash end\\", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status != 0);
EXPECT_EQ_STR("\tbackslash end", buffer);
return 0;
/* Backslash at buffer end */
- strncpy(buffer, "\\t3\\56", sizeof(buffer));
+ strncpy(buffer, "\\t3\\56", sizeof(buffer) - 1);
status = strunescape(buffer, 4);
OK(status != 0);
OK(buffer[0] == '\t');