2 * Copyright (c) 2017 Juniper Networks. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char *_RESTRICT_KYWD m
;
36 h(const char *_RESTRICT_KYWD msg
, void *_RESTRICT_KYWD ptr
, errno_t error
)
49 set_constraint_handler_s(ignore_handler_s
);
50 assert(memset_s(0, 1, 1, 1) != 0);
53 set_constraint_handler_s(ignore_handler_s
);
54 assert(memset_s(&b
, RSIZE_MAX
+ 1, 1, 1) != 0);
57 set_constraint_handler_s(ignore_handler_s
);
58 assert(memset_s(&a
, -1, 1, 1) != 0);
61 set_constraint_handler_s(ignore_handler_s
);
63 assert(memset_s(&a
, 1, 5, 1) == 0);
67 set_constraint_handler_s(ignore_handler_s
);
68 assert(memset_s(&a
, 1, 1, RSIZE_MAX
+ 1) != 0);
71 set_constraint_handler_s(ignore_handler_s
);
72 assert(memset_s(&a
, 1, 1, -1) != 0);
75 set_constraint_handler_s(ignore_handler_s
);
76 b
[0] = 1; b
[1] = 2; b
[2] = 3;
77 assert(memset_s(&b
[0], 3, 9, 1) == 0);
82 /* n > smax, handler */
83 set_constraint_handler_s(h
);
86 b
[0] = 1; b
[1] = 2; b
[2] = 3;
87 assert(memset_s(&b
[0], 1, 9, 3) != 0);
89 assert(strcmp(m
, "memset_s: n > smax") == 0);
94 /* smax > rmax, handler */
95 set_constraint_handler_s(h
);
98 assert(memset_s(&a
, RSIZE_MAX
+ 1, 1, 1) != 0);
100 assert(strcmp(m
, "memset_s: smax > RSIZE_MAX") == 0);
102 /* smax < 0, handler */
103 set_constraint_handler_s(h
);
106 assert(memset_s(&a
, -1, 1, 1) != 0);
108 assert(strcmp(m
, "memset_s: smax > RSIZE_MAX") == 0);
110 /* n > rmax, handler */
111 set_constraint_handler_s(h
);
114 assert(memset_s(&a
, 1, 1, RSIZE_MAX
+ 1) != 0);
116 assert(strcmp(m
, "memset_s: n > RSIZE_MAX") == 0);
119 set_constraint_handler_s(h
);
122 assert(memset_s(&a
, 1, 1, -1) != 0);
124 assert(strcmp(m
, "memset_s: n > RSIZE_MAX") == 0);