[CRT] Reduce diff

- use msvcrt_set_errno
- MSVCRT_CHECK_PMT already sets the error.
- NULL check is already in HeapFree
This commit is contained in:
Timo Kreuzer 2023-01-10 11:20:11 +02:00
parent c47506a5f4
commit d0a52a6d71

View file

@ -44,6 +44,7 @@
#define MSVCRT_free free
#define MSVCRT_memmove_s memmove_s
#define MSVCRT_strncpy_s strncpy_s
#define msvcrt_set_errno _dosmaperr
/* MT */
#define LOCK_HEAP _mlock( _HEAP_LOCK )
@ -277,7 +278,7 @@ int CDECL _heapchk(void)
if (!HeapValidate(heap, 0, NULL) ||
(sb_heap && !HeapValidate(sb_heap, 0, NULL)))
{
_dosmaperr(GetLastError());
msvcrt_set_errno(GetLastError());
return MSVCRT__HEAPBADNODE;
}
return MSVCRT__HEAPOK;
@ -292,7 +293,7 @@ int CDECL _heapmin(void)
(sb_heap && !HeapCompact( sb_heap, 0 )))
{
if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
_dosmaperr(GetLastError());
msvcrt_set_errno(GetLastError());
return -1;
}
return 0;
@ -317,7 +318,7 @@ int CDECL _heapwalk(struct MSVCRT__heapinfo* next)
!HeapValidate( heap, 0, phe.lpData ))
{
UNLOCK_HEAP;
_dosmaperr(GetLastError());
msvcrt_set_errno(GetLastError());
return MSVCRT__HEAPBADNODE;
}
@ -328,7 +329,7 @@ int CDECL _heapwalk(struct MSVCRT__heapinfo* next)
UNLOCK_HEAP;
if (GetLastError() == ERROR_NO_MORE_ITEMS)
return MSVCRT__HEAPEND;
_dosmaperr(GetLastError());
msvcrt_set_errno(GetLastError());
if (!phe.lpData)
return MSVCRT__HEAPBADBEGIN;
return MSVCRT__HEAPBADNODE;
@ -406,7 +407,6 @@ void* CDECL MSVCRT_calloc(MSVCRT_size_t count, MSVCRT_size_t size)
*/
void CDECL MSVCRT_free(void* ptr)
{
if(ptr == NULL) return;
msvcrt_heap_free(ptr);
}
@ -703,11 +703,9 @@ int CDECL MSVCRT_strncpy_s(char *dest, MSVCRT_size_t numberOfElements,
if(!count)
return 0;
if (!MSVCRT_CHECK_PMT(dest != NULL) || !MSVCRT_CHECK_PMT(src != NULL) ||
!MSVCRT_CHECK_PMT(numberOfElements != 0)) {
*_errno() = EINVAL;
return EINVAL;
}
if (!MSVCRT_CHECK_PMT(dest != NULL)) return MSVCRT_EINVAL;
if (!MSVCRT_CHECK_PMT(src != NULL)) return MSVCRT_EINVAL;
if (!MSVCRT_CHECK_PMT(numberOfElements != 0)) return MSVCRT_EINVAL;
if(count!=MSVCRT__TRUNCATE && count<numberOfElements)
end = count;