• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7
17 #define __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7
18 
19 #ifndef SECUREC_USING_STD_SECURE_LIB
20 #if defined(_MSC_VER) && _MSC_VER >= 1400
21 #if defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__ == 0
22 /* Security functions have been provided since vs2005, default use of system library functions */
23 #define SECUREC_USING_STD_SECURE_LIB    0
24 #else
25 #define SECUREC_USING_STD_SECURE_LIB    1
26 #endif
27 #else
28 #define SECUREC_USING_STD_SECURE_LIB    0
29 #endif
30 #endif
31 
32 
33 /* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */
34 #if defined(_MSC_VER) && _MSC_VER >= 1400 && SECUREC_USING_STD_SECURE_LIB == 0
35 #ifndef SECUREC_DISABLE_CRT_FUNC
36 #define SECUREC_DISABLE_CRT_FUNC        1
37 #endif
38 #ifndef SECUREC_DISABLE_CRT_IMP
39 #define SECUREC_DISABLE_CRT_IMP         1
40 #endif
41 #else /*  MSC VER */
42 #ifndef SECUREC_DISABLE_CRT_FUNC
43 #define SECUREC_DISABLE_CRT_FUNC        0
44 #endif
45 #ifndef SECUREC_DISABLE_CRT_IMP
46 #define SECUREC_DISABLE_CRT_IMP         0
47 #endif
48 #endif
49 
50 #if SECUREC_DISABLE_CRT_FUNC
51 #ifdef __STDC_WANT_SECURE_LIB__
52 #undef __STDC_WANT_SECURE_LIB__
53 #endif
54 #define __STDC_WANT_SECURE_LIB__        0
55 #endif
56 
57 #if SECUREC_DISABLE_CRT_IMP
58 #ifdef _CRTIMP_ALTERNATIVE
59 #undef _CRTIMP_ALTERNATIVE
60 #endif
61 #define _CRTIMP_ALTERNATIVE     /* comment microsoft *_s function */
62 #endif
63 
64 /* Compile in kernel under macro control */
65 #ifndef SECUREC_IN_KERNEL
66 #ifdef __KERNEL__
67 #define SECUREC_IN_KERNEL               1
68 #else
69 #define SECUREC_IN_KERNEL               0
70 #endif
71 #endif
72 
73 #if SECUREC_IN_KERNEL
74 #ifndef SECUREC_ENABLE_SCANF_FILE
75 #define SECUREC_ENABLE_SCANF_FILE       0
76 #endif
77 #ifndef SECUREC_ENABLE_WCHAR_FUNC
78 #define SECUREC_ENABLE_WCHAR_FUNC       0
79 #endif
80 #else /* SECUREC_IN_KERNEL */
81 #ifndef SECUREC_ENABLE_SCANF_FILE
82 #define SECUREC_ENABLE_SCANF_FILE       1
83 #endif
84 #ifndef SECUREC_ENABLE_WCHAR_FUNC
85 #define SECUREC_ENABLE_WCHAR_FUNC       1
86 #endif
87 #endif
88 
89 
90 /* Default secure function declaration, default declarations for non-standard functions */
91 #ifndef SECUREC_SNPRINTF_TRUNCATED
92 #define SECUREC_SNPRINTF_TRUNCATED      1
93 #endif
94 
95 #if SECUREC_USING_STD_SECURE_LIB
96 #if defined(_MSC_VER) && _MSC_VER >= 1400
97 /* Declare secure functions that are not available in the vs compiler */
98 #ifndef SECUREC_ENABLE_MEMSET
99 #define SECUREC_ENABLE_MEMSET           1
100 #endif
101 /* vs 2005 have vsnprintf_s function */
102 #ifndef SECUREC_ENABLE_VSNPRINTF
103 #define SECUREC_ENABLE_VSNPRINTF        0
104 #endif
105 #ifndef SECUREC_ENABLE_SNPRINTF
106 /* vs 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */
107 #define snprintf_s _snprintf_s
108 #define SECUREC_ENABLE_SNPRINTF         0
109 #endif
110 /* befor vs 2010 do not have v functions */
111 #if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS)
112 #ifndef SECUREC_ENABLE_VFSCANF
113 #define SECUREC_ENABLE_VFSCANF          1
114 #endif
115 #ifndef SECUREC_ENABLE_VSCANF
116 #define SECUREC_ENABLE_VSCANF           1
117 #endif
118 #ifndef SECUREC_ENABLE_VSSCANF
119 #define SECUREC_ENABLE_VSSCANF          1
120 #endif
121 #endif
122 
123 #else /* _MSC_VER */
124 #ifndef SECUREC_ENABLE_MEMSET
125 #define SECUREC_ENABLE_MEMSET           0
126 #endif
127 #ifndef SECUREC_ENABLE_SNPRINTF
128 #define SECUREC_ENABLE_SNPRINTF         0
129 #endif
130 #ifndef SECUREC_ENABLE_VSNPRINTF
131 #define SECUREC_ENABLE_VSNPRINTF        0
132 #endif
133 #endif
134 
135 #ifndef SECUREC_ENABLE_MEMMOVE
136 #define SECUREC_ENABLE_MEMMOVE          0
137 #endif
138 #ifndef SECUREC_ENABLE_MEMCPY
139 #define SECUREC_ENABLE_MEMCPY           0
140 #endif
141 #ifndef SECUREC_ENABLE_STRCPY
142 #define SECUREC_ENABLE_STRCPY           0
143 #endif
144 #ifndef SECUREC_ENABLE_STRNCPY
145 #define SECUREC_ENABLE_STRNCPY          0
146 #endif
147 #ifndef SECUREC_ENABLE_STRCAT
148 #define SECUREC_ENABLE_STRCAT           0
149 #endif
150 #ifndef SECUREC_ENABLE_STRNCAT
151 #define SECUREC_ENABLE_STRNCAT          0
152 #endif
153 #ifndef SECUREC_ENABLE_SPRINTF
154 #define SECUREC_ENABLE_SPRINTF          0
155 #endif
156 #ifndef SECUREC_ENABLE_VSPRINTF
157 #define SECUREC_ENABLE_VSPRINTF          0
158 #endif
159 #ifndef SECUREC_ENABLE_SSCANF
160 #define SECUREC_ENABLE_SSCANF           0
161 #endif
162 #ifndef SECUREC_ENABLE_VSSCANF
163 #define SECUREC_ENABLE_VSSCANF          0
164 #endif
165 #ifndef SECUREC_ENABLE_SCANF
166 #define SECUREC_ENABLE_SCANF            0
167 #endif
168 #ifndef SECUREC_ENABLE_VSCANF
169 #define SECUREC_ENABLE_VSCANF           0
170 #endif
171 
172 #ifndef SECUREC_ENABLE_FSCANF
173 #define SECUREC_ENABLE_FSCANF           0
174 #endif
175 #ifndef SECUREC_ENABLE_VFSCANF
176 #define SECUREC_ENABLE_VFSCANF          0
177 #endif
178 #ifndef SECUREC_ENABLE_STRTOK
179 #define SECUREC_ENABLE_STRTOK           0
180 #endif
181 #ifndef SECUREC_ENABLE_GETS
182 #define SECUREC_ENABLE_GETS             0
183 #endif
184 
185 #else /* SECUREC_USE_STD_SECURE_LIB */
186 
187 #ifndef SECUREC_ENABLE_MEMSET
188 #define SECUREC_ENABLE_MEMSET           1
189 #endif
190 #ifndef SECUREC_ENABLE_MEMMOVE
191 #define SECUREC_ENABLE_MEMMOVE          1
192 #endif
193 #ifndef SECUREC_ENABLE_MEMCPY
194 #define SECUREC_ENABLE_MEMCPY           1
195 #endif
196 #ifndef SECUREC_ENABLE_STRCPY
197 #define SECUREC_ENABLE_STRCPY           1
198 #endif
199 #ifndef SECUREC_ENABLE_STRNCPY
200 #define SECUREC_ENABLE_STRNCPY          1
201 #endif
202 #ifndef SECUREC_ENABLE_STRCAT
203 #define SECUREC_ENABLE_STRCAT           1
204 #endif
205 #ifndef SECUREC_ENABLE_STRNCAT
206 #define SECUREC_ENABLE_STRNCAT          1
207 #endif
208 #ifndef SECUREC_ENABLE_SPRINTF
209 #define SECUREC_ENABLE_SPRINTF          1
210 #endif
211 #ifndef SECUREC_ENABLE_VSPRINTF
212 #define SECUREC_ENABLE_VSPRINTF          1
213 #endif
214 #ifndef SECUREC_ENABLE_SNPRINTF
215 #define SECUREC_ENABLE_SNPRINTF         1
216 #endif
217 #ifndef SECUREC_ENABLE_VSNPRINTF
218 #define SECUREC_ENABLE_VSNPRINTF        1
219 #endif
220 #ifndef SECUREC_ENABLE_SSCANF
221 #define SECUREC_ENABLE_SSCANF           1
222 #endif
223 #ifndef SECUREC_ENABLE_VSSCANF
224 #define SECUREC_ENABLE_VSSCANF          1
225 #endif
226 #ifndef SECUREC_ENABLE_SCANF
227 #if SECUREC_ENABLE_SCANF_FILE
228 #define SECUREC_ENABLE_SCANF            1
229 #else
230 #define SECUREC_ENABLE_SCANF            0
231 #endif
232 #endif
233 #ifndef SECUREC_ENABLE_VSCANF
234 #if SECUREC_ENABLE_SCANF_FILE
235 #define SECUREC_ENABLE_VSCANF           1
236 #else
237 #define SECUREC_ENABLE_VSCANF           0
238 #endif
239 #endif
240 
241 #ifndef SECUREC_ENABLE_FSCANF
242 #if SECUREC_ENABLE_SCANF_FILE
243 #define SECUREC_ENABLE_FSCANF           1
244 #else
245 #define SECUREC_ENABLE_FSCANF           0
246 #endif
247 #endif
248 #ifndef SECUREC_ENABLE_VFSCANF
249 #if SECUREC_ENABLE_SCANF_FILE
250 #define SECUREC_ENABLE_VFSCANF          1
251 #else
252 #define SECUREC_ENABLE_VFSCANF          0
253 #endif
254 #endif
255 
256 #ifndef SECUREC_ENABLE_STRTOK
257 #define SECUREC_ENABLE_STRTOK           1
258 #endif
259 #ifndef SECUREC_ENABLE_GETS
260 #define SECUREC_ENABLE_GETS             1
261 #endif
262 #endif /* SECUREC_USE_STD_SECURE_LIB */
263 
264 #if SECUREC_ENABLE_SCANF_FILE == 0
265 #if SECUREC_ENABLE_FSCANF
266 #undef SECUREC_ENABLE_FSCANF
267 #define SECUREC_ENABLE_FSCANF           0
268 #endif
269 #if SECUREC_ENABLE_VFSCANF
270 #undef SECUREC_ENABLE_VFSCANF
271 #define SECUREC_ENABLE_VFSCANF          0
272 #endif
273 #if SECUREC_ENABLE_SCANF
274 #undef SECUREC_ENABLE_SCANF
275 #define SECUREC_ENABLE_SCANF            0
276 #endif
277 #if SECUREC_ENABLE_FSCANF
278 #undef SECUREC_ENABLE_FSCANF
279 #define SECUREC_ENABLE_FSCANF           0
280 #endif
281 
282 #endif
283 
284 #if SECUREC_IN_KERNEL
285 #include <linux/kernel.h>
286 #include <linux/module.h>
287 #else
288 #include <cstdio>
289 #include <cstring>
290 #include <cstdlib>
291 #endif
292 
293 /* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable .
294  * The macro is automatically closed on the windows platform and linux kernel
295  */
296 #ifndef SECUREC_WITH_PERFORMANCE_ADDONS
297 #if SECUREC_IN_KERNEL
298 #define SECUREC_WITH_PERFORMANCE_ADDONS 0
299 #else
300 #define SECUREC_WITH_PERFORMANCE_ADDONS 1
301 #endif
302 #endif
303 
304 /* if enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */
305 #if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
306 #if !defined(SECUREC_COMPATIBLE_WIN_FORMAT)
307 #define SECUREC_COMPATIBLE_WIN_FORMAT
308 #endif
309 #endif
310 
311 #if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
312 /* in windows platform, can't use optimized function for there is no __builtin_constant_p like function */
313 /* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */
314 #ifdef SECUREC_WITH_PERFORMANCE_ADDONS
315 #undef SECUREC_WITH_PERFORMANCE_ADDONS
316 #define SECUREC_WITH_PERFORMANCE_ADDONS 0
317 #endif
318 #endif
319 
320 #if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_)  || \
321     defined(SECUREC_VXWORKS_VERSION_5_4)
322 #if !defined(SECUREC_VXWORKS_PLATFORM)
323 #define SECUREC_VXWORKS_PLATFORM
324 #endif
325 #endif
326 
327 /* if enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */
328 #if !(defined(SECUREC_COMPATIBLE_WIN_FORMAT) || defined(SECUREC_VXWORKS_PLATFORM))
329 #if !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
330 #define SECUREC_COMPATIBLE_LINUX_FORMAT
331 #endif
332 #endif
333 
334 #ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
335 #include <stddef.h>
336 #endif
337 
338 /* add  the -DSECUREC_SUPPORT_FORMAT_WARNING  compiler option to supoort  -Wformat.
339  * default does not check the format is that the same data type in the actual code
340  * in the product is different in the original data type definition of VxWorks and Linux.
341  */
342 #ifndef SECUREC_SUPPORT_FORMAT_WARNING
343 #define SECUREC_SUPPORT_FORMAT_WARNING 0
344 #endif
345 
346 /* SECUREC_PCLINT for tool do not recognize __attribute__  just for pclint */
347 #if SECUREC_SUPPORT_FORMAT_WARNING && !defined(SECUREC_PCLINT)
348 #define SECUREC_ATTRIBUTE(x, y)  __attribute__((format(printf, (x), (y))))
349 #else
350 #define SECUREC_ATTRIBUTE(x, y)
351 #endif
352 
353 /* SECUREC_PCLINT for tool do not recognize __builtin_expect, just for pclint */
354 #if defined(__GNUC__) && \
355     ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) && \
356     !defined(SECUREC_PCLINT)
357 /* This is a built-in function that can be used without a declaration, if you encounter an undeclared compilation alarm,
358  * you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options
359  */
360 #if defined(SECUREC_NEED_BUILTIN_EXPECT_DECLARE)
361 long __builtin_expect(long exp, long c);
362 #endif
363 #define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1)
364 #define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0)
365 #else
366 #define SECUREC_LIKELY(x) (x)
367 #define SECUREC_UNLIKELY(x) (x)
368 #endif
369 
370 /* define the max length of the string */
371 #ifndef SECUREC_STRING_MAX_LEN
372 #define SECUREC_STRING_MAX_LEN (0x7fffffffUL)
373 #endif
374 #define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t))
375 
376 /* add SECUREC_MEM_MAX_LEN for memcpy and memmove */
377 #ifndef SECUREC_MEM_MAX_LEN
378 #define SECUREC_MEM_MAX_LEN (0x7fffffffUL)
379 #endif
380 #define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t))
381 
382 #if SECUREC_STRING_MAX_LEN > 0x7fffffff
383 #error "max string is 2G"
384 #endif
385 
386 #if (defined(__GNUC__) && defined(__SIZEOF_POINTER__))
387 #if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8)
388 #error "unsupported system"
389 #endif
390 #endif
391 
392 #if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64)
393 #define SECUREC_ON_64BITS
394 #endif
395 
396 #if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__))
397 #if __SIZEOF_POINTER__ == 8
398 #define SECUREC_ON_64BITS
399 #endif
400 #endif
401 
402 #if defined(__SVR4) || defined(__svr4__)
403 #define SECUREC_ON_SOLARIS
404 #endif
405 
406 #if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS))
407 #define SECUREC_ON_UNIX
408 #endif
409 
410 /* codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default,
411  * and strtold. The function
412  * strtold is referenced first at ISO9899:1999(C99), and some old compilers can
413  * not support these functions. Here provides a macro to open these functions:
414  * SECUREC_SUPPORT_STRTOLD  -- if defined, strtold will   be used
415  */
416 #ifndef SECUREC_SUPPORT_STRTOLD
417 #define SECUREC_SUPPORT_STRTOLD 0
418 #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT))
419 #if defined(__USE_ISOC99)  || \
420     (defined(_AIX) && defined(_ISOC99_SOURCE)) || \
421     (defined(__hpux) && defined(__ia64)) || \
422     (defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
423     defined(_STDC_C99) || defined(__EXTENSIONS__))
424 #undef  SECUREC_SUPPORT_STRTOLD
425 #define SECUREC_SUPPORT_STRTOLD 1
426 #endif
427 #endif
428 #if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_)))
429 #undef  SECUREC_SUPPORT_STRTOLD
430 #define SECUREC_SUPPORT_STRTOLD 0
431 #endif
432 #endif
433 
434 
435 #if SECUREC_WITH_PERFORMANCE_ADDONS
436 
437 #ifndef SECUREC_TWO_MIN
438 #define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b))
439 #endif
440 
441 /* for strncpy_s performance optimization */
442 #define SECUREC_STRNCPY_SM(dest, destMax, src, count) \
443     (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
444     (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
445     (SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \
446     (((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \
447     (memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count))))
448 
449 #define SECUREC_STRCPY_SM(dest, destMax, src) \
450     (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
451     (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
452     (strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \
453     (strcpy_error((dest), (destMax), (src))))
454 
455 /* for strcat_s performance optimization */
456 #if defined(__GNUC__)
457 #define SECUREC_STRCAT_SM(dest, destMax, src) ({ \
458     int catRet = EOK; \
459     if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
460         (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
461         char *catTmpDst = (char *)(dest); \
462         size_t catRestSize = (destMax); \
463         while (catRestSize > 0 && *catTmpDst != '\0') { \
464             ++catTmpDst; \
465             --catRestSize; \
466         } \
467         if (catRestSize == 0) { \
468             catRet = EINVAL; \
469         } else if ((strlen(src) + 1) <= catRestSize) { \
470             memcpy(catTmpDst, (src), strlen(src) + 1); \
471             catRet = EOK; \
472         } else { \
473             catRet = ERANGE; \
474         } \
475         if (catRet != EOK) { \
476             catRet = strcat_s((dest), (destMax), (src)); \
477         } \
478     } else { \
479         catRet = strcat_s((dest), (destMax), (src)); \
480     } \
481     catRet; \
482 })
483 #else
484 #define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src))
485 #endif
486 
487 /* for strncat_s performance optimization */
488 #if defined(__GNUC__)
489 #define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \
490     int ncatRet = EOK; \
491     if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
492         (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)  && \
493         (((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
494         char *ncatTmpDest = (char *)(dest); \
495         size_t ncatRestSize = (size_t)(destMax); \
496         while (ncatRestSize > 0 && *ncatTmpDest != '\0') { \
497             ++ncatTmpDest; \
498             --ncatRestSize; \
499         } \
500         if (ncatRestSize == 0) { \
501             ncatRet = EINVAL; \
502         } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize) { \
503             if ((size_t)(count) < strlen(src)) { \
504                 memcpy(ncatTmpDest, (src), (count)); \
505                 *(ncatTmpDest + (count)) = '\0'; \
506             } else { \
507                 memcpy(ncatTmpDest, (src), strlen(src) + 1); \
508             } \
509         } else { \
510             ncatRet = ERANGE; \
511         } \
512         if (ncatRet != EOK) { \
513             ncatRet = strncat_s((dest), (destMax), (src), (count)); \
514         } \
515     } else { \
516         ncatRet = strncat_s((dest), (destMax), (src), (count)); \
517     } \
518     ncatRet; \
519 })
520 #else
521 #define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count))
522 #endif
523 
524 /* SECUREC_MEMCPY_SM do NOT check buffer overlap by default */
525 #define  SECUREC_MEMCPY_SM(dest, destMax, src, count) \
526     (!(((size_t)(destMax) == 0) || \
527         (((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
528         ((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL))? \
529         (memcpy((dest), (src), (count)), EOK) : \
530         (memcpy_s((dest), (destMax), (src), (count))))
531 
532 #define  SECUREC_MEMSET_SM(dest, destMax, c, count) \
533     (!(((size_t)(destMax) == 0) || \
534         (((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
535         ((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \
536         (memset((dest), (c), (count)), EOK) : \
537         (memset_s((dest), (destMax), (c), (count))))
538 
539 #endif
540 #endif /* __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 */
541 
542