diff --git a/channels/audin/client/alsa/audin_alsa.c b/channels/audin/client/alsa/audin_alsa.c index e1e0001e0..a9566a541 100644 --- a/channels/audin/client/alsa/audin_alsa.c +++ b/channels/audin/client/alsa/audin_alsa.c @@ -229,7 +229,7 @@ static void* audin_alsa_thread_func(void* arg) DWORD status; DEBUG_DVC("in"); 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) { @@ -410,7 +410,7 @@ static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive, alsa->receive = receive; alsa->user_data = user_data; 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) { diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 2a0a552bf..5ee2fea18 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -164,7 +164,7 @@ static UINT audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback, } Stream_Seek_UINT32(s); /* cbSizeFormatsPacket */ - callback->formats = (audinFormat*) calloc(1, NumFormats * sizeof(audinFormat)); + callback->formats = (audinFormat*) calloc(NumFormats, sizeof(audinFormat)); if (!callback->formats) { diff --git a/channels/audin/client/opensles/opensl_io.c b/channels/audin/client/opensles/opensl_io.c index 27f964c96..d12662b96 100644 --- a/channels/audin/client/opensles/opensl_io.c +++ b/channels/audin/client/opensles/opensl_io.c @@ -253,7 +253,7 @@ OPENSL_STREAM* android_OpenRecDevice(char* name, int sr, int inchannels, int bufferframes, int bits_per_sample) { OPENSL_STREAM* p; - p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1); + p = (OPENSL_STREAM*) calloc(1, sizeof(OPENSL_STREAM)); if (!p) return NULL; diff --git a/channels/audin/client/pulse/audin_pulse.c b/channels/audin/client/pulse/audin_pulse.c index d854dca44..da12128bf 100644 --- a/channels/audin/client/pulse/audin_pulse.c +++ b/channels/audin/client/pulse/audin_pulse.c @@ -496,7 +496,7 @@ static UINT audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* u pa_threaded_mainloop_unlock(pulse->mainloop); 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) { diff --git a/channels/client/addin.c b/channels/client/addin.c index 14dda2798..11e1fb890 100644 --- a/channels/client/addin.c +++ b/channels/client/addin.c @@ -93,7 +93,7 @@ FREERDP_ADDIN** freerdp_channels_list_client_static_addins(LPSTR pszName, LPSTR FREERDP_ADDIN** ppAddins = NULL; STATIC_SUBSYSTEM_ENTRY* subsystems; nAddins = 0; - ppAddins = (FREERDP_ADDIN**) calloc(1, sizeof(FREERDP_ADDIN*) * 128); + ppAddins = (FREERDP_ADDIN**) calloc(128, sizeof(FREERDP_ADDIN*)); if (!ppAddins) { @@ -216,7 +216,7 @@ FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPSTR pszName, LPSTR pszSub hFind = FindFirstFileA(pszSearchPath, &FindData); free(pszSearchPath); nAddins = 0; - ppAddins = (FREERDP_ADDIN**) calloc(1, sizeof(FREERDP_ADDIN*) * 128); + ppAddins = (FREERDP_ADDIN**) calloc(128, sizeof(FREERDP_ADDIN*)); if (!ppAddins) { diff --git a/channels/printer/client/printer_cups.c b/channels/printer/client/printer_cups.c index 2c09c8732..d6f0705d6 100644 --- a/channels/printer/client/printer_cups.c +++ b/channels/printer/client/printer_cups.c @@ -281,7 +281,7 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver) int i; num_dests = cupsGetDests(&dests); - printers = (rdpPrinter**) calloc(1, sizeof(rdpPrinter*) * (num_dests + 1)); + printers = (rdpPrinter**) calloc(num_dests + 1, sizeof(rdpPrinter*)); if (!printers) return NULL; diff --git a/channels/rdpgfx/client/rdpgfx_codec.c b/channels/rdpgfx/client/rdpgfx_codec.c index 525dad0e3..c04cada7d 100644 --- a/channels/rdpgfx/client/rdpgfx_codec.c +++ b/channels/rdpgfx/client/rdpgfx_codec.c @@ -63,7 +63,7 @@ static UINT rdpgfx_read_h264_metablock(RDPGFX_PLUGIN* gfx, wStream* s, 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) { @@ -72,7 +72,7 @@ static UINT rdpgfx_read_h264_metablock(RDPGFX_PLUGIN* gfx, wStream* s, 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)); if (!meta->quantQualityVals) diff --git a/channels/rdpgfx/client/rdpgfx_main.c b/channels/rdpgfx/client/rdpgfx_main.c index 815e08dcb..ec9501516 100644 --- a/channels/rdpgfx/client/rdpgfx_main.c +++ b/channels/rdpgfx/client/rdpgfx_main.c @@ -1593,7 +1593,7 @@ static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, return CHANNEL_RC_OK; } - pSurfaceIds = (UINT16*) malloc(count * sizeof(UINT16)); + pSurfaceIds = (UINT16*) calloc(count, sizeof(UINT16)); if (!pSurfaceIds) { diff --git a/channels/rdpsnd/client/opensles/opensl_io.c b/channels/rdpsnd/client/opensles/opensl_io.c index 191caecc1..ffc24e12c 100644 --- a/channels/rdpsnd/client/opensles/opensl_io.c +++ b/channels/rdpsnd/client/opensles/opensl_io.c @@ -264,7 +264,7 @@ OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels, int bufferframes) { OPENSL_STREAM* p; - p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1); + p = (OPENSL_STREAM*) calloc(1, sizeof(OPENSL_STREAM)); if (!p) return NULL; diff --git a/channels/rdpsnd/client/rdpsnd_main.c b/channels/rdpsnd/client/rdpsnd_main.c index 70a5e26d9..172128d58 100644 --- a/channels/rdpsnd/client/rdpsnd_main.c +++ b/channels/rdpsnd/client/rdpsnd_main.c @@ -223,8 +223,9 @@ static void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd) if (!rdpsnd->NumberOfServerFormats) return; - rdpsnd->ClientFormats = (AUDIO_FORMAT*) calloc(sizeof(AUDIO_FORMAT), - rdpsnd->NumberOfServerFormats); + rdpsnd->ClientFormats = (AUDIO_FORMAT*) calloc( + rdpsnd->NumberOfServerFormats, + sizeof(AUDIO_FORMAT)); if (!rdpsnd->ClientFormats) return; diff --git a/channels/smartcard/client/smartcard_pack.c b/channels/smartcard/client/smartcard_pack.c index 560330a58..1f89d5431 100644 --- a/channels/smartcard/client/smartcard_pack.c +++ b/channels/smartcard/client/smartcard_pack.c @@ -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); /* NdrOffset (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) { @@ -1557,7 +1557,7 @@ LONG smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wStr return STATUS_BUFFER_TOO_SMALL; } - readerState->szReader = (WCHAR*) malloc((count + 1) * 2); + readerState->szReader = (WCHAR*) calloc((count + 1), 2); if (!readerState->szReader) { diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index f79294968..2609efbd5 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -465,7 +465,7 @@ static BOOL tsmf_sample_playback_video(TSMF_SAMPLE* sample) if (presentation->nr_rects > 0) { 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) { diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index 3ac327250..62ddb786a 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -759,7 +759,7 @@ static MSUSB_CONFIG_DESCRIPTOR* libusb_udev_complete_msconfig_setup(IUDEVICE* id LibusbInterface = &LibusbConfig->interface[MsInterface->InterfaceNumber]; LibusbAltsetting = &LibusbInterface->altsetting[MsInterface->AlternateSetting]; 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++) { diff --git a/client/Android/android_event.c b/client/Android/android_event.c index 19b246c34..de04157c3 100644 --- a/client/Android/android_event.c +++ b/client/Android/android_event.c @@ -309,7 +309,7 @@ BOOL android_event_queue_init(freerdp* inst) 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) { diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 0f158de88..fd075f6b1 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -2508,8 +2508,8 @@ BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr) && clipboard->GetUpdatedClipboardFormats)) clipboard->legacyApi = TRUE; - if (!(clipboard->format_mappings = (formatMapping*) calloc(1, - sizeof(formatMapping) * clipboard->map_capacity))) + if (!(clipboard->format_mappings = (formatMapping*) calloc(clipboard->map_capacity, + sizeof(formatMapping)))) goto error; if (!(clipboard->response_data_event = CreateEvent(NULL, TRUE, FALSE, diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index a0f2a4cb6..57a3e5310 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -580,7 +580,7 @@ static BOOL xf_gdi_polyline(rdpContext* context, XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, color.pixel); npoints = polyline->numDeltaEntries + 1; - points = malloc(sizeof(XPoint) * npoints); + points = calloc(npoints, sizeof(XPoint)); if (!points) { @@ -743,7 +743,7 @@ static BOOL xf_gdi_polygon_sc(rdpContext* context, xf_lock_x11(xfc, FALSE); xf_set_rop2(xfc, polygon_sc->bRop2); npoints = polygon_sc->numPoints + 1; - points = malloc(sizeof(XPoint) * npoints); + points = calloc(npoints, sizeof(XPoint)); if (!points) { @@ -814,7 +814,7 @@ static BOOL xf_gdi_polygon_cb(rdpContext* context, brush = &(polygon_cb->brush); xf_set_rop2(xfc, polygon_cb->bRop2); npoints = polygon_cb->numPoints + 1; - points = malloc(sizeof(XPoint) * npoints); + points = calloc(npoints, sizeof(XPoint)); if (!points) { diff --git a/client/common/file.c b/client/common/file.c index ea3c50455..ca1b9b71b 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -814,7 +814,7 @@ BOOL freerdp_client_write_rdp_file(const rdpFile* file, const char* name, BOOL u 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) { @@ -1427,7 +1427,7 @@ rdpFile* freerdp_client_rdp_file_new() FillMemory(file, sizeof(rdpFile), 0xFF); file->lineCount = 0; file->lineSize = 32; - file->lines = (rdpFileLine*) malloc(file->lineSize * sizeof(rdpFileLine)); + file->lines = (rdpFileLine*) calloc(file->lineSize, sizeof(rdpFileLine)); if (!file->lines) { @@ -1437,7 +1437,7 @@ rdpFile* freerdp_client_rdp_file_new() file->argc = 0; file->argSize = 32; - file->argv = (char**) malloc(file->argSize * sizeof(char*)); + file->argv = (char**) calloc(file->argSize, sizeof(char*)); if (!file->argv) { diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index dde1cdaaf..bf62e58c0 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -1064,7 +1064,7 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* inPlane, if (width * height == 0) return NULL; - if (!(outPlane = (BYTE*) malloc(width * height))) + if (!(outPlane = (BYTE*) calloc(height, width))) return NULL; } @@ -1269,10 +1269,10 @@ BOOL freerdp_bitmap_planar_context_reset( free(context->pTempData); free(context->deltaPlanesBuffer); free(context->rlePlanesBuffer); - context->planesBuffer = malloc(context->maxPlaneSize * 4); - context->pTempData = malloc(context->maxPlaneSize * 4); - context->deltaPlanesBuffer = malloc(context->maxPlaneSize * 4); - context->rlePlanesBuffer = malloc(context->maxPlaneSize * 4); + context->planesBuffer = calloc(context->maxPlaneSize, 4); + context->pTempData = calloc(context->maxPlaneSize, 4); + context->deltaPlanesBuffer = calloc(context->maxPlaneSize, 4); + context->rlePlanesBuffer = calloc(context->maxPlaneSize, 4); if (!context->planesBuffer || !context->pTempData || !context->deltaPlanesBuffer || !context->rlePlanesBuffer) diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index b79408e90..def538408 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -1938,28 +1938,28 @@ PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor) progressive->Compressor = Compressor; progressive->bufferPool = BufferPool_New(TRUE, (8192 + 32) * 3, 16); 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) goto cleanup; progressive->cTiles = 64; - progressive->tiles = (RFX_PROGRESSIVE_TILE**) malloc(progressive->cTiles * + progressive->tiles = (RFX_PROGRESSIVE_TILE**) calloc(progressive->cTiles, sizeof(RFX_PROGRESSIVE_TILE*)); if (!progressive->tiles) goto cleanup; progressive->cQuant = 8; - progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) malloc( - progressive->cQuant * sizeof(RFX_COMPONENT_CODEC_QUANT)); + progressive->quantVals = (RFX_COMPONENT_CODEC_QUANT*) calloc( + progressive->cQuant, sizeof(RFX_COMPONENT_CODEC_QUANT)); if (!progressive->quantVals) goto cleanup; progressive->cProgQuant = 8; - progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) malloc( - progressive->cProgQuant * sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); + progressive->quantProgVals = (RFX_PROGRESSIVE_CODEC_QUANT*) calloc( + progressive->cProgQuant, sizeof(RFX_PROGRESSIVE_CODEC_QUANT)); if (!progressive->quantProgVals) goto cleanup; diff --git a/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c b/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c index 5fff49c8e..7370eb68d 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c @@ -2968,7 +2968,7 @@ static BOOL RunTestPlanar(BITMAP_PLANAR_CONTEXT* planar, const BYTE* srcBitmap, UINT32 dstSize; BYTE* compressedBitmap = freerdp_bitmap_compress_planar(planar, 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__, GetColorFormatName(srcFormat), GetColorFormatName(dstFormat)); fflush(stdout); diff --git a/libfreerdp/common/assistance.c b/libfreerdp/common/assistance.c index fa80686b2..b0fa9ac11 100644 --- a/libfreerdp/common/assistance.c +++ b/libfreerdp/common/assistance.c @@ -87,7 +87,7 @@ int freerdp_assistance_crypt_derive_key_sha1(BYTE* hash, int hashLength, BYTE* k pad2[i] ^= hash[i]; } - buffer = (BYTE*) calloc(1, hashLength * 2); + buffer = (BYTE*) calloc(hashLength, 2); if (!buffer) goto fail; @@ -131,7 +131,7 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list) count++; } - tokens = (char**) malloc(sizeof(char*) * count); + tokens = (char**) calloc(count, sizeof(char*)); if (!tokens) { free(str); @@ -812,7 +812,7 @@ char* freerdp_assistance_bin_to_hex_string(const BYTE* data, int size) int ln, hn; char bin2hex[] = "0123456789ABCDEF"; - p = (char*) malloc((size + 1) * 2); + p = (char*) calloc((size + 1), 2); if (!p) return NULL; diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index aa804daf2..641590331 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -592,7 +592,7 @@ ADDIN_ARGV* freerdp_dynamic_channel_clone(ADDIN_ARGV* channel) return NULL; _channel->argc = channel->argc; - _channel->argv = (char**) malloc(sizeof(char*) * channel->argc); + _channel->argv = (char**) calloc(sizeof(char*), channel->argc); if (!_channel->argv) goto out_free; diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index df2da7838..8499cc7f3 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -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 * for details */ - crypt_client_random = calloc(1, key_len + 8); + crypt_client_random = calloc(key_len + 8, 1); if (!crypt_client_random) return FALSE; diff --git a/libfreerdp/core/gateway/ntlm.c b/libfreerdp/core/gateway/ntlm.c index ccfcb521a..18dfc108e 100644 --- a/libfreerdp/core/gateway/ntlm.c +++ b/libfreerdp/core/gateway/ntlm.c @@ -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) goto error; - ntlm->ServicePrincipalName = (LPTSTR) malloc(SpnLength * sizeof(TCHAR)); + ntlm->ServicePrincipalName = (LPTSTR) calloc(SpnLength, sizeof(TCHAR)); if (!ntlm->ServicePrincipalName) goto error; diff --git a/libfreerdp/core/license.c b/libfreerdp/core/license.c index d89163969..407e7691c 100644 --- a/libfreerdp/core/license.c +++ b/libfreerdp/core/license.c @@ -734,7 +734,7 @@ BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList) return FALSE; scopeList->count = scopeCount; - scopeList->array = (LICENSE_BLOB*) malloc(sizeof(LICENSE_BLOB) * scopeCount); + scopeList->array = (LICENSE_BLOB*) calloc(scopeCount, sizeof(LICENSE_BLOB)); if (!scopeList->array) return FALSE; diff --git a/libfreerdp/core/message.c b/libfreerdp/core/message.c index 0d0070581..ef4c7361f 100644 --- a/libfreerdp/core/message.c +++ b/libfreerdp/core/message.c @@ -115,7 +115,7 @@ static BOOL update_message_BitmapUpdate(rdpContext* context, wParam->number = bitmap->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) { @@ -213,7 +213,7 @@ static BOOL update_message_RefreshRect(rdpContext* context, BYTE count, if (!context || !context->update || !areas) return FALSE; - lParam = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * count); + lParam = (RECTANGLE_16*) calloc(count, sizeof(RECTANGLE_16)); if (!lParam) return FALSE; @@ -539,7 +539,7 @@ static BOOL update_message_Polyline(rdpContext* context, return FALSE; 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) { @@ -692,7 +692,7 @@ static BOOL update_message_PolygonSC(rdpContext* context, return FALSE; 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) { @@ -718,7 +718,7 @@ static BOOL update_message_PolygonCB(rdpContext* context, POLYGON_CB_ORDER* poly return FALSE; 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) { @@ -947,7 +947,7 @@ static BOOL update_message_CreateOffscreenBitmap( CopyMemory(wParam, createOffscreenBitmap, sizeof(CREATE_OFFSCREEN_BITMAP_ORDER)); wParam->deleteList.cIndices = createOffscreenBitmap->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) { @@ -1452,7 +1452,7 @@ static BOOL update_message_MonitoredDesktop(rdpContext* context, WINDOW_ORDER_IN 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); } diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index 1970e1a03..63966f562 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -1727,7 +1727,7 @@ LPTSTR nla_make_spn(const char* ServiceClass, const char* hostname) return NULL; } - ServicePrincipalName = (LPTSTR) malloc(SpnLength * sizeof(TCHAR)); + ServicePrincipalName = (LPTSTR) calloc(SpnLength, sizeof(TCHAR)); if (!ServicePrincipalName) { diff --git a/libfreerdp/core/proxy.c b/libfreerdp/core/proxy.c index 3ef2a62f8..4835477dc 100644 --- a/libfreerdp/core/proxy.c +++ b/libfreerdp/core/proxy.c @@ -133,7 +133,7 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri) hostnamelen = strlen(hostname); } - settings->ProxyHostname = calloc(1, hostnamelen + 1); + settings->ProxyHostname = calloc(hostnamelen + 1, 1); if (!settings->ProxyHostname) { diff --git a/libfreerdp/core/redirection.c b/libfreerdp/core/redirection.c index 9492adfd3..af030aa07 100644 --- a/libfreerdp/core/redirection.c +++ b/libfreerdp/core/redirection.c @@ -217,7 +217,7 @@ int rdp_redirection_apply_settings(rdpRdp* rdp) UINT32 i; freerdp_target_net_addresses_free(settings); settings->TargetNetAddressCount = redirection->TargetNetAddressesCount; - settings->TargetNetAddresses = (char**) malloc(sizeof(char*) * settings->TargetNetAddressCount); + settings->TargetNetAddresses = (char**) calloc(settings->TargetNetAddressCount, sizeof(char*)); if (!settings->TargetNetAddresses) { settings->TargetNetAddressCount = 0; diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 9af8b714a..ef4dd8ebd 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -769,8 +769,8 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings) if (_settings->ChannelDefArraySize > 0) { - _settings->ChannelDefArray = (CHANNEL_DEF*) malloc(sizeof( - CHANNEL_DEF) * settings->ChannelDefArraySize); + _settings->ChannelDefArray = (CHANNEL_DEF*) calloc(settings->ChannelDefArraySize, + sizeof(CHANNEL_DEF)); if (!_settings->ChannelDefArray) goto out_fail; @@ -786,8 +786,8 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings) if (_settings->MonitorDefArraySize > 0) { - _settings->MonitorDefArray = (rdpMonitor*) malloc(sizeof( - rdpMonitor) * settings->MonitorDefArraySize); + _settings->MonitorDefArray = (rdpMonitor*) calloc(settings->MonitorDefArraySize, + sizeof(rdpMonitor)); if (!_settings->MonitorDefArray) goto out_fail; diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index 245fc3b6e..d2d911279 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -1898,7 +1898,7 @@ BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s) if (Stream_GetRemainingLength(s) < ((size_t) numberOfAreas * 4 * 2)) return FALSE; - areas = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * numberOfAreas); + areas = (RECTANGLE_16*) calloc(numberOfAreas, sizeof(RECTANGLE_16)); if (!areas) return FALSE; @@ -2103,7 +2103,7 @@ rdpUpdate* update_new(rdpRdp* rdp) deleteList = &(update->altsec->create_offscreen_bitmap.deleteList); deleteList->sIndices = 64; - deleteList->indices = malloc(deleteList->sIndices * 2); + deleteList->indices = calloc(deleteList->sIndices, 2); if (!deleteList->indices) goto error_indices; diff --git a/libfreerdp/crypto/crypto.c b/libfreerdp/crypto/crypto.c index dadc388eb..15e65d534 100644 --- a/libfreerdp/crypto/crypto.c +++ b/libfreerdp/crypto/crypto.c @@ -213,7 +213,7 @@ char* crypto_cert_fingerprint(X509* xcert) 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) 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); 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) goto out; - *lengths = (int*) malloc(sizeof(int) * num_subject_alt_names); + *lengths = (int*) calloc(num_subject_alt_names, sizeof(int)); if (!*lengths) { free(strings); diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index d067ae124..d6d003082 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -760,7 +760,7 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context, const RDPGFX_CREATE_SURFACE_PDU* createSurface) { gdiGfxSurface* surface; - rdpGdi* gdi = (rdpGdi*) context->custom; + rdpGdi* gdi = (rdpGdi*) context->custom; surface = (gdiGfxSurface*) calloc(1, sizeof(gdiGfxSurface)); if (!surface) @@ -992,7 +992,7 @@ static UINT gdi_SurfaceToCache(RdpgfxClientContext* context, cacheEntry->height = (UINT32)(rect->bottom - rect->top); cacheEntry->format = surface->format; 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) { diff --git a/libfreerdp/locale/keyboard_layout.c b/libfreerdp/locale/keyboard_layout.c index 91bec80f8..74beb94f0 100644 --- a/libfreerdp/locale/keyboard_layout.c +++ b/libfreerdp/locale/keyboard_layout.c @@ -229,7 +229,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types) RDP_KEYBOARD_LAYOUT* new; 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) return NULL; diff --git a/rdtk/librdtk/rdtk_surface.c b/rdtk/librdtk/rdtk_surface.c index 03e64e9e0..8e20cdf1b 100644 --- a/rdtk/librdtk/rdtk_surface.c +++ b/rdtk/librdtk/rdtk_surface.c @@ -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->data = (BYTE*) malloc(surface->scanline * surface->height); + surface->data = (BYTE*) calloc(surface->height, surface->scanline); if (!surface->data) { diff --git a/rdtk/sample/rdtk_x11.c b/rdtk/sample/rdtk_x11.c index c632e5529..dbe8c2787 100644 --- a/rdtk/sample/rdtk_x11.c +++ b/rdtk/sample/rdtk_x11.c @@ -99,7 +99,7 @@ int main(int argc, char** argv) return 1; scanline = width * 4; - buffer = (BYTE*) malloc(scanline * height); + buffer = (BYTE*) calloc(height, scanline); if (!buffer) return 1; diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index a63731749..c60a229ca 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -266,7 +266,7 @@ static BOOL test_peer_load_icon(freerdp_peer* client) /* Max */ 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; 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 */ - if (!(context->bg_data = malloc(context->icon_width * context->icon_height * - 3))) + if (!(context->bg_data = calloc(context->icon_height, context->icon_width * 3))) goto out_fail; memset(context->bg_data, 0xA0, context->icon_width * context->icon_height * 3); diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c index b37c4d2a8..1855e4cd5 100644 --- a/server/Windows/wf_wasapi.c +++ b/server/Windows/wf_wasapi.c @@ -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, "matched %d characters", wcscmp(pattern, nameVar.pwszVal); devStrLen = wcslen(pwszID); - *deviceStr = (LPWSTR) calloc(1, (devStrLen * 2) + 2); + *deviceStr = (LPWSTR) calloc(devStrLen + 1, 2); if (!deviceStr) return -1; wcscpy_s(*deviceStr, devStrLen+1, pwszID); diff --git a/server/shadow/shadow_client.c b/server/shadow/shadow_client.c index d4a194756..08a133182 100644 --- a/server/shadow/shadow_client.c +++ b/server/shadow/shadow_client.c @@ -1067,8 +1067,7 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client, totalBitmapSize = 0; bitmapUpdate.count = bitmapUpdate.number = rows * cols; - if (!(bitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * - bitmapUpdate.number))) + if (!(bitmapData = (BITMAP_DATA*) calloc(bitmapUpdate.number, sizeof(BITMAP_DATA)))) return FALSE; bitmapUpdate.rectangles = bitmapData; @@ -1154,7 +1153,7 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client, BITMAP_DATA* fragBitmapData = NULL; if (k > 0) - fragBitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * k); + fragBitmapData = (BITMAP_DATA*) calloc(k, sizeof(BITMAP_DATA)); if (!fragBitmapData) { diff --git a/server/shadow/shadow_encoder.c b/server/shadow/shadow_encoder.c index b9d1cb55b..5d9218492 100644 --- a/server/shadow/shadow_encoder.c +++ b/server/shadow/shadow_encoder.c @@ -86,12 +86,12 @@ static int shadow_encoder_init_grid(rdpShadowEncoder* encoder) encoder->maxTileHeight); tileSize = encoder->maxTileWidth * encoder->maxTileHeight * 4; tileCount = encoder->gridWidth * encoder->gridHeight; - encoder->gridBuffer = (BYTE*) malloc(tileSize * tileCount); + encoder->gridBuffer = (BYTE*) calloc(tileSize, tileCount); if (!encoder->gridBuffer) return -1; - encoder->grid = (BYTE**) malloc(tileCount * sizeof(BYTE*)); + encoder->grid = (BYTE**) calloc(tileCount, sizeof(BYTE*)); if (!encoder->grid) return -1; diff --git a/server/shadow/shadow_surface.c b/server/shadow/shadow_surface.c index e3d1f8c0a..78d31a77b 100644 --- a/server/shadow/shadow_surface.c +++ b/server/shadow/shadow_surface.c @@ -40,8 +40,8 @@ rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y, surface->height = height; surface->scanline = ALIGN_SCREEN_SIZE(surface->width, 4) * 4; surface->format = PIXEL_FORMAT_BGRX32; - surface->data = (BYTE*) calloc(1, - surface->scanline * ALIGN_SCREEN_SIZE(surface->height, 4)); + surface->data = (BYTE*) calloc(ALIGN_SCREEN_SIZE(surface->height, 4), + surface->scanline); if (!surface->data) { diff --git a/winpr/libwinpr/clipboard/clipboard.c b/winpr/libwinpr/clipboard/clipboard.c index 3b2cb5b92..35956b8bc 100644 --- a/winpr/libwinpr/clipboard/clipboard.c +++ b/winpr/libwinpr/clipboard/clipboard.c @@ -197,7 +197,7 @@ UINT32 ClipboardGetRegisteredFormatIds(wClipboard* clipboard, if (!pFormatIds) { - pFormatIds = malloc(clipboard->numFormats * sizeof(UINT32)); + pFormatIds = calloc(clipboard->numFormats, sizeof(UINT32)); if (!pFormatIds) return 0; @@ -340,7 +340,7 @@ UINT32 ClipboardGetFormatIds(wClipboard* clipboard, UINT32** ppFormatIds) if (!pFormatIds) { - pFormatIds = malloc(count * sizeof(UINT32)); + pFormatIds = calloc(count, sizeof(UINT32)); if (!pFormatIds) return 0; diff --git a/winpr/libwinpr/comm/test/TestGetCommState.c b/winpr/libwinpr/comm/test/TestGetCommState.c index f021152c1..38619aecb 100644 --- a/winpr/libwinpr/comm/test/TestGetCommState.c +++ b/winpr/libwinpr/comm/test/TestGetCommState.c @@ -57,7 +57,7 @@ static BOOL test_generic(HANDLE hComm) return FALSE; } - pDcb = (DCB*)calloc(1, sizeof(DCB) * 2); + pDcb = (DCB*)calloc(2, sizeof(DCB)); if (!pDcb) return FALSE; pDcb->DCBlength = sizeof(DCB) * 2; diff --git a/winpr/libwinpr/crt/test/TestUnicodeConversion.c b/winpr/libwinpr/crt/test/TestUnicodeConversion.c index b2a103fcc..e0e13378b 100644 --- a/winpr/libwinpr/crt/test/TestUnicodeConversion.c +++ b/winpr/libwinpr/crt/test/TestUnicodeConversion.c @@ -138,7 +138,7 @@ int convert_utf8_to_utf16(BYTE* lpMultiByteStr, BYTE* expected_lpWideCharStr, in return -1; } - lpWideCharStr = (LPWSTR) malloc(cchWideChar * sizeof(WCHAR)); + lpWideCharStr = (LPWSTR) calloc(cchWideChar, sizeof(WCHAR)); if (!lpWideCharStr) { printf("MultiByteToWideChar: unable to allocate memory for test\n"); diff --git a/winpr/libwinpr/crypto/test/TestCryptoCertEnumCertificatesInStore.c b/winpr/libwinpr/crypto/test/TestCryptoCertEnumCertificatesInStore.c index b112fc80a..837e8ff74 100644 --- a/winpr/libwinpr/crypto/test/TestCryptoCertEnumCertificatesInStore.c +++ b/winpr/libwinpr/crypto/test/TestCryptoCertEnumCertificatesInStore.c @@ -47,7 +47,7 @@ int TestCryptoCertEnumCertificatesInStore(int argc, char* argv[]) if (status == 0) return -1; - pszNameString = (LPTSTR) malloc(status * sizeof(TCHAR)); + pszNameString = (LPTSTR) calloc(status, sizeof(TCHAR)); if (!pszNameString) { printf("Unable to allocate memory\n"); diff --git a/winpr/libwinpr/dsparse/test/TestDsMakeSpn.c b/winpr/libwinpr/dsparse/test/TestDsMakeSpn.c index 11510577c..3088de968 100644 --- a/winpr/libwinpr/dsparse/test/TestDsMakeSpn.c +++ b/winpr/libwinpr/dsparse/test/TestDsMakeSpn.c @@ -40,7 +40,7 @@ int TestDsMakeSpn(int argc, char* argv[]) } /* SpnLength includes null terminator */ - Spn = (LPTSTR) malloc(SpnLength * sizeof(TCHAR)); + Spn = (LPTSTR) calloc(SpnLength, sizeof(TCHAR)); if (!Spn) { _tprintf(_T("DsMakeSpn: Unable to allocate memroy\n")); diff --git a/winpr/libwinpr/environment/environment.c b/winpr/libwinpr/environment/environment.c index 84d354c89..26d1ac617 100644 --- a/winpr/libwinpr/environment/environment.c +++ b/winpr/libwinpr/environment/environment.c @@ -231,7 +231,7 @@ LPCH GetEnvironmentStringsA(VOID) envp = environ; cchEnvironmentBlock = 128; - lpszEnvironmentBlock = (LPCH) malloc(cchEnvironmentBlock * sizeof(CHAR)); + lpszEnvironmentBlock = (LPCH) calloc(cchEnvironmentBlock, sizeof(CHAR)); if (!lpszEnvironmentBlock) return NULL; @@ -365,7 +365,7 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge) offset = 0; cchEnvironmentBlock = 128; - lpszEnvironmentBlock = (LPCH) malloc(cchEnvironmentBlock * sizeof(CHAR)); + lpszEnvironmentBlock = (LPCH) calloc(cchEnvironmentBlock, sizeof(CHAR)); if (!lpszEnvironmentBlock) { diff --git a/winpr/libwinpr/file/test/TestFileFindFirstFile.c b/winpr/libwinpr/file/test/TestFileFindFirstFile.c index 917cf3930..7cb5678d7 100644 --- a/winpr/libwinpr/file/test/TestFileFindFirstFile.c +++ b/winpr/libwinpr/file/test/TestFileFindFirstFile.c @@ -21,7 +21,7 @@ int TestFileFindFirstFile(int argc, char* argv[]) #ifdef UNICODE 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) { _tprintf(_T("Unable to allocate memory\n")); diff --git a/winpr/libwinpr/file/test/TestFileFindNextFile.c b/winpr/libwinpr/file/test/TestFileFindNextFile.c index 20d5400b7..7b154eaad 100644 --- a/winpr/libwinpr/file/test/TestFileFindNextFile.c +++ b/winpr/libwinpr/file/test/TestFileFindNextFile.c @@ -23,7 +23,7 @@ int TestFileFindNextFile(int argc, char* argv[]) #ifdef UNICODE 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) { _tprintf(_T("Unable to allocate memory")); diff --git a/winpr/libwinpr/nt/nt.c b/winpr/libwinpr/nt/nt.c index 6d9dde908..2730ea3bb 100644 --- a/winpr/libwinpr/nt/nt.c +++ b/winpr/libwinpr/nt/nt.c @@ -172,7 +172,7 @@ NTSTATUS _RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, if (SourceString->MaximumLength) { - if (!(wbuf = (PWSTR) malloc(SourceString->MaximumLength * 2))) + if (!(wbuf = (PWSTR) calloc(SourceString->MaximumLength, 2))) return STATUS_NO_MEMORY; } diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index b167741bd..5a3d7eaa1 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -797,7 +797,7 @@ char* PCSC_ConvertReaderNamesToWinSCard(const char* names, LPDWORD pcchReaders) BOOL allReaders = FALSE; p = (char*) names; cchReaders = *pcchReaders; - namesWinSCard = (char*) malloc(cchReaders * 2); + namesWinSCard = (char*) calloc(cchReaders, 2); if (!namesWinSCard) return NULL; @@ -865,7 +865,7 @@ char* PCSC_ConvertReaderNamesToPCSC(const char* names, LPDWORD pcchReaders) DWORD cchReaders; p = (char*) names; cchReaders = *pcchReaders; - namesPCSC = (char*) malloc(cchReaders * 2); + namesPCSC = (char*) calloc(cchReaders, 2); if (!namesPCSC) return NULL; diff --git a/winpr/libwinpr/sspi/sspi_winpr.c b/winpr/libwinpr/sspi/sspi_winpr.c index 12d7b7ca1..ec41f5632 100644 --- a/winpr/libwinpr/sspi/sspi_winpr.c +++ b/winpr/libwinpr/sspi/sspi_winpr.c @@ -416,7 +416,7 @@ int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, SEC_WINNT_AUTH_IDEN 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) return -1; @@ -429,7 +429,7 @@ int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, SEC_WINNT_AUTH_IDEN 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) return -1; @@ -445,7 +445,7 @@ int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, SEC_WINNT_AUTH_IDEN if (srcIdentity->Password) { - identity->Password = (UINT16*) malloc((identity->PasswordLength + 1) * sizeof(WCHAR)); + identity->Password = (UINT16*) calloc((identity->PasswordLength + 1), sizeof(WCHAR)); if (!identity->Password) return -1; diff --git a/winpr/libwinpr/thread/argv.c b/winpr/libwinpr/thread/argv.c index cdef7d2ec..6739150eb 100644 --- a/winpr/libwinpr/thread/argv.c +++ b/winpr/libwinpr/thread/argv.c @@ -114,7 +114,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) numArgs = 0; lpEscapedCmdLine = NULL; cmdLineLength = (int) strlen(lpCmdLine); - lpEscapedChars = (BOOL*) calloc(1, (cmdLineLength + 1) * sizeof(BOOL)); + lpEscapedChars = (BOOL*) calloc(cmdLineLength + 1, sizeof(BOOL)); if (!lpEscapedChars) return NULL; @@ -123,7 +123,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) { int i, n; char* pLastEnd = NULL; - lpEscapedCmdLine = (char*) malloc((cmdLineLength + 1) * sizeof(char)); + lpEscapedCmdLine = (char*) calloc(cmdLineLength + 1, sizeof(char)); if (!lpEscapedCmdLine) { diff --git a/winpr/libwinpr/utils/collections/ArrayList.c b/winpr/libwinpr/utils/collections/ArrayList.c index d22b4891c..95d6f9a51 100644 --- a/winpr/libwinpr/utils/collections/ArrayList.c +++ b/winpr/libwinpr/utils/collections/ArrayList.c @@ -456,7 +456,7 @@ wArrayList *ArrayList_New(BOOL synchronized) arrayList->capacity = 32; arrayList->growthFactor = 2; arrayList->object.fnObjectEquals = ArrayList_DefaultCompare; - arrayList->array = (void **)malloc(arrayList->capacity * sizeof(void *)); + arrayList->array = (void **)calloc(arrayList->capacity, sizeof(void *)); if (!arrayList->array) goto out_free; diff --git a/winpr/libwinpr/utils/collections/BufferPool.c b/winpr/libwinpr/utils/collections/BufferPool.c index 8067ae081..1e805c5c8 100644 --- a/winpr/libwinpr/utils/collections/BufferPool.c +++ b/winpr/libwinpr/utils/collections/BufferPool.c @@ -452,7 +452,7 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment) pool->size = 0; pool->capacity = 32; - pool->array = (void**) malloc(sizeof(void*) * pool->capacity); + pool->array = (void**) calloc(pool->capacity, sizeof(void*)); if (!pool->array) goto out_error; } @@ -462,13 +462,13 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment) pool->aSize = 0; pool->aCapacity = 32; - pool->aArray = (wBufferPoolItem*) malloc(sizeof(wBufferPoolItem) * pool->aCapacity); + pool->aArray = (wBufferPoolItem*) calloc(pool->aCapacity, sizeof(wBufferPoolItem)); if (!pool->aArray) goto out_error; pool->uSize = 0; pool->uCapacity = 32; - pool->uArray = (wBufferPoolItem*) malloc(sizeof(wBufferPoolItem) * pool->uCapacity); + pool->uArray = (wBufferPoolItem*) calloc(pool->uCapacity, sizeof(wBufferPoolItem)); if (!pool->uArray) { free(pool->aArray); diff --git a/winpr/libwinpr/utils/collections/ObjectPool.c b/winpr/libwinpr/utils/collections/ObjectPool.c index 3839970f2..3eb573687 100644 --- a/winpr/libwinpr/utils/collections/ObjectPool.c +++ b/winpr/libwinpr/utils/collections/ObjectPool.c @@ -129,7 +129,7 @@ wObjectPool* ObjectPool_New(BOOL synchronized) { pool->capacity = 32; pool->size = 0; - pool->array = (void**) malloc(sizeof(void*) * pool->capacity); + pool->array = (void**) calloc(pool->capacity, sizeof(void*)); if (!pool->array) { free(pool); diff --git a/winpr/libwinpr/utils/collections/PubSub.c b/winpr/libwinpr/utils/collections/PubSub.c index 54a5a283b..de9d88b87 100644 --- a/winpr/libwinpr/utils/collections/PubSub.c +++ b/winpr/libwinpr/utils/collections/PubSub.c @@ -218,7 +218,7 @@ wPubSub* PubSub_New(BOOL synchronized) pubSub->count = 0; 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->synchronized) diff --git a/winpr/libwinpr/utils/collections/Stack.c b/winpr/libwinpr/utils/collections/Stack.c index 008d63b63..14b2d79c4 100644 --- a/winpr/libwinpr/utils/collections/Stack.c +++ b/winpr/libwinpr/utils/collections/Stack.c @@ -206,7 +206,7 @@ wStack* Stack_New(BOOL synchronized) stack->synchronized = synchronized; stack->capacity = 32; - stack->array = (void**) malloc(sizeof(void*) * stack->capacity); + stack->array = (void**) calloc(stack->capacity, sizeof(void*)); if (!stack->array) goto out_free; diff --git a/winpr/libwinpr/utils/debug.c b/winpr/libwinpr/utils/debug.c index 4d1090c49..4c2d0db66 100644 --- a/winpr/libwinpr/utils/debug.c +++ b/winpr/libwinpr/utils/debug.c @@ -396,7 +396,7 @@ char** winpr_backtrace_symbols(void* buffer, size_t* used) size_t array_size = data->used * sizeof(char*); size_t lines_size = data->used * line_len; 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)); if (!vlines || !symbol || !line) diff --git a/winpr/libwinpr/utils/ini.c b/winpr/libwinpr/utils/ini.c index 9cad4d321..9bbf45f1c 100644 --- a/winpr/libwinpr/utils/ini.c +++ b/winpr/libwinpr/utils/ini.c @@ -227,7 +227,7 @@ wIniFileSection* IniFile_Section_New(const char* name) section->nKeys = 0; section->cKeys = 64; - section->keys = (wIniFileKey**) malloc(sizeof(wIniFileKey*) * section->cKeys); + section->keys = (wIniFileKey**) calloc(section->cKeys, sizeof(wIniFileKey*)); if (!section->keys) { diff --git a/winpr/libwinpr/utils/lodepng/lodepng.c b/winpr/libwinpr/utils/lodepng/lodepng.c index 0d4bf154a..36902ce5e 100644 --- a/winpr/libwinpr/utils/lodepng/lodepng.c +++ b/winpr/libwinpr/utils/lodepng/lodepng.c @@ -766,8 +766,8 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen For every symbol, maxbitlen coins will be created*/ coinmem = numpresent * 2; /*max amount of coins needed with the current algo*/ - coins = (Coin*)malloc(sizeof(Coin) * coinmem); - prev_row = (Coin*)malloc(sizeof(Coin) * coinmem); + coins = (Coin*)calloc(sizeof(Coin), coinmem); + prev_row = (Coin*)calloc(sizeof(Coin), coinmem); if(!coins || !prev_row) { free(coins); @@ -1353,13 +1353,13 @@ typedef struct Hash static unsigned hash_init(Hash* hash, unsigned windowsize) { unsigned i; - hash->head = (int*)malloc(sizeof(int) * HASH_NUM_VALUES); - hash->val = (int*)malloc(sizeof(int) * windowsize); - hash->chain = (unsigned short*)malloc(sizeof(unsigned short) * windowsize); + hash->head = (int*)calloc(sizeof(int), HASH_NUM_VALUES); + hash->val = (int*)calloc(sizeof(int), windowsize); + hash->chain = (unsigned short*)calloc(sizeof(unsigned short), windowsize); - hash->zeros = (unsigned short*)malloc(sizeof(unsigned short) * windowsize); - hash->headz = (int*)malloc(sizeof(int) * (MAX_SUPPORTED_DEFLATE_LENGTH + 1)); - hash->chainz = (unsigned short*)malloc(sizeof(unsigned short) * windowsize); + hash->zeros = (unsigned short*)calloc(sizeof(unsigned short), windowsize); + hash->headz = (int*)calloc(sizeof(int), (MAX_SUPPORTED_DEFLATE_LENGTH + 1)); + hash->chainz = (unsigned short*)calloc(sizeof(unsigned short), windowsize); if(!hash->head || !hash->chain || !hash->val || !hash->headz|| !hash->chainz || !hash->zeros) { diff --git a/winpr/libwinpr/utils/ntlm.c b/winpr/libwinpr/utils/ntlm.c index 7dd05eeb3..771b358cc 100644 --- a/winpr/libwinpr/utils/ntlm.c +++ b/winpr/libwinpr/utils/ntlm.c @@ -58,7 +58,7 @@ BYTE* NTOWFv1A(LPSTR Password, UINT32 PasswordLength, BYTE* NtHash) { LPWSTR PasswordW = NULL; - if (!(PasswordW = (LPWSTR) malloc(PasswordLength * 2))) + if (!(PasswordW = (LPWSTR) calloc(PasswordLength, 2))) return NULL; MultiByteToWideChar(CP_ACP, 0, Password, PasswordLength, PasswordW, PasswordLength); @@ -124,9 +124,9 @@ BYTE* NTOWFv2A(LPSTR Password, UINT32 PasswordLength, LPSTR User, LPWSTR DomainW = NULL; LPWSTR PasswordW = NULL; - UserW = (LPWSTR) malloc(UserLength * 2); - DomainW = (LPWSTR) malloc(DomainLength * 2); - PasswordW = (LPWSTR) malloc(PasswordLength * 2); + UserW = (LPWSTR) calloc(UserLength, 2); + DomainW = (LPWSTR) calloc(DomainLength, 2); + PasswordW = (LPWSTR) calloc(PasswordLength, 2); if (!UserW || !DomainW || !PasswordW) goto out_fail; @@ -186,8 +186,8 @@ BYTE* NTOWFv2FromHashA(BYTE* NtHashV1, LPSTR User, UINT32 UserLength, LPSTR Doma LPWSTR UserW = NULL; LPWSTR DomainW = NULL; - UserW = (LPWSTR) malloc(UserLength * 2); - DomainW = (LPWSTR) malloc(DomainLength * 2); + UserW = (LPWSTR) calloc(UserLength, 2); + DomainW = (LPWSTR) calloc(DomainLength, 2); if (!UserW || !DomainW) goto out_fail; diff --git a/winpr/tools/makecert/makecert.c b/winpr/tools/makecert/makecert.c index 2fdb71690..a9efb352c 100644 --- a/winpr/tools/makecert/makecert.c +++ b/winpr/tools/makecert/makecert.c @@ -365,7 +365,7 @@ static char* x509_get_default_name(void) GetLastError() != ERROR_MORE_DATA) goto fallback; - computerName = (CHAR*)calloc(nSize, 1); + computerName = (CHAR*)calloc(1, nSize); if (!computerName) goto fallback; @@ -381,7 +381,7 @@ fallback: GetLastError() != ERROR_MORE_DATA) return NULL; - computerName = (CHAR*)calloc(nSize, 1); + computerName = (CHAR*)calloc(1, nSize); if (!computerName) return NULL;