Merge pull request #5223 from akallabeth/scanbuild_null_fixes

Scanbuild null fixes
This commit is contained in:
David Fort 2019-01-30 18:22:45 +01:00 committed by GitHub
commit 85161c718f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 102 additions and 19 deletions

View File

@ -279,7 +279,7 @@ static DWORD WINAPI audin_oss_thread_func(LPVOID arg)
err_out:
if (error && oss->rdpcontext)
if (error && oss && oss->rdpcontext)
setChannelError(oss->rdpcontext, error,
"audin_oss_thread_func reported an error");

View File

@ -161,7 +161,7 @@ LONG smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UI
SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartcard,
REDIR_SCARDCONTEXT* context)
{
SCARDCONTEXT hContext = 0;
SCARDCONTEXT hContext = { 0 };
if ((context->cbContext != sizeof(ULONG_PTR)) && (context->cbContext != 0))
{
@ -173,8 +173,6 @@ SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartca
if (context->cbContext)
CopyMemory(&hContext, &(context->pbContext), context->cbContext);
else
ZeroMemory(&hContext, sizeof(ULONG_PTR));
return hContext;
}

View File

@ -1387,7 +1387,7 @@ static int libusb_udev_isoch_transfer(IUDEVICE* idev, UINT32 RequestId, UINT32 E
if (iso_transfer == NULL)
{
WLog_ERR(TAG, "Error: libusb_alloc_transfer.");
status = -1;
return -1;
}
/** process URB_FUNCTION_IOSCH_TRANSFER */

View File

@ -643,6 +643,7 @@ static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context
{
cnv = ConvertToUnicode(CP_UTF8, 0, (LPCSTR)data, (int)size, &cdata, 0);
free(data);
data = NULL;
if (cnv < 0)
rc = ERROR_INTERNAL_ERROR;

View File

@ -213,7 +213,7 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event)
char buffer[1024] = { 0 };
char command[1024] = { 0 };
if (!xfc->actionScriptExists || !xfc->xevents)
if (!xfc->actionScriptExists || !xfc->xevents || !xfc->window)
return FALSE;
if (event->type > LASTEvent)
@ -477,6 +477,9 @@ static BOOL xf_event_KeyRelease(xfContext* xfc, XEvent* event, BOOL app)
}
static BOOL xf_event_FocusIn(xfContext* xfc, XEvent* event, BOOL app)
{
if (!xfc->window)
return FALSE;
if (event->xfocus.mode == NotifyGrab)
return TRUE;
@ -560,6 +563,9 @@ static BOOL xf_event_ClientMessage(xfContext* xfc, XEvent* event, BOOL app)
}
static BOOL xf_event_EnterNotify(xfContext* xfc, XEvent* event, BOOL app)
{
if (!xfc->window)
return FALSE;
if (!app)
{
xfc->mouse_active = TRUE;
@ -601,7 +607,12 @@ static BOOL xf_event_ConfigureNotify(xfContext* xfc, XEvent* event, BOOL app)
{
Window childWindow;
xfAppWindow* appWindow;
rdpSettings* settings = xfc->context.settings;
rdpSettings* settings;
if (!xfc->window)
return FALSE;
settings = xfc->context.settings;
if (!app)
{

View File

@ -141,7 +141,7 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
int monitor_index = 0;
BOOL primaryMonitorFound = FALSE;
VIRTUAL_SCREEN* vscreen;
rdpSettings* settings = xfc->context.settings;
rdpSettings* settings;
int mouse_x, mouse_y, _dummy_i;
Window _dummy_w;
int current_monitor = 0;
@ -154,6 +154,11 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
XRRMonitorInfo* rrmonitors = NULL;
BOOL useXRandr = FALSE;
#endif
if (!xfc || !pMaxWidth || !pMaxHeight || !xfc->context.settings)
return FALSE;
settings = xfc->context.settings;
vscreen = &xfc->vscreen;
*pMaxWidth = settings->DesktopWidth;
*pMaxHeight = settings->DesktopHeight;
@ -274,6 +279,9 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
if (settings->NumMonitorIds == 1)
{
monitor = vscreen->monitors + current_monitor;
if (!monitor)
return FALSE;
xfc->workArea.x = monitor->area.left;
xfc->workArea.y = monitor->area.top;
xfc->workArea.width = monitor->area.right - monitor->area.left + 1;
@ -305,6 +313,9 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
*/
if (vscreen->nmonitors > 0)
{
if (!vscreen->monitors)
return FALSE;
*pMaxWidth = vscreen->monitors[current_monitor].area.right -
vscreen->monitors[current_monitor].area.left + 1;
*pMaxHeight = vscreen->monitors[current_monitor].area.bottom -
@ -346,6 +357,9 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
if (!xf_is_monitor_id_active(xfc, i))
continue;
if (!vscreen->monitors)
return FALSE;
settings->MonitorDefArray[nmonitors].x = vscreen->monitors[i].area.left;
settings->MonitorDefArray[nmonitors].y = vscreen->monitors[i].area.top;
settings->MonitorDefArray[nmonitors].width =
@ -380,7 +394,10 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
/* If no monitor is active(bogus command-line monitor specification) - then lets try to fallback to go fullscreen on the current monitor only */
if (nmonitors == 0 && vscreen->nmonitors > 0)
{
{
if (!vscreen->monitors)
return FALSE;
settings->MonitorDefArray[0].x = vscreen->monitors[current_monitor].area.left;
settings->MonitorDefArray[0].y = vscreen->monitors[current_monitor].area.top;
settings->MonitorDefArray[0].width = MIN(

View File

@ -164,7 +164,7 @@ static BOOL clear_decompress_subcode_rlex(wStream* s,
Stream_Read_UINT8(s, paletteCount);
bitmapDataOffset = 1 + (paletteCount * 3);
if (paletteCount > 127)
if ((paletteCount > 127) || (paletteCount < 1))
{
WLog_ERR(TAG, "paletteCount %"PRIu8"", paletteCount);
return FALSE;

View File

@ -1343,6 +1343,21 @@ static INLINE pstatus_t general_RGBToAVC444YUV(
BYTE* pDst2[3], const UINT32 dst2Step[3],
const prim_size_t* roi)
{
if (!pSrc || !pDst1 || !dst1Step || !pDst2 || !dst2Step)
return -1;
if (!pDst1[0] || !pDst1[1] || !pDst1[2])
return -1;
if (!dst1Step[0] || !dst1Step[1] || !dst1Step[2])
return -1;
if (!pDst2[0] || !pDst2[1] || !pDst2[2])
return -1;
if (!dst2Step[0] || !dst2Step[1] || !dst2Step[2])
return -1;
switch (srcFormat)
{
case PIXEL_FORMAT_BGRA32:

View File

@ -84,6 +84,9 @@ PFORMAT_STRING NdrpComputeCount(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMem
switch (correlation_operator)
{
case FC_DEREFERENCE:
if (!ptr)
return pFormat;
ptr = *(LPVOID*)((char*) ptr + offset);
break;

View File

@ -673,6 +673,9 @@ static void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer)
SecPkgInfoA* pPackageInfo = (SecPkgInfoA*) contextBuffer;
cPackages = sizeof(SecPkgInfoA_LIST) / sizeof(*(SecPkgInfoA_LIST));
if (!pPackageInfo)
return;
for (index = 0; index < (int) cPackages; index++)
{
free(pPackageInfo[index].Name);

View File

@ -117,6 +117,7 @@ static unsigned uivector_reserve(uivector* p, size_t allocsize)
void* data = realloc(p->data, newsize);
if(data)
{
memset(&((char*)data)[p->allocsize], 0, newsize - p->allocsize);
p->allocsize = newsize;
p->data = (unsigned*)data;
}
@ -908,6 +909,9 @@ static unsigned huffmanDecodeSymbol(const unsigned char* in, size_t* bp,
const HuffmanTree* codetree, size_t inbitlength)
{
unsigned treepos = 0, ct;
if (!codetree || !codetree->tree2d)
return 0;
for(;;)
{
if(*bp >= inbitlength) return (unsigned)(-1); /*error: end of input memory reached without endcode*/
@ -1759,6 +1763,9 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
else
{
if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/);
if (!lz77_encoded.data)
ERROR_BREAK(83 /* alloc fail */);
for(i = datapos; i < dataend; i++) lz77_encoded.data[i] = data[i]; /*no LZ77, but still will be Huffman compressed*/
}
@ -1768,7 +1775,12 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
/*Count the frequencies of lit, len and dist codes*/
for(i = 0; i < lz77_encoded.size; i++)
{
unsigned symbol = lz77_encoded.data[i];
unsigned symbol;
if (!lz77_encoded.data)
ERROR_BREAK(83 /* alloc fail */);
symbol = lz77_encoded.data[i];
frequencies_ll.data[symbol]++;
if(symbol > 256)
{
@ -2399,8 +2411,16 @@ static void setBitOfReversedStream0(size_t* bitpointer, unsigned char* bitstream
static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, unsigned char bit)
{
/*the current bit in bitstream may be 0 or 1 for this to work*/
if(bit == 0) bitstream[(*bitpointer) >> 3] &= (unsigned char)(~(1 << (7 - ((*bitpointer) & 0x7))));
else bitstream[(*bitpointer) >> 3] |= (1 << (7 - ((*bitpointer) & 0x7)));
if(bit == 0)
{
size_t pos = (*bitpointer) >> 3;
bitstream[pos] &= (unsigned char)(~(1 << (7 - ((*bitpointer) & 0x7))));
}
else
{
size_t pos = (*bitpointer) >> 3;
bitstream[pos] |= (1 << (7 - ((*bitpointer) & 0x7)));
}
(*bitpointer)++;
}
@ -5428,7 +5448,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
if(info_png->interlace_method == 0)
{
*outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/
*out = (unsigned char*)malloc(*outsize);
*out = (unsigned char*)calloc(*outsize, 1);
if(!(*out) && (*outsize)) error = 83; /*alloc fail*/
if(!error)
@ -5436,7 +5456,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
/*non multiple of 8 bits per scanline, padding bits needed per scanline*/
if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
{
unsigned char* padded = (unsigned char*)malloc(h * ((w * bpp + 7) / 8));
unsigned char* padded = (unsigned char*)calloc(h * ((w * bpp + 7) / 8), 1);
if(!padded) error = 83; /*alloc fail*/
if(!error)
{
@ -5461,7 +5481,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
*outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/
*out = (unsigned char*)malloc(*outsize);
*out = (unsigned char*)calloc(*outsize, 1);
if(!(*out)) error = 83; /*alloc fail*/
adam7 = (unsigned char*)calloc(passstart[7], sizeof(unsigned char));
@ -5594,7 +5614,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
unsigned char* converted;
size_t size = (w * h * lodepng_get_bpp(&info.color) + 7) / 8;
converted = (unsigned char*)malloc(size);
converted = (unsigned char*)calloc(size, 1);
if(!converted && size) state->error = 83; /*alloc fail*/
if(!state->error)
{
@ -5769,8 +5789,8 @@ unsigned lodepng_encode24(unsigned char** out, size_t* outsize, const unsigned c
unsigned lodepng_encode_file(const char* filename, const unsigned char* image, unsigned w, unsigned h,
LodePNGColorType colortype, unsigned bitdepth)
{
unsigned char* buffer;
size_t buffersize;
unsigned char* buffer = NULL;
size_t buffersize = 0;
unsigned error = lodepng_encode_memory(&buffer, &buffersize, image, w, h, colortype, bitdepth);
if(!error) error = lodepng_save_file(buffer, buffersize, filename);
free(buffer);

View File

@ -6584,6 +6584,9 @@ TRIO_ARGS4((self, target, flags, width),
infinity = ((start == 1) && (doubleString[0] == '-'))
? trio_ninf()
: trio_pinf();
if (!target)
return FALSE;
if (flags & FLAGS_LONGDOUBLE)
{
*((trio_long_double_t *)target) = infinity;
@ -6600,6 +6603,9 @@ TRIO_ARGS4((self, target, flags, width),
}
if (trio_equal(doubleString, NAN_UPPER))
{
if (!target)
return FALSE;
/* NaN must not have a preceeding + nor - */
if (flags & FLAGS_LONGDOUBLE)
{
@ -6696,14 +6702,23 @@ TRIO_ARGS4((self, target, flags, width),
if (flags & FLAGS_LONGDOUBLE)
{
if (!target)
return FALSE;
*((trio_long_double_t *)target) = trio_to_long_double(doubleString, NULL);
}
else if (flags & FLAGS_LONG)
{
if (!target)
return FALSE;
*((double *)target) = trio_to_double(doubleString, NULL);
}
else
{
if (!target)
return FALSE;
*((float *)target) = trio_to_float(doubleString, NULL);
}
return TRUE;