Fixed clang malloc integer overflow warnings.
authorArmin Novak <armin.novak@thincast.com>
Tue, 30 May 2017 08:46:43 +0000 (10:46 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 20 Jul 2017 07:29:48 +0000 (09:29 +0200)
63 files changed:
channels/audin/client/alsa/audin_alsa.c
channels/audin/client/audin_main.c
channels/audin/client/opensles/opensl_io.c
channels/audin/client/pulse/audin_pulse.c
channels/client/addin.c
channels/printer/client/printer_cups.c
channels/rdpgfx/client/rdpgfx_codec.c
channels/rdpgfx/client/rdpgfx_main.c
channels/rdpsnd/client/opensles/opensl_io.c
channels/rdpsnd/client/rdpsnd_main.c
channels/smartcard/client/smartcard_pack.c
channels/tsmf/client/tsmf_media.c
channels/urbdrc/client/libusb/libusb_udevice.c
client/Android/android_event.c
client/Windows/wf_cliprdr.c
client/X11/xf_gdi.c
client/common/file.c
libfreerdp/codec/planar.c
libfreerdp/codec/progressive.c
libfreerdp/codec/test/TestFreeRDPCodecPlanar.c
libfreerdp/common/assistance.c
libfreerdp/common/settings.c
libfreerdp/core/connection.c
libfreerdp/core/gateway/ntlm.c
libfreerdp/core/license.c
libfreerdp/core/message.c
libfreerdp/core/nla.c
libfreerdp/core/proxy.c
libfreerdp/core/redirection.c
libfreerdp/core/settings.c
libfreerdp/core/update.c
libfreerdp/crypto/crypto.c
libfreerdp/gdi/gfx.c
libfreerdp/locale/keyboard_layout.c
rdtk/librdtk/rdtk_surface.c
rdtk/sample/rdtk_x11.c
server/Sample/sfreerdp.c
server/Windows/wf_wasapi.c
server/shadow/shadow_client.c
server/shadow/shadow_encoder.c
server/shadow/shadow_surface.c
winpr/libwinpr/clipboard/clipboard.c
winpr/libwinpr/comm/test/TestGetCommState.c
winpr/libwinpr/crt/test/TestUnicodeConversion.c
winpr/libwinpr/crypto/test/TestCryptoCertEnumCertificatesInStore.c
winpr/libwinpr/dsparse/test/TestDsMakeSpn.c
winpr/libwinpr/environment/environment.c
winpr/libwinpr/file/test/TestFileFindFirstFile.c
winpr/libwinpr/file/test/TestFileFindNextFile.c
winpr/libwinpr/nt/nt.c
winpr/libwinpr/smartcard/smartcard_pcsc.c
winpr/libwinpr/sspi/sspi_winpr.c
winpr/libwinpr/thread/argv.c
winpr/libwinpr/utils/collections/ArrayList.c
winpr/libwinpr/utils/collections/BufferPool.c
winpr/libwinpr/utils/collections/ObjectPool.c
winpr/libwinpr/utils/collections/PubSub.c
winpr/libwinpr/utils/collections/Stack.c
winpr/libwinpr/utils/debug.c
winpr/libwinpr/utils/ini.c
winpr/libwinpr/utils/lodepng/lodepng.c
winpr/libwinpr/utils/ntlm.c
winpr/tools/makecert/makecert.c

index e1e0001..a9566a5 100644 (file)
@@ -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)
        {
index 2a0a552..5ee2fea 100644 (file)
@@ -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)
        {
index 27f964c..d12662b 100644 (file)
@@ -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;
index d854dca..da12128 100644 (file)
@@ -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)
        {
index 14dda27..11e1fb8 100644 (file)
@@ -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)
        {
index 2c09c87..d6f0705 100644 (file)
@@ -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;
 
index 525dad0..c04cada 100644 (file)
@@ -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)
index 815e08d..ec95015 100644 (file)
@@ -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)
        {
index 191caec..ffc24e1 100644 (file)
@@ -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;
index 70a5e26..172128d 100644 (file)
@@ -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;
index 560330a..1f89d54 100644 (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); /* 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)
                        {
index f792949..2609efb 100644 (file)
@@ -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)
                        {
index 3ac3272..62ddb78 100644 (file)
@@ -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++)
                {
index 19b246c..de04157 100644 (file)
@@ -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)
        {
index 0f158de..fd075f6 100644 (file)
@@ -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,
index a0f2a4c..57a3e53 100644 (file)
@@ -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)
        {
index ea3c504..ca1b9b7 100644 (file)
@@ -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)
                {
index dde1cda..bf62e58 100644 (file)
@@ -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)
index b79408e..def5384 100644 (file)
@@ -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;
index 5fff49c..7370eb6 100644 (file)
@@ -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);
index fa80686..b0fa9ac 100644 (file)
@@ -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;
 
index aa804da..6415903 100644 (file)
@@ -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;
index df2da78..8499cc7 100644 (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
         * for details
         */
-       crypt_client_random = calloc(1, key_len + 8);
+       crypt_client_random = calloc(key_len + 8, 1);
 
        if (!crypt_client_random)
                return FALSE;
index ccfcb52..18dfc10 100644 (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)
                goto error;
 
-       ntlm->ServicePrincipalName = (LPTSTR) malloc(SpnLength * sizeof(TCHAR));
+       ntlm->ServicePrincipalName = (LPTSTR) calloc(SpnLength, sizeof(TCHAR));
 
        if (!ntlm->ServicePrincipalName)
                goto error;
index d891639..407e769 100644 (file)
@@ -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;
 
index 0d00705..ef4c736 100644 (file)
@@ -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);
        }
 
