Lines 42-63
memset_s(void *s, rsize_t smax, int c, rsize_t n)
Link Here
|
42 |
volatile unsigned char *dst; |
42 |
volatile unsigned char *dst; |
43 |
|
43 |
|
44 |
ret = EINVAL; |
44 |
ret = EINVAL; |
45 |
lim = smax; |
45 |
lim = (n < smax) ? n : smax; |
46 |
v = (unsigned char)c; |
46 |
v = (unsigned char)c; |
47 |
dst = (unsigned char *)s; |
47 |
dst = (unsigned char *)s; |
48 |
if (s == NULL) { |
48 |
if (s == NULL) { |
49 |
__throw_constraint_handler_s("memset_s : s is NULL", ret); |
49 |
__throw_constraint_handler_s("memset_s : s is NULL", ret); |
50 |
} else if (smax > RSIZE_MAX) { |
50 |
} else if (smax > RSIZE_MAX) { |
51 |
__throw_constraint_handler_s("memset_s : smax > RSIZE_MAX", |
51 |
__throw_constraint_handler_s("memset_s : smax > RSIZE_MAX", |
52 |
ret); |
52 |
ret); |
53 |
} else if (n > RSIZE_MAX) { |
53 |
} else if (n > RSIZE_MAX) { |
54 |
__throw_constraint_handler_s("memset_s : n > RSIZE_MAX", ret); |
54 |
__throw_constraint_handler_s("memset_s : n > RSIZE_MAX", ret); |
55 |
} else { |
55 |
} else { |
56 |
if (n < smax) |
|
|
57 |
lim = n; |
58 |
while (lim > 0) |
56 |
while (lim > 0) |
59 |
dst[--lim] = v; |
57 |
dst[--lim] = v; |
60 |
ret = 0; |
58 |
if (n > smax) { |
|
|
59 |
__throw_constraint_handler_s("memset_s : n > smax", |
60 |
ret); |
61 |
} else { |
62 |
ret = 0; |
63 |
} |
61 |
} |
64 |
} |
62 |
return (ret); |
65 |
return (ret); |
63 |
} |
66 |
} |