[Toybox] [PATCH] hwclock cleanup.
    Rob Landley 
    rob at landley.net
       
    Sun Jan 10 19:27:59 PST 2016
    
    
  
On 01/09/2016 02:35 PM, enh wrote:
> Fix a misspelled (and slightly technically inaccurate) comment, and fix an
> accidental self-assignment.
It's not accidental. Self-assignment at initialization is a way to get
gcc to shut up about "may be used uninitialized, but isn't actually"
errors. In this case, if I remove the assignment it goes:
toys/other/hwclock.c:96:13: warning: 's' may be used uninitialized in
this function [-Wmaybe-uninitialized]
         free(s);
             ^
When the logic block is:
    if (!w) {
      char *s;
      xioctl(fd, RTC_RD_TIME, &tm);
      if (TT.utc) s = xtzset("UTC0");
      if ((time = mktime(&tm)) < 0) error_exit("mktime failed");
      if (TT.utc) {
        free(xtzset(s));
        free(s);
      }
    }
I.E. the assignment and use are under the same test of the same
variable, but since it's a global variable gcc can't confirm it's not
changing between the two of them even though we know it isn't. Maybe
someday the --whole-tree stuff will advance to the point it can stop
producing false positives, but not yet.
Self-assignment generates no code (always optimized out) and signals to
the compiler that it can shut up about the stupid warning. It's used in
a few places for exactly that purpose.
Rob
    
    
More information about the Toybox
mailing list