Fixed clang malloc integer overflow warnings.

This commit is contained in:
Armin Novak 2017-05-30 10:46:43 +02:00
parent 8292b4558f
commit 0490aeb018
63 changed files with 123 additions and 124 deletions

View File

@ -229,7 +229,7 @@ static void* audin_alsa_thread_func(void* arg)
DWORD status; DWORD status;
DEBUG_DVC("in"); DEBUG_DVC("in");
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel; rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
buffer = (BYTE*) calloc(1, rbytes_per_frame * alsa->frames_per_packet); buffer = (BYTE*) calloc(alsa->frames_per_packet, rbytes_per_frame);
if (!buffer) if (!buffer)
{ {
@ -410,7 +410,7 @@ static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive,
alsa->receive = receive; alsa->receive = receive;
alsa->user_data = user_data; alsa->user_data = user_data;
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel; tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
alsa->buffer = (BYTE*) calloc(1, tbytes_per_frame * alsa->frames_per_packet); alsa->buffer = (BYTE*) calloc(alsa->frames_per_packet, tbytes_per_frame);
if (!alsa->buffer) if (!alsa->buffer)
{ {

View File

@ -164,7 +164,7 @@ static UINT audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback,
} }
Stream_Seek_UINT32(s); /* cbSizeFormatsPacket */ Stream_Seek_UINT32(s); /* cbSizeFormatsPacket */
callback->formats = (audinFormat*) calloc(1, NumFormats * sizeof(audinFormat)); callback->formats = (audinFormat*) calloc(NumFormats, sizeof(audinFormat));
if (!callback->formats) if (!callback->formats)
{ {

View File

@ -253,7 +253,7 @@ OPENSL_STREAM* android_OpenRecDevice(char* name, int sr, int inchannels,
int bufferframes, int bits_per_sample) int bufferframes, int bits_per_sample)
{ {
OPENSL_STREAM* p; OPENSL_STREAM* p;
p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1); p = (OPENSL_STREAM*) calloc(1, sizeof(OPENSL_STREAM));
if (!p) if (!p)
return NULL; return NULL;

View File

@ -496,7 +496,7 @@ static UINT audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* u
pa_threaded_mainloop_unlock(pulse->mainloop); pa_threaded_mainloop_unlock(pulse->mainloop);
freerdp_dsp_context_reset_adpcm(pulse->dsp_context); freerdp_dsp_context_reset_adpcm(pulse->dsp_context);
pulse->buffer = calloc(1, pulse->bytes_per_frame * pulse->frames_per_packet); pulse->buffer = calloc(pulse->frames_per_packet, pulse->bytes_per_frame);
if (!pulse->buffer) if (!pulse->buffer)
{ {

View File

@ -93,7 +93,7 @@ FREERDP_ADDIN** freerdp_channels_list_client_static_addins(LPSTR pszName, LPSTR
FREERDP_ADDIN** ppAddins = NULL; FREERDP_ADDIN** ppAddins = NULL;
STATIC_SUBSYSTEM_ENTRY* subsystems; STATIC_SUBSYSTEM_ENTRY* subsystems;
nAddins = 0; nAddins = 0;
ppAddins = (FREERDP_ADDIN**) calloc(1, sizeof(FREERDP_ADDIN*) * 128); ppAddins = (FREERDP_ADDIN**) calloc(128, sizeof(FREERDP_ADDIN*));
if (!ppAddins) if (!ppAddins)
{ {
@ -216,7 +216,7 @@ FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPSTR pszName, LPSTR pszSub
hFind = FindFirstFileA(pszSearchPath, &FindData); hFind = FindFirstFileA(pszSearchPath, &FindData);
free(pszSearchPath); free(pszSearchPath);
nAddins = 0; nAddins = 0;
ppAddins = (FREERDP_ADDIN**) calloc(1, sizeof(FREERDP_ADDIN*) * 128); ppAddins = (FREERDP_ADDIN**) calloc(128, sizeof(FREERDP_ADDIN*));
if (!ppAddins) if (!ppAddins)
{ {

View File

@ -281,7 +281,7 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver)
int i; int i;
num_dests = cupsGetDests(&dests); num_dests = cupsGetDests(&dests);
printers = (rdpPrinter**) calloc(1, sizeof(rdpPrinter*) * (num_dests + 1)); printers = (rdpPrinter**) calloc(num_dests + 1, sizeof(rdpPrinter*));
if (!printers) if (!printers)
return NULL; return NULL;

View File

@ -63,7 +63,7 @@ static UINT rdpgfx_read_h264_metablock(RDPGFX_PLUGIN* gfx, wStream* s,
goto error_out; goto error_out;
} }
meta->regionRects = (RECTANGLE_16*) malloc(meta->numRegionRects * sizeof(RECTANGLE_16)); meta->regionRects = (RECTANGLE_16*) calloc(meta->numRegionRects, sizeof(RECTANGLE_16));
if (!meta->regionRects) if (!meta->regionRects)
{ {
@ -72,7 +72,7 @@ static UINT rdpgfx_read_h264_metablock(RDPGFX_PLUGIN* gfx, wStream* s,
goto error_out; goto error_out;
} }
meta->quantQualityVals = (RDPGFX_H264_QUANT_QUALITY*) malloc(meta->numRegionRects * sizeof( meta->quantQualityVals = (RDPGFX_H264_QUANT_QUALITY*) calloc(meta->numRegionRects, sizeof(
RDPGFX_H264_QUANT_QUALITY)); RDPGFX_H264_QUANT_QUALITY));
if (!meta->quantQualityVals) if (!meta->quantQualityVals)

View File

@ -1593,7 +1593,7 @@ static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context,
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
pSurfaceIds = (UINT16*) malloc(count * sizeof(UINT16)); pSurfaceIds = (UINT16*) calloc(count, sizeof(UINT16));
if (!pSurfaceIds) if (!pSurfaceIds)
{ {

View File

@ -264,7 +264,7 @@ OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels,
int bufferframes) int bufferframes)
{ {
OPENSL_STREAM* p; OPENSL_STREAM* p;
p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1); p = (OPENSL_STREAM*) calloc(1, sizeof(OPENSL_STREAM));
if (!p) if (!p)
return NULL; return NULL;

View File

@ -223,8 +223,9 @@ static void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd)
if (!rdpsnd->NumberOfServerFormats) if (!rdpsnd->NumberOfServerFormats)
return; return;
rdpsnd->ClientFormats = (AUDIO_FORMAT*) calloc(sizeof(AUDIO_FORMAT), rdpsnd->ClientFormats = (AUDIO_FORMAT*) calloc(
rdpsnd->NumberOfServerFormats); rdpsnd->NumberOfServerFormats,
sizeof(AUDIO_FORMAT));
if (!rdpsnd->ClientFormats) if (!rdpsnd->ClientFormats)
return; return;

View File

@ -981,7 +981,7 @@ LONG smartcard_unpack_connect_w_call(SMARTCARD_DEVICE* smartcard, wStream* s, Co
Stream_Seek_UINT32(s); /* NdrMaxCount (4 bytes) */ Stream_Seek_UINT32(s); /* NdrMaxCount (4 bytes) */
Stream_Seek_UINT32(s); /* NdrOffset (4 bytes) */ Stream_Seek_UINT32(s); /* NdrOffset (4 bytes) */
Stream_Read_UINT32(s, count); /* NdrActualCount (4 bytes) */ Stream_Read_UINT32(s, count); /* NdrActualCount (4 bytes) */
call->szReader = (WCHAR*) malloc((count + 1) * 2); call->szReader = (WCHAR*) calloc((count + 1), 2);
if (!call->szReader) if (!call->szReader)
{ {
@ -1557,7 +1557,7 @@ LONG smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wStr
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
} }
readerState->szReader = (WCHAR*) malloc((count + 1) * 2); readerState->szReader = (WCHAR*) calloc((count + 1), 2);
if (!readerState->szReader) if (!readerState->szReader)
{ {

View File

@ -465,7 +465,7 @@ static BOOL tsmf_sample_playback_video(TSMF_SAMPLE* sample)
if (presentation->nr_rects > 0) if (presentation->nr_rects > 0)
{ {
event.numVisibleRects = presentation->nr_rects; event.numVisibleRects = presentation->nr_rects;
event.visibleRects = (RECTANGLE_16*) calloc(1, event.numVisibleRects * sizeof(RECTANGLE_16)); event.visibleRects = (RECTANGLE_16*) calloc(event.numVisibleRects, sizeof(RECTANGLE_16));
if (!event.visibleRects) if (!event.visibleRects)
{ {

View File

@ -759,7 +759,7 @@ static MSUSB_CONFIG_DESCRIPTOR* libusb_udev_complete_msconfig_setup(IUDEVICE* id
LibusbInterface = &LibusbConfig->interface[MsInterface->InterfaceNumber]; LibusbInterface = &LibusbConfig->interface[MsInterface->InterfaceNumber];
LibusbAltsetting = &LibusbInterface->altsetting[MsInterface->AlternateSetting]; LibusbAltsetting = &LibusbInterface->altsetting[MsInterface->AlternateSetting];
LibusbNumEndpoint = LibusbAltsetting->bNumEndpoints; LibusbNumEndpoint = LibusbAltsetting->bNumEndpoints;
t_MsPipes = (MSUSB_PIPE_DESCRIPTOR**) malloc(LibusbNumEndpoint * sizeof(MSUSB_PIPE_DESCRIPTOR*)); t_MsPipes = (MSUSB_PIPE_DESCRIPTOR**) calloc(LibusbNumEndpoint, sizeof(MSUSB_PIPE_DESCRIPTOR*));
for (pnum = 0; pnum < LibusbNumEndpoint; pnum++) for (pnum = 0; pnum < LibusbNumEndpoint; pnum++)
{ {

View File

@ -309,7 +309,7 @@ BOOL android_event_queue_init(freerdp* inst)
return FALSE; return FALSE;
} }
queue->events = (ANDROID_EVENT**) calloc(sizeof(ANDROID_EVENT*), queue->size); queue->events = (ANDROID_EVENT**) calloc(queue->size, sizeof(ANDROID_EVENT*));
if (!queue->events) if (!queue->events)
{ {

View File

@ -2508,8 +2508,8 @@ BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr)
&& clipboard->GetUpdatedClipboardFormats)) && clipboard->GetUpdatedClipboardFormats))
clipboard->legacyApi = TRUE; clipboard->legacyApi = TRUE;
if (!(clipboard->format_mappings = (formatMapping*) calloc(1, if (!(clipboard->format_mappings = (formatMapping*) calloc(clipboard->map_capacity,
sizeof(formatMapping) * clipboard->map_capacity))) sizeof(formatMapping))))
goto error; goto error;
if (!(clipboard->response_data_event = CreateEvent(NULL, TRUE, FALSE, if (!(clipboard->response_data_event = CreateEvent(NULL, TRUE, FALSE,

View File

@ -580,7 +580,7 @@ static BOOL xf_gdi_polyline(rdpContext* context,
XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetFillStyle(xfc->display, xfc->gc, FillSolid);
XSetForeground(xfc->display, xfc->gc, color.pixel); XSetForeground(xfc->display, xfc->gc, color.pixel);
npoints = polyline->numDeltaEntries + 1; npoints = polyline->numDeltaEntries + 1;
points = malloc(sizeof(XPoint) * npoints); points = calloc(npoints, sizeof(XPoint));
if (!points) if (!points)
{ {
@ -743,7 +743,7 @@ static BOOL xf_gdi_polygon_sc(rdpContext* context,
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
xf_set_rop2(xfc, polygon_sc->bRop2); xf_set_rop2(xfc, polygon_sc->bRop2);
npoints = polygon_sc->numPoints + 1; npoints = polygon_sc->numPoints + 1;
points = malloc(sizeof(XPoint) * npoints); points = calloc(npoints, sizeof(XPoint));
if (!points) if (!points)
{ {
@ -814,7 +814,7 @@ static BOOL xf_gdi_polygon_cb(rdpContext* context,
brush = &(polygon_cb->brush); brush = &(polygon_cb->brush);
xf_set_rop2(xfc, polygon_cb->bRop2); xf_set_rop2(xfc, polygon_cb->bRop2);
npoints = polygon_cb->numPoints + 1; npoints = polygon_cb->numPoints + 1;
points = malloc(sizeof(XPoint) * npoints); points = calloc(npoints, sizeof(XPoint));
if (!points) if (!points)
{ {

View File

@ -814,7 +814,7 @@ BOOL freerdp_client_write_rdp_file(const rdpFile* file, const char* name, BOOL u
return FALSE; return FALSE;
} }
buffer = (char*) malloc((length + 1) * sizeof(char)); buffer = (char*) calloc((length + 1), sizeof(char));
if (freerdp_client_write_rdp_file_buffer(file, buffer, length + 1) != length) if (freerdp_client_write_rdp_file_buffer(file, buffer, length + 1) != length)
{ {
@ -1427,7 +1427,7 @@ rdpFile* freerdp_client_rdp_file_new()
FillMemory(file, sizeof(rdpFile), 0xFF); FillMemory(file, sizeof(rdpFile), 0xFF);
file->lineCount = 0; file->lineCount = 0;
file->lineSize = 32; file->lineSize = 32;
file->lines = (rdpFileLine*) malloc(file->lineSize * sizeof(rdpFileLine)); file->lines = (rdpFileLine*) calloc(file->lineSize, sizeof(rdpFileLine));
if (!file->lines) if (!file->lines)
{ {
@ -1437,7 +1437,7 @@ rdpFile* freerdp_client_rdp_file_new()
file->argc = 0; file->argc = 0;
file->argSize = 32; file->argSize = 32;
file->argv = (char**) malloc(file->argSize * sizeof(char*)); file->argv = (char**) calloc(file->argSize, sizeof(char*));
if (!file->argv) if (!file->argv)
{ {

View File

@ -1064,7 +1064,7 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* inPlane,
if (width * height == 0) if (width * height == 0)
return NULL; return NULL;
if (!(outPlane = (BYTE*) malloc(width * height))) if (!(outPlane = (BYTE*) calloc(height, width)))
return NULL; return NULL;
} }
@ -1269,10 +1269,10 @@ BOOL freerdp_bitmap_planar_context_reset(
free(context->pTempData); free(context->pTempData);
free(context->deltaPlanesBuffer); free(context->deltaPlanesBuffer);
free(context->rlePlanesBuffer); free(context->rlePlanesBuffer);
context->planesBuffer = malloc(context->maxPlaneSize * 4); context->planesBuffer = calloc(context->maxPlaneSize, 4);
context->pTempData = malloc(context->maxPlaneSize * 4); context->pTempData = calloc(context->maxPlaneSize, 4);
context->deltaPlanesBuffer = malloc(context->maxPlaneSize * 4); context->deltaPlanesBuffer = calloc(context->maxPlaneSize, 4);
context->rlePlanesBuffer = malloc(context->maxPlaneSize * 4); context->rlePlanesBuffer = calloc(context->maxPlaneSize, 4);
if (!context->planesBuffer || !context->pTempData || if (!context->planesBuffer || !context->pTempData ||
!context->deltaPlanesBuffer || !context->rlePlanesBuffer) !context->deltaPlanesBuffer || !context->rlePlanesBuffer)

View File

@ -1938,28 +1938,28 @@ PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
progressive->Compressor = Compressor; progressive->Compressor = Compressor;
progressive->bufferPool = BufferPool_New(TRUE, (8192 + 32) * 3, 16); progressive->bufferPool = BufferPool_New(TRUE, (8192 + 32) * 3, 16);
progressive->cRects = 64; progressive->cRects = 64;
progressive->rects = (RFX_RECT*) malloc(progressive->cRects * sizeof(RFX_RECT)); progressive->rects = (RFX_RECT*) calloc(progressive->cRects, sizeof(RFX_RECT));
if (!progressive->rects) if (!progressive->rects)
goto cleanup; goto cleanup;
progressive->cTiles = 64; progressive->cTiles = 64;
progressive->tiles = (RFX_PROGRESSIVE_TILE**) malloc(progressive->cTiles * progressive->tiles = (RFX_PROGRESSIVE_TILE**) calloc(progressive->cTiles,
sizeof(RFX_PROGRESSIVE_TILE*)); sizeof(RFX_PROGRESSIVE_TILE*));
if (!progressive->tiles) if (!progressive->tiles)
goto cleanup; goto cleanup;
progressive->cQuant = 8; progressive->cQuant = 8;
progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) malloc( progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) calloc(
progressive->cQuant * sizeof(RFX_COMPONENT_CODEC_QUANT)); progressive->cQuant, sizeof(RFX_COMPONENT_CODEC_QUANT));
if (!progressive->quantVals) if (!progressive->quantVals)
goto cleanup; goto cleanup;
progressive->cProgQuant = 8; progressive->cProgQuant = 8;
progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) malloc( progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) calloc(
progressive->cProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); progressive->cProgQuant, sizeof(RFX_PROGRESSIVE_CODEC_QUANT));
if (!progressive->quantProgVals) if (!progressive->quantProgVals)
goto cleanup; goto cleanup;

View File

@ -2968,7 +2968,7 @@ static BOOL RunTestPlanar(BITMAP_PLANAR_CONTEXT* planar, const BYTE* srcBitmap,
UINT32 dstSize; UINT32 dstSize;
BYTE* compressedBitmap = freerdp_bitmap_compress_planar(planar, BYTE* compressedBitmap = freerdp_bitmap_compress_planar(planar,
srcBitmap, srcFormat, width, height, 0, NULL, &dstSize); srcBitmap, srcFormat, width, height, 0, NULL, &dstSize);
BYTE* decompressedBitmap = (BYTE*) calloc(1, size); BYTE* decompressedBitmap = (BYTE*) calloc(height, width * GetBytesPerPixel(dstFormat));
printf("%s [%s] --> [%s]: ", __FUNCTION__, printf("%s [%s] --> [%s]: ", __FUNCTION__,
GetColorFormatName(srcFormat), GetColorFormatName(dstFormat)); GetColorFormatName(srcFormat), GetColorFormatName(dstFormat));
fflush(stdout); fflush(stdout);

View File

@ -87,7 +87,7 @@ int freerdp_assistance_crypt_derive_key_sha1(BYTE* hash, int hashLength, BYTE* k
pad2[i] ^= hash[i]; pad2[i] ^= hash[i];
} }
buffer = (BYTE*) calloc(1, hashLength * 2); buffer = (BYTE*) calloc(hashLength, 2);
if (!buffer) if (!buffer)
goto fail; goto fail;
@ -131,7 +131,7 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
count++; count++;
} }
tokens = (char**) malloc(sizeof(char*) * count); tokens = (char**) calloc(count, sizeof(char*));
if (!tokens) if (!tokens)
{ {
free(str); free(str);
@ -812,7 +812,7 @@ char* freerdp_assistance_bin_to_hex_string(const BYTE* data, int size)
int ln, hn; int ln, hn;
char bin2hex[] = "0123456789ABCDEF"; char bin2hex[] = "0123456789ABCDEF";
p = (char*) malloc((size + 1) * 2); p = (char*) calloc((size + 1), 2);
if (!p) if (!p)
return NULL; return NULL;

View File

@ -592,7 +592,7 @@ ADDIN_ARGV* freerdp_dynamic_channel_clone(ADDIN_ARGV* channel)
return NULL; return NULL;
_channel->argc = channel->argc; _channel->argc = channel->argc;
_channel->argv = (char**) malloc(sizeof(char*) * channel->argc); _channel->argv = (char**) calloc(sizeof(char*), channel->argc);
if (!_channel->argv) if (!_channel->argv)
goto out_free; goto out_free;

View File

@ -429,7 +429,7 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp)
* client random must be (bitlen / 8) + 8 - see [MS-RDPBCGR] 5.3.4.1 * client random must be (bitlen / 8) + 8 - see [MS-RDPBCGR] 5.3.4.1
* for details * for details
*/ */
crypt_client_random = calloc(1, key_len + 8); crypt_client_random = calloc(key_len + 8, 1);
if (!crypt_client_random) if (!crypt_client_random)
return FALSE; return FALSE;

View File

@ -131,7 +131,7 @@ BOOL ntlm_client_make_spn(rdpNtlm* ntlm, LPCTSTR ServiceClass, char* hostname)
if (DsMakeSpn(ServiceClass, hostnameX, NULL, 0, NULL, &SpnLength, NULL) != ERROR_BUFFER_OVERFLOW) if (DsMakeSpn(ServiceClass, hostnameX, NULL, 0, NULL, &SpnLength, NULL) != ERROR_BUFFER_OVERFLOW)
goto error; goto error;
ntlm->ServicePrincipalName = (LPTSTR) malloc(SpnLength * sizeof(TCHAR)); ntlm->ServicePrincipalName = (LPTSTR) calloc(SpnLength, sizeof(TCHAR));
if (!ntlm->ServicePrincipalName) if (!ntlm->ServicePrincipalName)
goto error; goto error;

View File

@ -734,7 +734,7 @@ BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList)
return FALSE; return FALSE;
scopeList->count = scopeCount; scopeList->count = scopeCount;
scopeList->array = (LICENSE_BLOB*) malloc(sizeof(LICENSE_BLOB) * scopeCount); scopeList->array = (LICENSE_BLOB*) calloc(scopeCount, sizeof(LICENSE_BLOB));
if (!scopeList->array) if (!scopeList->array)
return FALSE; return FALSE;

View File

@ -115,7 +115,7 @@ static BOOL update_message_BitmapUpdate(rdpContext* context,
wParam->number = bitmap->number; wParam->number = bitmap->number;
wParam->count = wParam->number; wParam->count = wParam->number;
wParam->rectangles = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * wParam->number); wParam->rectangles = (BITMAP_DATA*) calloc(wParam->number, sizeof(BITMAP_DATA));
if (!wParam->rectangles) if (!wParam->rectangles)
{ {
@ -213,7 +213,7 @@ static BOOL update_message_RefreshRect(rdpContext* context, BYTE count,
if (!context || !context->update || !areas) if (!context || !context->update || !areas)
return FALSE; return FALSE;
lParam = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * count); lParam = (RECTANGLE_16*) calloc(count, sizeof(RECTANGLE_16));
if (!lParam) if (!lParam)
return FALSE; return FALSE;
@ -539,7 +539,7 @@ static BOOL update_message_Polyline(rdpContext* context,
return FALSE; return FALSE;
CopyMemory(wParam, polyline, sizeof(POLYLINE_ORDER)); CopyMemory(wParam, polyline, sizeof(POLYLINE_ORDER));
wParam->points = (DELTA_POINT*) malloc(sizeof(DELTA_POINT) * wParam->numDeltaEntries); wParam->points = (DELTA_POINT*) calloc(wParam->numDeltaEntries, sizeof(DELTA_POINT));
if (!wParam->points) if (!wParam->points)
{ {
@ -692,7 +692,7 @@ static BOOL update_message_PolygonSC(rdpContext* context,
return FALSE; return FALSE;
CopyMemory(wParam, polygonSC, sizeof(POLYGON_SC_ORDER)); CopyMemory(wParam, polygonSC, sizeof(POLYGON_SC_ORDER));
wParam->points = (DELTA_POINT*) malloc(sizeof(DELTA_POINT) * wParam->numPoints); wParam->points = (DELTA_POINT*) calloc(wParam->numPoints, sizeof(DELTA_POINT));
if (!wParam->points) if (!wParam->points)
{ {
@ -718,7 +718,7 @@ static BOOL update_message_PolygonCB(rdpContext* context, POLYGON_CB_ORDER* poly
return FALSE; return FALSE;
CopyMemory(wParam, polygonCB, sizeof(POLYGON_CB_ORDER)); CopyMemory(wParam, polygonCB, sizeof(POLYGON_CB_ORDER));
wParam->points = (DELTA_POINT*) malloc(sizeof(DELTA_POINT) * wParam->numPoints); wParam->points = (DELTA_POINT*) calloc(wParam->numPoints, sizeof(DELTA_POINT));
if (!wParam->points) if (!wParam->points)
{ {
@ -947,7 +947,7 @@ static BOOL update_message_CreateOffscreenBitmap(
CopyMemory(wParam, createOffscreenBitmap, sizeof(CREATE_OFFSCREEN_BITMAP_ORDER)); CopyMemory(wParam, createOffscreenBitmap, sizeof(CREATE_OFFSCREEN_BITMAP_ORDER));
wParam->deleteList.cIndices = createOffscreenBitmap->deleteList.cIndices; wParam->deleteList.cIndices = createOffscreenBitmap->deleteList.cIndices;
wParam->deleteList.sIndices = wParam->deleteList.cIndices; wParam->deleteList.sIndices = wParam->deleteList.cIndices;
wParam->deleteList.indices = (UINT16*) malloc(sizeof(UINT16) * wParam->deleteList.cIndices); wParam->deleteList.indices = (UINT16*) calloc(wParam->deleteList.cIndices, sizeof(UINT16));
if (!wParam->deleteList.indices) if (!wParam->deleteList.indices)
{ {
@ -1452,7 +1452,7 @@ static BOOL update_message_MonitoredDesktop(rdpContext* context, WINDOW_ORDER_IN
if (lParam->numWindowIds) if (lParam->numWindowIds)
{ {
lParam->windowIds = (UINT32*) malloc(sizeof(UINT32) * lParam->numWindowIds); lParam->windowIds = (UINT32*) calloc(lParam->numWindowIds, sizeof(UINT32));
CopyMemory(lParam->windowIds, monitoredDesktop->windowIds, lParam->numWindowIds); CopyMemory(lParam->windowIds, monitoredDesktop->windowIds, lParam->numWindowIds);
} }

View File

@ -1727,7 +1727,7 @@ LPTSTR nla_make_spn(const char* ServiceClass, const char* hostname)
return NULL; return NULL;
} }
ServicePrincipalName = (LPTSTR) malloc(SpnLength * sizeof(TCHAR)); ServicePrincipalName = (LPTSTR) calloc(SpnLength, sizeof(TCHAR));
if (!ServicePrincipalName) if (!ServicePrincipalName)
{ {

View File

@ -133,7 +133,7 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
hostnamelen = strlen(hostname); hostnamelen = strlen(hostname);
} }
settings->ProxyHostname = calloc(1, hostnamelen + 1); settings->ProxyHostname = calloc(hostnamelen + 1, 1);
if (!settings->ProxyHostname) if (!settings->ProxyHostname)
{ {

View File

@ -217,7 +217,7 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
UINT32 i; UINT32 i;
freerdp_target_net_addresses_free(settings); freerdp_target_net_addresses_free(settings);
settings->TargetNetAddressCount = redirection->TargetNetAddressesCount; settings->TargetNetAddressCount = redirection->TargetNetAddressesCount;
settings->TargetNetAddresses = (char**) malloc(sizeof(char*) * settings->TargetNetAddressCount); settings->TargetNetAddresses = (char**) calloc(settings->TargetNetAddressCount, sizeof(char*));
if (!settings->TargetNetAddresses) if (!settings->TargetNetAddresses)
{ {
settings->TargetNetAddressCount = 0; settings->TargetNetAddressCount = 0;

View File

@ -769,8 +769,8 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
if (_settings->ChannelDefArraySize > 0) if (_settings->ChannelDefArraySize > 0)
{ {
_settings->ChannelDefArray = (CHANNEL_DEF*) malloc(sizeof( _settings->ChannelDefArray = (CHANNEL_DEF*) calloc(settings->ChannelDefArraySize,
CHANNEL_DEF) * settings->ChannelDefArraySize); sizeof(CHANNEL_DEF));
if (!_settings->ChannelDefArray) if (!_settings->ChannelDefArray)
goto out_fail; goto out_fail;
@ -786,8 +786,8 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
if (_settings->MonitorDefArraySize > 0) if (_settings->MonitorDefArraySize > 0)
{ {
_settings->MonitorDefArray = (rdpMonitor*) malloc(sizeof( _settings->MonitorDefArray = (rdpMonitor*) calloc(settings->MonitorDefArraySize,
rdpMonitor) * settings->MonitorDefArraySize); sizeof(rdpMonitor));
if (!_settings->MonitorDefArray) if (!_settings->MonitorDefArray)
goto out_fail; goto out_fail;

View File

@ -1898,7 +1898,7 @@ BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s)
if (Stream_GetRemainingLength(s) < ((size_t) numberOfAreas * 4 * 2)) if (Stream_GetRemainingLength(s) < ((size_t) numberOfAreas * 4 * 2))
return FALSE; return FALSE;
areas = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * numberOfAreas); areas = (RECTANGLE_16*) calloc(numberOfAreas, sizeof(RECTANGLE_16));
if (!areas) if (!areas)
return FALSE; return FALSE;
@ -2103,7 +2103,7 @@ rdpUpdate* update_new(rdpRdp* rdp)
deleteList = &(update->altsec->create_offscreen_bitmap.deleteList); deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
deleteList->sIndices = 64; deleteList->sIndices = 64;
deleteList->indices = malloc(deleteList->sIndices * 2); deleteList->indices = calloc(deleteList->sIndices, 2);
if (!deleteList->indices) if (!deleteList->indices)
goto error_indices; goto error_indices;

View File

@ -213,7 +213,7 @@ char* crypto_cert_fingerprint(X509* xcert)
X509_digest(xcert, EVP_sha1(), fp, &fp_len); X509_digest(xcert, EVP_sha1(), fp, &fp_len);
fp_buffer = (char*) calloc(3, fp_len); fp_buffer = (char*) calloc(fp_len, 3);
if (!fp_buffer) if (!fp_buffer)
return NULL; return NULL;
@ -330,11 +330,11 @@ char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
num_subject_alt_names = sk_GENERAL_NAME_num(subject_alt_names); num_subject_alt_names = sk_GENERAL_NAME_num(subject_alt_names);
if (num_subject_alt_names) if (num_subject_alt_names)
{ {
strings = (char**) malloc(sizeof(char*) * num_subject_alt_names); strings = (char**) calloc(num_subject_alt_names, sizeof(char*));
if (!strings) if (!strings)
goto out; goto out;
*lengths = (int*) malloc(sizeof(int) * num_subject_alt_names); *lengths = (int*) calloc(num_subject_alt_names, sizeof(int));
if (!*lengths) if (!*lengths)
{ {
free(strings); free(strings);

View File

@ -760,7 +760,7 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context,
const RDPGFX_CREATE_SURFACE_PDU* createSurface) const RDPGFX_CREATE_SURFACE_PDU* createSurface)
{ {
gdiGfxSurface* surface; gdiGfxSurface* surface;
rdpGdi* gdi = (rdpGdi*) context->custom; rdpGdi* gdi = (rdpGdi*) context->custom;
surface = (gdiGfxSurface*) calloc(1, sizeof(gdiGfxSurface)); surface = (gdiGfxSurface*) calloc(1, sizeof(gdiGfxSurface));
if (!surface) if (!surface)
@ -992,7 +992,7 @@ static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
cacheEntry->height = (UINT32)(rect->bottom - rect->top); cacheEntry->height = (UINT32)(rect->bottom - rect->top);
cacheEntry->format = surface->format; cacheEntry->format = surface->format;
cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16); cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16);
cacheEntry->data = (BYTE*) calloc(1, cacheEntry->scanline * cacheEntry->height); cacheEntry->data = (BYTE*) calloc(cacheEntry->height, cacheEntry->scanline);
if (!cacheEntry->data) if (!cacheEntry->data)
{ {

View File

@ -229,7 +229,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types)
RDP_KEYBOARD_LAYOUT* new; RDP_KEYBOARD_LAYOUT* new;
num = 0; num = 0;
layouts = (RDP_KEYBOARD_LAYOUT*) malloc((num + 1) * sizeof(RDP_KEYBOARD_LAYOUT)); layouts = (RDP_KEYBOARD_LAYOUT*) calloc((num + 1), sizeof(RDP_KEYBOARD_LAYOUT));
if (!layouts) if (!layouts)
return NULL; return NULL;

View File

@ -56,7 +56,7 @@ rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int hei
{ {
surface->scanline = (surface->width + (surface->width % 4)) * 4; surface->scanline = (surface->width + (surface->width % 4)) * 4;
surface->data = (BYTE*) malloc(surface->scanline * surface->height); surface->data = (BYTE*) calloc(surface->height, surface->scanline);
if (!surface->data) if (!surface->data)
{ {

View File

@ -99,7 +99,7 @@ int main(int argc, char** argv)
return 1; return 1;
scanline = width * 4; scanline = width * 4;
buffer = (BYTE*) malloc(scanline * height); buffer = (BYTE*) calloc(height, scanline);
if (!buffer) if (!buffer)
return 1; return 1;

View File

@ -266,7 +266,7 @@ static BOOL test_peer_load_icon(freerdp_peer* client)
/* Max */ /* Max */
fgets(line, sizeof(line), fp); fgets(line, sizeof(line), fp);
if (!(rgb_data = malloc(context->icon_width * context->icon_height * 3))) if (!(rgb_data = calloc(context->icon_height, context->icon_width * 3)))
goto out_fail; goto out_fail;
for (i = 0; i < context->icon_width * context->icon_height * 3; i++) for (i = 0; i < context->icon_width * context->icon_height * 3; i++)
@ -278,8 +278,7 @@ static BOOL test_peer_load_icon(freerdp_peer* client)
} }
/* background with same size, which will be used to erase the icon from old position */ /* background with same size, which will be used to erase the icon from old position */
if (!(context->bg_data = malloc(context->icon_width * context->icon_height * if (!(context->bg_data = calloc(context->icon_height, context->icon_width * 3)))
3)))
goto out_fail; goto out_fail;
memset(context->bg_data, 0xA0, context->icon_width * context->icon_height * 3); memset(context->bg_data, 0xA0, context->icon_width * context->icon_height * 3);

View File

@ -133,7 +133,7 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr)
WLog_INFO(TAG, "Using sound ouput endpoint: [%s] (%s)", nameVar.pwszVal, pwszID); WLog_INFO(TAG, "Using sound ouput endpoint: [%s] (%s)", nameVar.pwszVal, pwszID);
//WLog_INFO(TAG, "matched %d characters", wcscmp(pattern, nameVar.pwszVal); //WLog_INFO(TAG, "matched %d characters", wcscmp(pattern, nameVar.pwszVal);
devStrLen = wcslen(pwszID); devStrLen = wcslen(pwszID);
*deviceStr = (LPWSTR) calloc(1, (devStrLen * 2) + 2); *deviceStr = (LPWSTR) calloc(devStrLen + 1, 2);
if (!deviceStr) if (!deviceStr)
return -1; return -1;
wcscpy_s(*deviceStr, devStrLen+1, pwszID); wcscpy_s(*deviceStr, devStrLen+1, pwszID);

View File

@ -1067,8 +1067,7 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
totalBitmapSize = 0; totalBitmapSize = 0;
bitmapUpdate.count = bitmapUpdate.number = rows * cols; bitmapUpdate.count = bitmapUpdate.number = rows * cols;
if (!(bitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * if (!(bitmapData = (BITMAP_DATA*) calloc(bitmapUpdate.number, sizeof(BITMAP_DATA))))
bitmapUpdate.number)))
return FALSE; return FALSE;
bitmapUpdate.rectangles = bitmapData; bitmapUpdate.rectangles = bitmapData;
@ -1154,7 +1153,7 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
BITMAP_DATA* fragBitmapData = NULL; BITMAP_DATA* fragBitmapData = NULL;
if (k > 0) if (k > 0)
fragBitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * k); fragBitmapData = (BITMAP_DATA*) calloc(k, sizeof(BITMAP_DATA));
if (!fragBitmapData) if (!fragBitmapData)
{ {

View File

@ -86,12 +86,12 @@ static int shadow_encoder_init_grid(rdpShadowEncoder* encoder)
encoder->maxTileHeight); encoder->maxTileHeight);
tileSize = encoder->maxTileWidth * encoder->maxTileHeight * 4; tileSize = encoder->maxTileWidth * encoder->maxTileHeight * 4;
tileCount = encoder->gridWidth * encoder->gridHeight; tileCount = encoder->gridWidth * encoder->gridHeight;
encoder->gridBuffer = (BYTE*) malloc(tileSize * tileCount); encoder->gridBuffer = (BYTE*) calloc(tileSize, tileCount);
if (!encoder->gridBuffer) if (!encoder->gridBuffer)
return -1; return -1;
encoder->grid = (BYTE**) malloc(tileCount * sizeof(BYTE*)); encoder->grid = (BYTE**) calloc(tileCount, sizeof(BYTE*));
if (!encoder->grid) if (!encoder->grid)
return -1; return -1;

View File

@ -40,8 +40,8 @@ rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y,
surface->height = height; surface->height = height;
surface->scanline = ALIGN_SCREEN_SIZE(surface->width, 4) * 4; surface->scanline = ALIGN_SCREEN_SIZE(surface->width, 4) * 4;
surface->format = PIXEL_FORMAT_BGRX32; surface->format = PIXEL_FORMAT_BGRX32;
surface->data = (BYTE*) calloc(1, surface->data = (BYTE*) calloc(ALIGN_SCREEN_SIZE(surface->height, 4),
surface->scanline * ALIGN_SCREEN_SIZE(surface->height, 4)); surface->scanline);
if (!surface->data) if (!surface->data)
{ {

View File

@ -197,7 +197,7 @@ UINT32 ClipboardGetRegisteredFormatIds(wClipboard* clipboard,
if (!pFormatIds) if (!pFormatIds)
{ {
pFormatIds = malloc(clipboard->numFormats * sizeof(UINT32)); pFormatIds = calloc(clipboard->numFormats, sizeof(UINT32));
if (!pFormatIds) if (!pFormatIds)
return 0; return 0;
@ -340,7 +340,7 @@ UINT32 ClipboardGetFormatIds(wClipboard* clipboard, UINT32** ppFormatIds)
if (!pFormatIds) if (!pFormatIds)
{ {
pFormatIds = malloc(count * sizeof(UINT32)); pFormatIds = calloc(count, sizeof(UINT32));
if (!pFormatIds) if (!pFormatIds)
return 0; return 0;

View File

@ -57,7 +57,7 @@ static BOOL test_generic(HANDLE hComm)
return FALSE; return FALSE;
} }
pDcb = (DCB*)calloc(1, sizeof(DCB) * 2); pDcb = (DCB*)calloc(2, sizeof(DCB));
if (!pDcb) if (!pDcb)
return FALSE; return FALSE;
pDcb->DCBlength = sizeof(DCB) * 2; pDcb->DCBlength = sizeof(DCB) * 2;

View File

@ -138,7 +138,7 @@ int convert_utf8_to_utf16(BYTE* lpMultiByteStr, BYTE* expected_lpWideCharStr, in
return -1; return -1;
} }
lpWideCharStr = (LPWSTR) malloc(cchWideChar * sizeof(WCHAR)); lpWideCharStr = (LPWSTR) calloc(cchWideChar, sizeof(WCHAR));
if (!lpWideCharStr) if (!lpWideCharStr)
{ {
printf("MultiByteToWideChar: unable to allocate memory for test\n"); printf("MultiByteToWideChar: unable to allocate memory for test\n");

View File

@ -47,7 +47,7 @@ int TestCryptoCertEnumCertificatesInStore(int argc, char* argv[])
if (status == 0) if (status == 0)
return -1; return -1;
pszNameString = (LPTSTR) malloc(status * sizeof(TCHAR)); pszNameString = (LPTSTR) calloc(status, sizeof(TCHAR));
if (!pszNameString) if (!pszNameString)
{ {
printf("Unable to allocate memory\n"); printf("Unable to allocate memory\n");

View File

@ -40,7 +40,7 @@ int TestDsMakeSpn(int argc, char* argv[])
} }
/* SpnLength includes null terminator */ /* SpnLength includes null terminator */
Spn = (LPTSTR) malloc(SpnLength * sizeof(TCHAR)); Spn = (LPTSTR) calloc(SpnLength, sizeof(TCHAR));
if (!Spn) if (!Spn)
{ {
_tprintf(_T("DsMakeSpn: Unable to allocate memroy\n")); _tprintf(_T("DsMakeSpn: Unable to allocate memroy\n"));

View File

@ -231,7 +231,7 @@ LPCH GetEnvironmentStringsA(VOID)
envp = environ; envp = environ;
cchEnvironmentBlock = 128; cchEnvironmentBlock = 128;
lpszEnvironmentBlock = (LPCH) malloc(cchEnvironmentBlock * sizeof(CHAR)); lpszEnvironmentBlock = (LPCH) calloc(cchEnvironmentBlock, sizeof(CHAR));
if (!lpszEnvironmentBlock) if (!lpszEnvironmentBlock)
return NULL; return NULL;
@ -365,7 +365,7 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
offset = 0; offset = 0;
cchEnvironmentBlock = 128; cchEnvironmentBlock = 128;
lpszEnvironmentBlock = (LPCH) malloc(cchEnvironmentBlock * sizeof(CHAR)); lpszEnvironmentBlock = (LPCH) calloc(cchEnvironmentBlock, sizeof(CHAR));
if (!lpszEnvironmentBlock) if (!lpszEnvironmentBlock)
{ {

View File

@ -21,7 +21,7 @@ int TestFileFindFirstFile(int argc, char* argv[])
#ifdef UNICODE #ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0); length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR)); BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR));
if (!BasePath) if (!BasePath)
{ {
_tprintf(_T("Unable to allocate memory\n")); _tprintf(_T("Unable to allocate memory\n"));

View File

@ -23,7 +23,7 @@ int TestFileFindNextFile(int argc, char* argv[])
#ifdef UNICODE #ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0); length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR)); BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR));
if (!BasePath) if (!BasePath)
{ {
_tprintf(_T("Unable to allocate memory")); _tprintf(_T("Unable to allocate memory"));

View File

@ -172,7 +172,7 @@ NTSTATUS _RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString,
if (SourceString->MaximumLength) if (SourceString->MaximumLength)
{ {
if (!(wbuf = (PWSTR) malloc(SourceString->MaximumLength * 2))) if (!(wbuf = (PWSTR) calloc(SourceString->MaximumLength, 2)))
return STATUS_NO_MEMORY; return STATUS_NO_MEMORY;
} }

View File

@ -797,7 +797,7 @@ char* PCSC_ConvertReaderNamesToWinSCard(const char* names, LPDWORD pcchReaders)
BOOL allReaders = FALSE; BOOL allReaders = FALSE;
p = (char*) names; p = (char*) names;
cchReaders = *pcchReaders; cchReaders = *pcchReaders;
namesWinSCard = (char*) malloc(cchReaders * 2); namesWinSCard = (char*) calloc(cchReaders, 2);
if (!namesWinSCard) if (!namesWinSCard)
return NULL; return NULL;
@ -865,7 +865,7 @@ char* PCSC_ConvertReaderNamesToPCSC(const char* names, LPDWORD pcchReaders)
DWORD cchReaders; DWORD cchReaders;
p = (char*) names; p = (char*) names;
cchReaders = *pcchReaders; cchReaders = *pcchReaders;
namesPCSC = (char*) malloc(cchReaders * 2); namesPCSC = (char*) calloc(cchReaders, 2);
if (!namesPCSC) if (!namesPCSC)
return NULL; return NULL;

View File

@ -416,7 +416,7 @@ int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, SEC_WINNT_AUTH_IDEN
if (identity->UserLength > 0) if (identity->UserLength > 0)
{ {
identity->User = (UINT16*) malloc((identity->UserLength + 1) * sizeof(WCHAR)); identity->User = (UINT16*) calloc((identity->UserLength + 1), sizeof(WCHAR));
if (!identity->User) if (!identity->User)
return -1; return -1;
@ -429,7 +429,7 @@ int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, SEC_WINNT_AUTH_IDEN
if (identity->DomainLength > 0) if (identity->DomainLength > 0)
{ {
identity->Domain = (UINT16*) malloc((identity->DomainLength + 1) * sizeof(WCHAR)); identity->Domain = (UINT16*) calloc((identity->DomainLength + 1), sizeof(WCHAR));
if (!identity->Domain) if (!identity->Domain)
return -1; return -1;
@ -445,7 +445,7 @@ int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, SEC_WINNT_AUTH_IDEN
if (srcIdentity->Password) if (srcIdentity->Password)
{ {
identity->Password = (UINT16*) malloc((identity->PasswordLength + 1) * sizeof(WCHAR)); identity->Password = (UINT16*) calloc((identity->PasswordLength + 1), sizeof(WCHAR));
if (!identity->Password) if (!identity->Password)
return -1; return -1;

View File

@ -114,7 +114,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
numArgs = 0; numArgs = 0;
lpEscapedCmdLine = NULL; lpEscapedCmdLine = NULL;
cmdLineLength = (int) strlen(lpCmdLine); cmdLineLength = (int) strlen(lpCmdLine);
lpEscapedChars = (BOOL*) calloc(1, (cmdLineLength + 1) * sizeof(BOOL)); lpEscapedChars = (BOOL*) calloc(cmdLineLength + 1, sizeof(BOOL));
if (!lpEscapedChars) if (!lpEscapedChars)
return NULL; return NULL;
@ -123,7 +123,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
{ {
int i, n; int i, n;
char* pLastEnd = NULL; char* pLastEnd = NULL;
lpEscapedCmdLine = (char*) malloc((cmdLineLength + 1) * sizeof(char)); lpEscapedCmdLine = (char*) calloc(cmdLineLength + 1, sizeof(char));
if (!lpEscapedCmdLine) if (!lpEscapedCmdLine)
{ {

View File

@ -456,7 +456,7 @@ wArrayList *ArrayList_New(BOOL synchronized)
arrayList->capacity = 32; arrayList->capacity = 32;
arrayList->growthFactor = 2; arrayList->growthFactor = 2;
arrayList->object.fnObjectEquals = ArrayList_DefaultCompare; arrayList->object.fnObjectEquals = ArrayList_DefaultCompare;
arrayList->array = (void **)malloc(arrayList->capacity * sizeof(void *)); arrayList->array = (void **)calloc(arrayList->capacity, sizeof(void *));
if (!arrayList->array) if (!arrayList->array)
goto out_free; goto out_free;

View File

@ -452,7 +452,7 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment)
pool->size = 0; pool->size = 0;
pool->capacity = 32; pool->capacity = 32;
pool->array = (void**) malloc(sizeof(void*) * pool->capacity); pool->array = (void**) calloc(pool->capacity, sizeof(void*));
if (!pool->array) if (!pool->array)
goto out_error; goto out_error;
} }
@ -462,13 +462,13 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment)
pool->aSize = 0; pool->aSize = 0;
pool->aCapacity = 32; pool->aCapacity = 32;
pool->aArray = (wBufferPoolItem*) malloc(sizeof(wBufferPoolItem) * pool->aCapacity); pool->aArray = (wBufferPoolItem*) calloc(pool->aCapacity, sizeof(wBufferPoolItem));
if (!pool->aArray) if (!pool->aArray)
goto out_error; goto out_error;
pool->uSize = 0; pool->uSize = 0;
pool->uCapacity = 32; pool->uCapacity = 32;
pool->uArray = (wBufferPoolItem*) malloc(sizeof(wBufferPoolItem) * pool->uCapacity); pool->uArray = (wBufferPoolItem*) calloc(pool->uCapacity, sizeof(wBufferPoolItem));
if (!pool->uArray) if (!pool->uArray)
{ {
free(pool->aArray); free(pool->aArray);

View File

@ -129,7 +129,7 @@ wObjectPool* ObjectPool_New(BOOL synchronized)
{ {
pool->capacity = 32; pool->capacity = 32;
pool->size = 0; pool->size = 0;
pool->array = (void**) malloc(sizeof(void*) * pool->capacity); pool->array = (void**) calloc(pool->capacity, sizeof(void*));
if (!pool->array) if (!pool->array)
{ {
free(pool); free(pool);

View File

@ -218,7 +218,7 @@ wPubSub* PubSub_New(BOOL synchronized)
pubSub->count = 0; pubSub->count = 0;
pubSub->size = 64; pubSub->size = 64;
pubSub->events = (wEventType*) calloc(1, sizeof(wEventType) * pubSub->size); pubSub->events = (wEventType*) calloc(pubSub->size, sizeof(wEventType));
if (!pubSub->events) if (!pubSub->events)
{ {
if (pubSub->synchronized) if (pubSub->synchronized)

View File

@ -206,7 +206,7 @@ wStack* Stack_New(BOOL synchronized)
stack->synchronized = synchronized; stack->synchronized = synchronized;
stack->capacity = 32; stack->capacity = 32;
stack->array = (void**) malloc(sizeof(void*) * stack->capacity); stack->array = (void**) calloc(stack->capacity, sizeof(void*));
if (!stack->array) if (!stack->array)
goto out_free; goto out_free;

View File

@ -396,7 +396,7 @@ char** winpr_backtrace_symbols(void* buffer, size_t* used)
size_t array_size = data->used * sizeof(char*); size_t array_size = data->used * sizeof(char*);
size_t lines_size = data->used * line_len; size_t lines_size = data->used * line_len;
char **vlines = calloc(1, array_size + lines_size); char **vlines = calloc(1, array_size + lines_size);
SYMBOL_INFO* symbol = calloc(sizeof(SYMBOL_INFO) + line_len * sizeof(char), 1); SYMBOL_INFO* symbol = calloc(1, sizeof(SYMBOL_INFO) + line_len * sizeof(char));
IMAGEHLP_LINE64* line = (IMAGEHLP_LINE64*) calloc(1, sizeof(IMAGEHLP_LINE64)); IMAGEHLP_LINE64* line = (IMAGEHLP_LINE64*) calloc(1, sizeof(IMAGEHLP_LINE64));
if (!vlines || !symbol || !line) if (!vlines || !symbol || !line)

View File

@ -227,7 +227,7 @@ wIniFileSection* IniFile_Section_New(const char* name)
section->nKeys = 0; section->nKeys = 0;
section->cKeys = 64; section->cKeys = 64;
section->keys = (wIniFileKey**) malloc(sizeof(wIniFileKey*) * section->cKeys); section->keys = (wIniFileKey**) calloc(section->cKeys, sizeof(wIniFileKey*));
if (!section->keys) if (!section->keys)
{ {

View File

@ -766,8 +766,8 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
For every symbol, maxbitlen coins will be created*/ For every symbol, maxbitlen coins will be created*/
coinmem = numpresent * 2; /*max amount of coins needed with the current algo*/ coinmem = numpresent * 2; /*max amount of coins needed with the current algo*/
coins = (Coin*)malloc(sizeof(Coin) * coinmem); coins = (Coin*)calloc(sizeof(Coin), coinmem);
prev_row = (Coin*)malloc(sizeof(Coin) * coinmem); prev_row = (Coin*)calloc(sizeof(Coin), coinmem);
if(!coins || !prev_row) if(!coins || !prev_row)
{ {
free(coins); free(coins);
@ -1353,13 +1353,13 @@ typedef struct Hash
static unsigned hash_init(Hash* hash, unsigned windowsize) static unsigned hash_init(Hash* hash, unsigned windowsize)
{ {
unsigned i; unsigned i;
hash->head = (int*)malloc(sizeof(int) * HASH_NUM_VALUES); hash->head = (int*)calloc(sizeof(int), HASH_NUM_VALUES);
hash->val = (int*)malloc(sizeof(int) * windowsize); hash->val = (int*)calloc(sizeof(int), windowsize);
hash->chain = (unsigned short*)malloc(sizeof(unsigned short) * windowsize); hash->chain = (unsigned short*)calloc(sizeof(unsigned short), windowsize);
hash->zeros = (unsigned short*)malloc(sizeof(unsigned short) * windowsize); hash->zeros = (unsigned short*)calloc(sizeof(unsigned short), windowsize);
hash->headz = (int*)malloc(sizeof(int) * (MAX_SUPPORTED_DEFLATE_LENGTH + 1)); hash->headz = (int*)calloc(sizeof(int), (MAX_SUPPORTED_DEFLATE_LENGTH + 1));
hash->chainz = (unsigned short*)malloc(sizeof(unsigned short) * windowsize); hash->chainz = (unsigned short*)calloc(sizeof(unsigned short), windowsize);
if(!hash->head || !hash->chain || !hash->val || !hash->headz|| !hash->chainz || !hash->zeros) if(!hash->head || !hash->chain || !hash->val || !hash->headz|| !hash->chainz || !hash->zeros)
{ {

View File

@ -58,7 +58,7 @@ BYTE* NTOWFv1A(LPSTR Password, UINT32 PasswordLength, BYTE* NtHash)
{ {
LPWSTR PasswordW = NULL; LPWSTR PasswordW = NULL;
if (!(PasswordW = (LPWSTR) malloc(PasswordLength * 2))) if (!(PasswordW = (LPWSTR) calloc(PasswordLength, 2)))
return NULL; return NULL;
MultiByteToWideChar(CP_ACP, 0, Password, PasswordLength, PasswordW, PasswordLength); MultiByteToWideChar(CP_ACP, 0, Password, PasswordLength, PasswordW, PasswordLength);
@ -124,9 +124,9 @@ BYTE* NTOWFv2A(LPSTR Password, UINT32 PasswordLength, LPSTR User,
LPWSTR DomainW = NULL; LPWSTR DomainW = NULL;
LPWSTR PasswordW = NULL; LPWSTR PasswordW = NULL;
UserW = (LPWSTR) malloc(UserLength * 2); UserW = (LPWSTR) calloc(UserLength, 2);
DomainW = (LPWSTR) malloc(DomainLength * 2); DomainW = (LPWSTR) calloc(DomainLength, 2);
PasswordW = (LPWSTR) malloc(PasswordLength * 2); PasswordW = (LPWSTR) calloc(PasswordLength, 2);
if (!UserW || !DomainW || !PasswordW) if (!UserW || !DomainW || !PasswordW)
goto out_fail; goto out_fail;
@ -186,8 +186,8 @@ BYTE* NTOWFv2FromHashA(BYTE* NtHashV1, LPSTR User, UINT32 UserLength, LPSTR Doma
LPWSTR UserW = NULL; LPWSTR UserW = NULL;
LPWSTR DomainW = NULL; LPWSTR DomainW = NULL;
UserW = (LPWSTR) malloc(UserLength * 2); UserW = (LPWSTR) calloc(UserLength, 2);
DomainW = (LPWSTR) malloc(DomainLength * 2); DomainW = (LPWSTR) calloc(DomainLength, 2);
if (!UserW || !DomainW) if (!UserW || !DomainW)
goto out_fail; goto out_fail;

View File

@ -365,7 +365,7 @@ static char* x509_get_default_name(void)
GetLastError() != ERROR_MORE_DATA) GetLastError() != ERROR_MORE_DATA)
goto fallback; goto fallback;
computerName = (CHAR*)calloc(nSize, 1); computerName = (CHAR*)calloc(1, nSize);
if (!computerName) if (!computerName)
goto fallback; goto fallback;
@ -381,7 +381,7 @@ fallback:
GetLastError() != ERROR_MORE_DATA) GetLastError() != ERROR_MORE_DATA)
return NULL; return NULL;
computerName = (CHAR*)calloc(nSize, 1); computerName = (CHAR*)calloc(1, nSize);
if (!computerName) if (!computerName)
return NULL; return NULL;