index 1970e1a..63966f5 100644 (file)
@@ -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)
        {
index 3ef2a62..4835477 100644 (file)
@@ -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)
        {
index 9492adf..af030aa 100644 (file)
@@ -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;
index 9af8b71..ef4dd8e 100644 (file)
@@ -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;
index 245fc3b..d2d9112 100644 (file)
@@ -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;
index dadc388..15e65d5 100644 (file)
@@ -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);
index d067ae1..d6d0030 100644 (file)
@@ -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)
        {
index 91bec80..74beb94 100644 (file)
@@ -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;
 
index 03e64e9..8e20cdf 100644 (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->data = (BYTE*) malloc(surface->scanline * surface->height);
+               surface->data = (BYTE*) calloc(surface->height, surface->scanline);
 
                if (!surface->data)
                {
index c632e55..dbe8c27 100644 (file)
@@ -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;
 
index a637317..c60a229 100644 (file)
@@ -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);
index b37c4d2..1855e4c 100644 (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, "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);
index d4a1947..08a1331 100644 (file)
@@ -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)
                {
index b9d1cb5..5d92184 100644 (file)
@@ -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;
index e3d1f8c..78d31a7 100644 (file)
@@ -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)
        {
index 3b2cb5b..35956b8 100644 (file)
@@ -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;
index f021152..38619ae 100644 (file)
@@ -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;
index b2a103f..e0e1337 100644 (file)
@@ -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");
index b112fc8..837e8ff 100644 (file)
@@ -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");
index 1151057..3088de9 100644 (file)
@@ -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"));
index 84d354c..26d1ac6 100644 (file)
@@ -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)
        {
index 917cf39..7cb5678 100644 (file)
@@ -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"));
index 20d5400..7b154ea 100644 (file)
@@ -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"));
index 6d9dde9..2730ea3 100644 (file)
@@ -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;
                }
 
index b167741..5a3d7ea 100644 (file)
@@ -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;
index 12d7b7c..ec41f56 100644 (file)
@@ -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;
index cdef7d2..6739150 100644 (file)
@@ -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)
                {
index d22b489..95d6f9a 100644 (file)
@@ -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;
index 8067ae0..1e805c5 100644 (file)
@@ -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);
index 3839970..3eb5736 100644 (file)
@@ -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);
index 54a5a28..de9d88b 100644 (file)
@@ -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)
index 008d63b..14b2d79 100644 (file)
@@ -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;
 
index 4d1090c..4c2d0db 100644 (file)
@@ -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)
index 9cad4d3..9bbf45f 100644 (file)
@@ -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)
        {
index 0d4bf15..36902ce 100644 (file)
@@ -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)
   {
index 7dd05ee..771b358 100644 (file)
@@ -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;
index 2fdb716..a9efb35 100644 (file)
@@ -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;