[libvirt PATCH v2 1/2] nwfilter: Replace a redundant 'now' variable with a direct time(0) call

Erik Skultety posted 2 patches 3 years, 5 months ago
[libvirt PATCH v2 1/2] nwfilter: Replace a redundant 'now' variable with a direct time(0) call
Posted by Erik Skultety 3 years, 5 months ago
In this very instance having a variable is pointless since there is
only a single time(0) call in the whole function.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
---
 src/nwfilter/nwfilter_dhcpsnoop.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index a10a14cfc1..18812c0b20 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -1723,13 +1723,11 @@ virNWFilterSnoopLeaseFileLoad(void)
     char ipstr[INET_ADDRSTRLEN], srvstr[INET_ADDRSTRLEN];
     virNWFilterSnoopIPLease ipl;
     virNWFilterSnoopReq *req;
-    time_t now;
     FILE *fp;
     int ln = 0, tmp;
     VIR_LOCK_GUARD lock = virLockGuardLock(&virNWFilterSnoopState.snoopLock);
 
     fp = fopen(LEASEFILE, "r");
-    time(&now);
     while (fp && fgets(line, sizeof(line), fp)) {
         if (line[strlen(line)-1] != '\n') {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1746,7 +1744,7 @@ virNWFilterSnoopLeaseFileLoad(void)
                              "line %d corrupt"), ln);
             break;
         }
-        if (ipl.timeout && ipl.timeout < now)
+        if (ipl.timeout && ipl.timeout < time(0))
             continue;
         req = virNWFilterSnoopReqGetByIFKey(ifkey);
         if (!req) {
-- 
2.37.2
Re: [libvirt PATCH v2 1/2] nwfilter: Replace a redundant 'now' variable with a direct time(0) call
Posted by Peter Krempa 3 years, 5 months ago
On Tue, Aug 23, 2022 at 18:22:36 +0200, Erik Skultety wrote:
> In this very instance having a variable is pointless since there is
> only a single time(0) call in the whole function.
> 
> Signed-off-by: Erik Skultety <eskultet@redhat.com>
> ---
>  src/nwfilter/nwfilter_dhcpsnoop.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
> index a10a14cfc1..18812c0b20 100644
> --- a/src/nwfilter/nwfilter_dhcpsnoop.c
> +++ b/src/nwfilter/nwfilter_dhcpsnoop.c

[...]

> @@ -1746,7 +1744,7 @@ virNWFilterSnoopLeaseFileLoad(void)
>                               "line %d corrupt"), ln);
>              break;
>          }
> -        if (ipl.timeout && ipl.timeout < now)
> +        if (ipl.timeout && ipl.timeout < time(0))

'time()' takes a pointer, so the argument should be 'NULL' instead.

>              continue;
>          req = virNWFilterSnoopReqGetByIFKey(ifkey);
>          if (!req) {
> -- 
> 2.37.2
>