Commit 9a4b596e authored by Alexandre Julliard's avatar Alexandre Julliard

msvcrt/tests: Add some function pointers to bypass gcc builtin functions.

parent 2e01a484
...@@ -458,22 +458,26 @@ static void test_sbheap(void) ...@@ -458,22 +458,26 @@ static void test_sbheap(void)
static void test_calloc(void) static void test_calloc(void)
{ {
/* use function pointer to bypass gcc builtin */
void *(__cdecl *p_calloc)(size_t, size_t);
void *ptr; void *ptr;
ptr = calloc(1, 0); p_calloc = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "calloc");
ptr = p_calloc(1, 0);
ok(ptr != NULL, "got %p\n", ptr); ok(ptr != NULL, "got %p\n", ptr);
free(ptr); free(ptr);
ptr = calloc(0, 0); ptr = p_calloc(0, 0);
ok(ptr != NULL, "got %p\n", ptr); ok(ptr != NULL, "got %p\n", ptr);
free(ptr); free(ptr);
ptr = calloc(0, 1); ptr = p_calloc(0, 1);
ok(ptr != NULL, "got %p\n", ptr); ok(ptr != NULL, "got %p\n", ptr);
free(ptr); free(ptr);
errno = 0; errno = 0;
ptr = calloc(~(size_t)0 / 2, ~(size_t)0 / 2); ptr = p_calloc(~(size_t)0 / 2, ~(size_t)0 / 2);
ok(ptr == NULL || broken(ptr != NULL) /* winxp sp0 */, "got %p\n", ptr); ok(ptr == NULL || broken(ptr != NULL) /* winxp sp0 */, "got %p\n", ptr);
ok(errno == ENOMEM || broken(errno == 0) /* winxp, win2k3 */, "got errno %d\n", errno); ok(errno == ENOMEM || broken(errno == 0) /* winxp, win2k3 */, "got errno %d\n", errno);
free(ptr); free(ptr);
......
...@@ -3098,29 +3098,33 @@ static void test_atof(void) ...@@ -3098,29 +3098,33 @@ static void test_atof(void)
static void test_strncpy(void) static void test_strncpy(void)
{ {
#define TEST_STRNCPY_LEN 10 #define TEST_STRNCPY_LEN 10
/* use function pointer to bypass gcc builtin */
char *(__cdecl *p_strncpy)(char*,const char*,size_t);
char *ret; char *ret;
char dst[TEST_STRNCPY_LEN + 1]; char dst[TEST_STRNCPY_LEN + 1];
char not_null_terminated[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; char not_null_terminated[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
p_strncpy = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "strncpy");
/* strlen(src) > TEST_STRNCPY_LEN */ /* strlen(src) > TEST_STRNCPY_LEN */
ret = strncpy(dst, "01234567890123456789", TEST_STRNCPY_LEN); ret = p_strncpy(dst, "01234567890123456789", TEST_STRNCPY_LEN);
ok(ret == dst, "ret != dst\n"); ok(ret == dst, "ret != dst\n");
ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n"); ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
/* without null-terminated */ /* without null-terminated */
ret = strncpy(dst, not_null_terminated, TEST_STRNCPY_LEN); ret = p_strncpy(dst, not_null_terminated, TEST_STRNCPY_LEN);
ok(ret == dst, "ret != dst\n"); ok(ret == dst, "ret != dst\n");
ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n"); ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
/* strlen(src) < TEST_STRNCPY_LEN */ /* strlen(src) < TEST_STRNCPY_LEN */
strcpy(dst, "0123456789"); strcpy(dst, "0123456789");
ret = strncpy(dst, "012345", TEST_STRNCPY_LEN); ret = p_strncpy(dst, "012345", TEST_STRNCPY_LEN);
ok(ret == dst, "ret != dst\n"); ok(ret == dst, "ret != dst\n");
ok(!strcmp(dst, "012345"), "dst != 012345\n"); ok(!strcmp(dst, "012345"), "dst != 012345\n");
ok(dst[TEST_STRNCPY_LEN - 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n"); ok(dst[TEST_STRNCPY_LEN - 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
/* strlen(src) == TEST_STRNCPY_LEN */ /* strlen(src) == TEST_STRNCPY_LEN */
ret = strncpy(dst, "0123456789", TEST_STRNCPY_LEN); ret = p_strncpy(dst, "0123456789", TEST_STRNCPY_LEN);
ok(ret == dst, "ret != dst\n"); ok(ret == dst, "ret != dst\n");
ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n"); ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment