knik0 / faac

Freeware Advanced Audio Coder faac mirror
https://sourceforge.net/projects/faac/
Other
180 stars 60 forks source link

cppcheck -f -v . 2>cppcheck.log >/dev/null #28

Closed zvezdochiot closed 5 years ago

zvezdochiot commented 5 years ago

https://github.com/knik0/faac/blob/40fffb1f696ef1abaf7a0a0ec4c4c3d0cde790b1/common/Cfaac/CRegistry.cpp#L205-L209

Maybe:

        BYTE *tempVal=new BYTE[slen];
...
       delete *tempVal;

?

https://github.com/knik0/faac/blob/40fffb1f696ef1abaf7a0a0ec4c4c3d0cde790b1/common/Cfaac/CRegistry.cpp#L225-L229

Maybe:

...
       delete *tempVal;

?

https://github.com/knik0/faac/blob/40fffb1f696ef1abaf7a0a0ec4c4c3d0cde790b1/common/Cfaac/CRegistry.cpp#L343-L345

Maybe:

    *dest=NULL;
...

?

fabiangreffrath commented 5 years ago

What exactly does cppcheck print? It doesn't help if you just post the code lines.

zvezdochiot commented 5 years ago

@fabiangreffrath say> What exactly does cppcheck print?

git/knik0/faac/common/Cfaac$ cat cppcheck.log 
[CRegistry.cpp:209]: (error) Mismatching allocation and deallocation: tempVal
[CRegistry.cpp:229]: (error) Mismatching allocation and deallocation: tempVal
[CRegistry.cpp:345]: (error) Null pointer dereference
fabiangreffrath commented 5 years ago

In the first two cases, replace delete tempVal with delete[] tempVal. You are pretty sure right with your fix to the third error.

zvezdochiot commented 5 years ago

@fabiangreffrath say> You are pretty sure right with your fix to the third error.

See: https://github.com/knik0/faac/blob/40fffb1f696ef1abaf7a0a0ec4c4c3d0cde790b1/common/Cfaac/CRegistry.cpp#L317-L320 https://github.com/knik0/faac/blob/40fffb1f696ef1abaf7a0a0ec4c4c3d0cde790b1/common/Cfaac/CRegistry.cpp#L343-L345

Maybe:

int CRegistry::GetSetValN(char *keyStr, BYTE *defData, DWORD defSize, BYTE **dest)
{
long    retVal;
DWORD   size;

    *dest=NULL;
    if((retVal=RegQueryValueEx(regKey , keyStr , NULL , NULL, NULL, &size))==ERROR_SUCCESS)
        if(*dest=(BYTE *)malloc(size+1))
            retVal=RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)*dest , &size);
    if(retVal!=ERROR_SUCCESS)
    {
        if(*dest)
            free(*dest);
        if(!defData)
            return 0;

        size=defSize;
        if(!(*dest=(BYTE *)malloc(size)))
            return 0;
        memcpy(*dest,defData,size);
        RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , (BYTE *)*dest , size);
    }
    return size;
}

?

fabiangreffrath commented 5 years ago

Would you create a PR for this?

zvezdochiot commented 5 years ago

@fabiangreffrath say> Would you create a PR for this?

No time.