Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
553 | serge | 1 | /**************************************************************************** |
2 | * |
||
3 | * Open Watcom Project |
||
4 | * |
||
5 | * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
||
6 | * |
||
7 | * ======================================================================== |
||
8 | * |
||
9 | * This file contains Original Code and/or Modifications of Original |
||
10 | * Code as defined in and that are subject to the Sybase Open Watcom |
||
11 | * Public License version 1.0 (the 'License'). You may not use this file |
||
12 | * except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
||
13 | * ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
||
14 | * provided with the Original Code and Modifications, and is also |
||
15 | * available at www.sybase.com/developer/opensource. |
||
16 | * |
||
17 | * The Original Code and all software distributed under the License are |
||
18 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||
19 | * EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
||
20 | * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
||
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
||
22 | * NON-INFRINGEMENT. Please see the License for the specific language |
||
23 | * governing rights and limitations under the License. |
||
24 | * |
||
25 | * ======================================================================== |
||
26 | * |
||
27 | * Description: Implementation of memmove_s() - bounds-checking memmove(). |
||
28 | * |
||
29 | ****************************************************************************/ |
||
30 | |||
31 | |||
32 | #include "variety.h" |
||
33 | #include "saferlib.h" |
||
34 | #include "widechar.h" |
||
35 | #include |
||
36 | #include |
||
37 | #include "xstring.h" |
||
38 | |||
39 | _WCRTLINK errno_t __F_NAME(memmove_s,wmemmove_s)( VOID_WC_TYPE * __restrict s1, |
||
40 | rsize_t s1max, |
||
41 | const VOID_WC_TYPE * __restrict s2, |
||
42 | rsize_t n ) |
||
43 | /*******************************************************************************/ |
||
44 | { |
||
45 | errno_t rc = -1; |
||
46 | const char *msg; |
||
47 | |||
48 | |||
49 | // Verify runtime-constraints |
||
50 | // s1 not NULL |
||
51 | // s2 not NULL |
||
52 | // s1max <= RSIZE_MAX |
||
53 | // n <= RSIZE_MAX |
||
54 | // n <= s1max |
||
55 | if( __check_constraint_nullptr_msg( msg, s1 ) && |
||
56 | __check_constraint_nullptr_msg( msg, s2 ) && |
||
57 | __check_constraint_maxsize_msg( msg, s1max ) && |
||
58 | __check_constraint_maxsize_msg( msg, n ) && |
||
59 | __check_constraint_a_gt_b_msg( msg, n, s1max ) ) { |
||
60 | |||
61 | /* now it's safe to use memmove */ |
||
62 | __F_NAME(memmove,wmemmove)( s1, s2, n ); |
||
63 | rc = 0; |
||
64 | } else { |
||
65 | // Runtime-constraints violated, zero out destination array |
||
66 | if( (s1 != NULL) && __lte_rsizmax( s1max ) ) { |
||
67 | __F_NAME(memset,wmemset)( s1, 0, s1max ); |
||
68 | } |
||
69 | // Now call the handler |
||
70 | __rtct_fail( __func__, msg, NULL ); |
||
71 | } |
||
72 | |||
73 | return( rc ); |
||
74 | }=>=>=> |