dhcpcd-discuss

Re: dhcpcd-7.0.8 Coverity detected defect - Logically dead code (DEADCODE)

Stuart Henderson

Mon Sep 10 18:01:05 2018

On 2018/09/10 13:45, Shahid Mahmood wrote:
> Hi Roy,
> Our coverity analysis reported the following defect. Just so you know:
> 
>  63static size_t
>  64duid_machineuuid(char *uuid, size_t uuid_len)
>  65{
>  66        int r;
>  67        size_t len = uuid_len;
> ....

It makes more sense if you fill in the "..." :

 68 
 69 #if defined(HW_UUID) /* OpenBSD */
 70         int mib[] = { CTL_HW, HW_UUID };
 71 
 72         r = sysctl(mib, sizeof(mib)/sizeof(mib[0]), uuid, &len, NULL, 0);
 73 #elif defined(KERN_HOSTUUID) /* FreeBSD */
 74         int mib[] = { CTL_KERN, KERN_HOSTUUID };
 75 
 76         r = sysctl(mib, sizeof(mib)/sizeof(mib[0]), uuid, &len, NULL, 0);
 77 #elif defined(__NetBSD__)
 78         r = sysctlbyname("machdep.dmi.system-uuid", uuid, &len, NULL, 0);
 79 #elif defined(__linux__)
 80         FILE *fp;
 81 
 82         fp = fopen("/sys/class/dmi/id/product_uuid", "r");
 83         if (fp == NULL)
 84                 return 0;
> 85        if (fgets(uuid, (int)uuid_len, fp) == NULL) {
>  86                fclose(fp);
>  87                return 0;
>  88        }
>  89        len = strlen(uuid) + 1;
>  90        fclose(fp);
>    
> [Coverity]assignment: Assigning: r = 0.
>  91        r = 0;
>  92#else
>  93        r = -1;
>  94        errno = ENOSYS;
>  95#endif
>  96
>    
> [Coverity] const: At condition r == -1, the value of r must be equal to 0.
>    
> [Coverity] dead_error_condition: The condition r == -1 cannot be true.

there are other OS than Linux ..

>  97        if (r == -1)
>    
> [Coverity]  Logically dead code (DEADCODE)dead_error_line: Execution cannot reach this
> statement: return 0U;.
>  98                return 0;
>  99        return len;
> 100}
> 
> Regards,
> -shahid
> 


Follow-Ups:
Re: dhcpcd-7.0.8 Coverity detected defect - Logically dead code (DEADCODE)Roy Marples
References:
dhcpcd-7.0.8 Coverity detected defect - Logically dead code (DEADCODE)Shahid Mahmood
Archive administrator: postmaster@marples.name