int main(int argc, char *argv[]) { // careful to understand why we can get these sizes char from[] = "0123456789"; int from_len = sizeof(from); // notice that it's 7 chars + \0 char to[] = "0123456"; int to_len = sizeof(to); debug("Copying '%s':%d to '%s':%d", from, from_len, to, to_len); int rc = safercopy(from_len, from, to_len, to); check(rc > 0, "Failed to safercopy."); check(to[to_len - 1] == '\0', "String not terminated."); debug("Result is: '%s':%d", to, to_len); // now try to break it rc = safercopy(from_len * -1, from, to_len, to); check(rc == -1, "safercopy should fail #1"); check(to[to_len - 1] == '\0', "String not terminated."); rc = safercopy(from_len, from, 0, to); check(rc == -1, "safercopy should fail #2"); check(to[to_len - 1] == '\0', "String not terminated."); return 0; error: return 1; }
int main(int argc, char *argv[]) { char from[] = "0123456789"; int from_len = sizeof(from); char to[] = "6543210"; int to_len = sizeof(to); debug("Copying '%s':%d to '%s':%d", from, from_len, to, to_len); int rc = safercopy(from_len, from, to_len, to); check(rc > 0, "Failed to safercopy"); check(to[to_len - 1] == '\0', "to not null terminated"); debug("Result is: '%s':%d", to, to_len); rc = safercopy(from_len * -1, from, to_len, to); check(rc == -1, "safercopy should fail with negative length"); check(to[to_len - 1] == '\0', "String not terminated"); rc = safercopy(from_len, from, 0, to); check(rc == -1, "safercopy should fail with 0 to length"); check(to[to_len - 1] == '\0', "String not terminated"); return 0; error: return -1; }
int main(int argc, char const *argv[]) { char from[] = "0123456789"; int from_len = sizeof(from); // notice that it's 7 chars + \0 char to[] = "0123456"; int to_len = sizeof(to); debug("Copying '%s: %d to '%s': '%d'", from, from_len, to, to_len); int rc = safercopy(from_len, from, to_len, to); check(rc > 0, "Failed to safercopy"); check(to[to_len -1] == '\0', "String not terminated"); debug("Result is %s:%d", to, to_len); return 0; error: return 1; return 0; }