Suspicious variable

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 624
Joined: Mon May 12, 2008 10:55 am

Suspicious variable

Post by SeeCwriter »

The following snippets are from v3.5.2.
In File SslSocket.cpp, beginning at line 274, It appears that local variable 'ret' can be used uninitialized at line 298.

Code: Select all

uint16_t SslSocket::InitSocket(int tcpFd, WOLFSSL_CTX *ctx, const char *commonName, uint32_t sockFlags /* = 0 */, int verifyPeer)
{
    OSCriticalSectionObj crit(m_Crit);
    uint16_t ret, error;
    char errorBuf[80];   // Buffer to hold text version of error code

    if(sockFlags != 0)
    {
        SetFlag(sockFlags);
    }

    SSL_DEBUG_IPRINTF("Getting Socket - ctx: %p - Flags: %#08lx - sockFlags: %#08lx\r\n",
            ctx, GetFlags(), sockFlags);
    CryptoSocket::InitSocket(tcpFd, &SslIoExpand);
    SSL_DEBUG_IPRINTF("Flags: %#08lx", GetFlags());


    SSL_DEBUG_IPRINTF("ctx->certificate: %p\r\n",ctx->certificate);
    if (ctx->certificate)
    {
        const int derBufSz = 4096;
        const int pemBufSz = 4096;
        puint8_t gDerBuf = new(std::nothrow) uint8_t[derBufSz];
        puint8_t gPemBuf = new(std::nothrow) uint8_t[pemBufSz];
        int ps=wc_DerToPem(gDerBuf, ret,gPemBuf,pemBufSz,CERT_TYPE);
        if(ps>0)
            SSL_DEBUG_IPRINTF("%s\r\n", gPemBuf);
        delete gDerBuf;
        delete gPemBuf;
    }
...
Also:

In File: C:\nburn\arch\coldfire\cpu\MCF5441X\source\Wire.cpp, is the assignment in the second 'if' statement, line 546, correct?

Code: Select all

int  TwoWire::readRegN(uint8_t devAddr, uint32_t reg, uint8_t *buf, uint32_t blen)
{
	beginTransmission(devAddr);
	write((uint8_t)reg);
	int rv= requestFrom(devAddr,blen,true);
	if (available()) 
	{
		int nread=read(buf,blen);
		if (nread=blen) return wire_success;


	}
	return rv;
}
In File: C:\nburn\platform\NANO54415\source\sdhc_mcf.cpp, line 713. Variable 'bus_width' is declared twice, and I believe 'if (bus_width==0)' will always evaluate to true. Is that the way it's supposed to work?

Code: Select all

    uint32_t bus_width = 0;
    if (get_scr(drv, &sdhc_dsc[drv].SCR[0], sizeof(sdhc_dsc[0].SCR)) == SDHC_NO_ERROR)
    {
        uint32_t bus_width = get_dev_reg_bits(sdhc_dsc[drv].SCR, sizeof(sdhc_dsc[0].SCR) * 8, SCR_SD_BUS_WIDTH_POS, SCR_SD_BUS_WIDTH_LEN);
        SDHC_LOG_DEBUG("SD_BUS_WIDTH=0x%x\n\r", (uint16_t)bus_width);

        if ((bus_width & 0x4) != 0) { bus_width = 4; }
        else if ((bus_width & 0x1) != 0)
        {
            bus_width = 1;
        }
        else
            bus_width = 0;

        sdhc_dsc[drv].dat_bus_width = bus_width;
    }

    if (bus_width == 0) bus_width = 4;
    ...
User avatar
TomNB
Posts: 569
Joined: Tue May 10, 2016 8:22 am

Re: Suspicious variable

Post by TomNB »

Hi SeeCwriter,

Great questions, and thank you for posting.

1. wc_DerToPem() and ret variable. That is a wolf function, so we do not want to change it. Looking at the source, it is a misuse, but does not change the functionality.

2. You are correct on this one! That assignment should not be there. The Wire driver was new for 3.5.2 and that was missed. Will be corrected.

3. Still looking into this one. bus_width is not getting assigned if get_scr() does not evaluate to true, but not yet sure if leaving it at 0 if the function is false is an issue or intentional.
User avatar
TomNB
Posts: 569
Joined: Tue May 10, 2016 8:22 am

Re: Suspicious variable

Post by TomNB »

Hi SeeCwriter. You are correct on #3 as well. We are reviewing our lint check process to determine why there were not addressed.
SeeCwriter
Posts: 624
Joined: Mon May 12, 2008 10:55 am

Re: Suspicious variable

Post by SeeCwriter »

I only found these because I rebuilt the system libs, and that always generates a lot of compiler warnings. And warnings make me nervous. So I go through every warning to see if I can do something to remove it without changing how the code works.
Post Reply