Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
9582f5c7
Commit
9582f5c7
authored
Nov 16, 2007
by
Stefan Dösinger
Committed by
Alexandre Julliard
Nov 16, 2007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: Implement strcat_s.
parent
18daed62
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
0 deletions
+96
-0
msvcrt.spec
dlls/msvcrt/msvcrt.spec
+1
-0
string.c
dlls/msvcrt/string.c
+29
-0
string.c
dlls/msvcrt/tests/string.c
+66
-0
No files found.
dlls/msvcrt/msvcrt.spec
View file @
9582f5c7
...
...
@@ -711,6 +711,7 @@
@ cdecl srand(long) MSVCRT_srand
@ varargs sscanf(str str) MSVCRT_sscanf
@ cdecl strcat(str str) ntdll.strcat
@ cdecl strcat_s(str long str) MSVCRT_strcat_s
@ cdecl strchr(str long) ntdll.strchr
@ cdecl strcmp(str str) ntdll.strcmp
@ cdecl strcoll(str str) MSVCRT_strcoll
...
...
dlls/msvcrt/string.c
View file @
9582f5c7
...
...
@@ -176,6 +176,35 @@ int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
}
/*********************************************************************
* strcat_s (MSVCRT.@)
*/
int
CDECL
MSVCRT_strcat_s
(
char
*
dst
,
MSVCRT_size_t
elem
,
const
char
*
src
)
{
MSVCRT_size_t
i
,
j
;
if
(
!
dst
)
return
EINVAL
;
if
(
elem
==
0
)
return
EINVAL
;
if
(
!
src
)
{
dst
[
0
]
=
'\0'
;
return
EINVAL
;
}
for
(
i
=
0
;
i
<
elem
;
i
++
)
{
if
(
dst
[
i
]
==
'\0'
)
{
for
(
j
=
0
;
(
j
+
i
)
<
elem
;
j
++
)
{
if
((
dst
[
j
+
i
]
=
src
[
j
])
==
'\0'
)
return
0
;
}
}
}
/* Set the first element to 0, not the first element after the skipped part */
dst
[
0
]
=
'\0'
;
return
ERANGE
;
}
/*********************************************************************
* strxfrm (MSVCRT.@)
*/
MSVCRT_size_t
CDECL
MSVCRT_strxfrm
(
char
*
dest
,
const
char
*
src
,
MSVCRT_size_t
len
)
...
...
dlls/msvcrt/tests/string.c
View file @
9582f5c7
...
...
@@ -48,6 +48,7 @@ static char *buf_to_string(const unsigned char *bin, int len, int nr)
static
void
*
(
*
pmemcpy
)(
void
*
,
const
void
*
,
size_t
n
);
static
int
*
(
*
pmemcmp
)(
void
*
,
const
void
*
,
size_t
n
);
static
int
(
*
pstrcpy_s
)(
char
*
dst
,
size_t
len
,
const
char
*
src
);
static
int
(
*
pstrcat_s
)(
char
*
dst
,
size_t
len
,
const
char
*
src
);
#define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
#define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
...
...
@@ -450,6 +451,69 @@ static void test_strcpy_s(void)
ok
(
ret
==
EINVAL
,
"Copying a big string a NULL dest returned %d, expected EINVAL
\n
"
,
ret
);
}
static
void
test_strcat_s
(
void
)
{
char
dest
[
8
];
const
char
*
small
=
"sma"
;
int
ret
;
if
(
!
pstrcat_s
)
{
skip
(
"strcat_s not found
\n
"
);
return
;
}
memset
(
dest
,
'X'
,
sizeof
(
dest
));
dest
[
0
]
=
'\0'
;
ret
=
pstrcat_s
(
dest
,
sizeof
(
dest
),
small
);
ok
(
ret
==
0
,
"strcat_s: Copying a string into a big enough destination returned %d, expected 0
\n
"
,
ret
);
ok
(
dest
[
0
]
==
's'
&&
dest
[
1
]
==
'm'
&&
dest
[
2
]
==
'a'
&&
dest
[
3
]
==
'\0'
&&
dest
[
4
]
==
'X'
&&
dest
[
5
]
==
'X'
&&
dest
[
6
]
==
'X'
&&
dest
[
7
]
==
'X'
,
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
\n
"
,
dest
[
0
],
dest
[
1
],
dest
[
2
],
dest
[
3
],
dest
[
4
],
dest
[
5
],
dest
[
6
],
dest
[
7
]);
ret
=
pstrcat_s
(
dest
,
sizeof
(
dest
),
small
);
ok
(
ret
==
0
,
"strcat_s: Attaching a string to a big enough destination returned %d, expected 0
\n
"
,
ret
);
ok
(
dest
[
0
]
==
's'
&&
dest
[
1
]
==
'm'
&&
dest
[
2
]
==
'a'
&&
dest
[
3
]
==
's'
&&
dest
[
4
]
==
'm'
&&
dest
[
5
]
==
'a'
&&
dest
[
6
]
==
'\0'
&&
dest
[
7
]
==
'X'
,
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
\n
"
,
dest
[
0
],
dest
[
1
],
dest
[
2
],
dest
[
3
],
dest
[
4
],
dest
[
5
],
dest
[
6
],
dest
[
7
]);
ret
=
pstrcat_s
(
dest
,
sizeof
(
dest
),
small
);
ok
(
ret
==
ERANGE
,
"strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE
\n
"
,
ret
);
ok
(
dest
[
0
]
==
'\0'
&&
dest
[
1
]
==
'm'
&&
dest
[
2
]
==
'a'
&&
dest
[
3
]
==
's'
&&
dest
[
4
]
==
'm'
&&
dest
[
5
]
==
'a'
&&
dest
[
6
]
==
's'
&&
dest
[
7
]
==
'm'
,
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
\n
"
,
dest
[
0
],
dest
[
1
],
dest
[
2
],
dest
[
3
],
dest
[
4
],
dest
[
5
],
dest
[
6
],
dest
[
7
]);
memset
(
dest
,
'X'
,
sizeof
(
dest
));
dest
[
0
]
=
'a'
;
dest
[
1
]
=
'\0'
;
ret
=
pstrcat_s
(
dest
,
0
,
small
);
ok
(
ret
==
EINVAL
,
"strcat_s: Source len = 0 returned %d, expected EINVAL
\n
"
,
ret
);
ok
(
dest
[
0
]
==
'a'
&&
dest
[
1
]
==
'\0'
&&
dest
[
2
]
==
'X'
&&
dest
[
3
]
==
'X'
&&
dest
[
4
]
==
'X'
&&
dest
[
5
]
==
'X'
&&
dest
[
6
]
==
'X'
&&
dest
[
7
]
==
'X'
,
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
\n
"
,
dest
[
0
],
dest
[
1
],
dest
[
2
],
dest
[
3
],
dest
[
4
],
dest
[
5
],
dest
[
6
],
dest
[
7
]);
ret
=
pstrcat_s
(
dest
,
0
,
NULL
);
ok
(
ret
==
EINVAL
,
"strcat_s: len = 0 and src = NULL returned %d, expected EINVAL
\n
"
,
ret
);
ok
(
dest
[
0
]
==
'a'
&&
dest
[
1
]
==
'\0'
&&
dest
[
2
]
==
'X'
&&
dest
[
3
]
==
'X'
&&
dest
[
4
]
==
'X'
&&
dest
[
5
]
==
'X'
&&
dest
[
6
]
==
'X'
&&
dest
[
7
]
==
'X'
,
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
\n
"
,
dest
[
0
],
dest
[
1
],
dest
[
2
],
dest
[
3
],
dest
[
4
],
dest
[
5
],
dest
[
6
],
dest
[
7
]);
ret
=
pstrcat_s
(
dest
,
sizeof
(
dest
),
NULL
);
ok
(
ret
==
EINVAL
,
"strcat_s: Sourcing from NULL returned %d, expected EINVAL
\n
"
,
ret
);
ok
(
dest
[
0
]
==
'\0'
&&
dest
[
1
]
==
'\0'
&&
dest
[
2
]
==
'X'
&&
dest
[
3
]
==
'X'
&&
dest
[
4
]
==
'X'
&&
dest
[
5
]
==
'X'
&&
dest
[
6
]
==
'X'
&&
dest
[
7
]
==
'X'
,
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
\n
"
,
dest
[
0
],
dest
[
1
],
dest
[
2
],
dest
[
3
],
dest
[
4
],
dest
[
5
],
dest
[
6
],
dest
[
7
]);
ret
=
pstrcat_s
(
NULL
,
sizeof
(
dest
),
small
);
ok
(
ret
==
EINVAL
,
"strcat_s: Writing to a NULL string returned %d, expected EINVAL
\n
"
,
ret
);
}
START_TEST
(
string
)
{
char
mem
[
100
];
...
...
@@ -463,6 +527,7 @@ START_TEST(string)
SET
(
pmemcpy
,
"memcpy"
);
SET
(
pmemcmp
,
"memcmp"
);
SET
(
pstrcpy_s
,
"strcpy_s"
);
SET
(
pstrcat_s
,
"strcat_s"
);
/* MSVCRT memcpy behaves like memmove for overlapping moves,
MFC42 CString::Insert seems to rely on that behaviour */
...
...
@@ -483,4 +548,5 @@ START_TEST(string)
/* test _strdup */
test_strdup
();
test_strcpy_s
();
test_strcat_s
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment