MCPcopy Create free account
hub / github.com/coreboot/coreboot / test_strncpy

Function test_strncpy

tests/lib/string-test.c:96–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96static void test_strncpy(void **state)
97{
98 int i;
99 int n1 = 2, n2 = 8;
100 char src[] = "Hello";
101 char dst[sizeof(src) + 5];
102 size_t src_len = __builtin_strlen(src);
103 size_t dst_len = sizeof(dst);
104
105 /* n1 case */
106
107 /* Needed for ensuring that characters behind the limit
108 are not overwritten */
109 memset(dst, 'x', dst_len);
110
111 strncpy(dst, src, n1);
112
113 assert_int_equal(0, memcmp(dst, src, n1));
114
115 for (i = n1; i < dst_len; i++)
116 assert_true(dst[i] == 'x');
117
118 /* n2 case: */
119
120 memset(dst, 'x', dst_len);
121
122 strncpy(dst, src, n2);
123
124 assert_int_equal(0, memcmp(dst, src, src_len));
125
126 for (i = src_len; i < n2; i++)
127 assert_true(dst[i] == '\0');
128
129 for (i = n2; i < dst_len; i++)
130 assert_true(dst[i] == 'x');
131}
132
133static void test_strcpy(void **state)
134{

Callers

nothing calls this directly

Calls 3

memsetFunction · 0.50
strncpyFunction · 0.50
memcmpFunction · 0.50

Tested by

no test coverage detected