upnpc.c: prevent warning with gcc 10 and 11
src/upnpc.c:153:37: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Wformat-truncation=] 153 | snprintf(index, 6, "%d", i); | ^~ src/upnpc.c:153:36: note: directive argument in the range [0, 2147483647] 153 | snprintf(index, 6, "%d", i); | ^~~~ Somehow the static analyser fails to recognize that 0 <= i < 65536 see #643
This commit is contained in:
parent
98cc9f1b43
commit
b10c247fb1
|
@ -135,7 +135,7 @@ static void ListRedirections(struct UPNPUrls * urls,
|
||||||
struct IGDdatas * data)
|
struct IGDdatas * data)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
int i = 0;
|
unsigned short i = 0;
|
||||||
char index[6];
|
char index[6];
|
||||||
char intClient[40];
|
char intClient[40];
|
||||||
char intPort[6];
|
char intPort[6];
|
||||||
|
@ -150,7 +150,7 @@ static void ListRedirections(struct UPNPUrls * urls,
|
||||||
printf("PortMappingNumberOfEntries : %u\n", num);*/
|
printf("PortMappingNumberOfEntries : %u\n", num);*/
|
||||||
printf(" i protocol exPort->inAddr:inPort description remoteHost leaseTime\n");
|
printf(" i protocol exPort->inAddr:inPort description remoteHost leaseTime\n");
|
||||||
do {
|
do {
|
||||||
snprintf(index, 6, "%d", i);
|
snprintf(index, 6, "%hu", i);
|
||||||
rHost[0] = '\0'; enabled[0] = '\0';
|
rHost[0] = '\0'; enabled[0] = '\0';
|
||||||
duration[0] = '\0'; desc[0] = '\0';
|
duration[0] = '\0'; desc[0] = '\0';
|
||||||
extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0';
|
extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0';
|
||||||
|
@ -162,20 +162,19 @@ static void ListRedirections(struct UPNPUrls * urls,
|
||||||
rHost, duration);
|
rHost, duration);
|
||||||
if(r==0)
|
if(r==0)
|
||||||
/*
|
/*
|
||||||
printf("%02d - %s %s->%s:%s\tenabled=%s leaseDuration=%s\n"
|
printf("%02hu - %s %s->%s:%s\tenabled=%s leaseDuration=%s\n"
|
||||||
" desc='%s' rHost='%s'\n",
|
" desc='%s' rHost='%s'\n",
|
||||||
i, protocol, extPort, intClient, intPort,
|
i, protocol, extPort, intClient, intPort,
|
||||||
enabled, duration,
|
enabled, duration,
|
||||||
desc, rHost);
|
desc, rHost);
|
||||||
*/
|
*/
|
||||||
printf("%2d %s %5s->%s:%-5s '%s' '%s' %s\n",
|
printf("%2hu %s %5s->%s:%-5s '%s' '%s' %s\n",
|
||||||
i, protocol, extPort, intClient, intPort,
|
i, protocol, extPort, intClient, intPort,
|
||||||
desc, rHost, duration);
|
desc, rHost, duration);
|
||||||
else
|
else
|
||||||
printf("GetGenericPortMappingEntry() returned %d (%s)\n",
|
printf("GetGenericPortMappingEntry() returned %d (%s)\n",
|
||||||
r, strupnperror(r));
|
r, strupnperror(r));
|
||||||
i++;
|
} while(r == 0 && i++ < 65535);
|
||||||
} while(r == 0 && i < 65536);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NewListRedirections(struct UPNPUrls * urls,
|
static void NewListRedirections(struct UPNPUrls * urls,
|
||||||
|
|
Loading…
Reference in New Issue