View previous topic :: View next topic |
Author |
Message |
fox88
Joined: 05 Feb 2015 Posts: 9
|
Posted: Sat Mar 05, 2016 8:23 am Post subject: Minor issues from cppcheck |
|
|
In file miniupnpcommands.c both lines 583 and 584 are flagged with the messages:
Either the condition 'p&&intClient' is redundant or there is possible null pointer dereference: intClient.
The lines in question are:
Code: | intClient[0] = '\0';
intPort[0] = '\0';
|
The reason is that below at line 619 both pointers are checked for null
Code: |
if(p && intClient)
{
strncpy(intClient, p, 16);
intClient[15] = '\0';
r = 0;
}
p = GetValueFromNameValueList(&pdata, "NewInternalPort");
if(p && intPort)
{
strncpy(intPort, p, 6);
intPort[5] = '\0';
}
|
Which means there are three theoretical possibilities.
1. Pointers cannot be null at lines 583 and 584 (verified somewhere before the call). Then no further checking is necessary.
2. Pointers must be checked before assignments, furthers checks removed.
3. Intended check was not for pointers, but for non-empty string.
My guess would be the point 2. |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1594
|
|
Back to top |
|
 |
fox88
Joined: 05 Feb 2015 Posts: 9
|
Posted: Sat Mar 12, 2016 9:18 pm Post subject: |
|
|
Sorry, I should have posted the topic in miniupnpc Bugs (it could be moved to the proper subforum, though).
Anyway, there is another unnecessary check in file miniupnpc.c at line 685:
Code: | if(desc[i].xml) {
free(desc[i].xml);
|
According to standards: If ptr is a null pointer, no action occurs. |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1594
|
Posted: Mon Mar 14, 2016 9:35 am Post subject: |
|
|
fox88 wrote: | Sorry, I should have posted the topic in miniupnpc Bugs (it could be moved to the proper subforum, though).
Anyway, there is another unnecessary check in file miniupnpc.c at line 685:
Code: | if(desc[i].xml) {
free(desc[i].xml);
|
According to standards: If ptr is a null pointer, no action occurs. |
you are right, I should fix that. _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
|