fix hotspot build failures with -D_FORTIFY_SOURCE=2 and -Wformat=1

Matthias Klose doko at ubuntu.com
Wed Dec 3 05:46:08 PST 2008


Kelly O'Hair schrieb:
> 
> 
> David Holmes - Sun Microsystems wrote:
>> Hi Matthias,
>>
>> Can't we get rid of all the dummy variables here:
>>
>>    count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu",
>> -                 &idummy, &idummy, &idummy, &idummy, &idummy, &idummy,
>> +                 &cdummy, &idummy, &idummy, &idummy, &idummy, &idummy,
>>                   &ldummy, &ldummy, &ldummy, &ldummy, &ldummy,
>>                   &user_time, &sys_time);
>>
>> by using the %*d %*c format specifiers to parse but not store the value.
>>
>> And here:
>>
>> -    ::write(defaultStream::output_fd(), s, (int)strlen(s));
>> +    ssize_t rv = ::write(defaultStream::output_fd(), s, (int)strlen(s));
>>
>> if we are ignoring the return value anyway (which might be the real
>> error here!) wouldn't a cast to void be a cleaner fix?
> 
> I tend to agree on the (void) cast, and seems like we run the risk of a
> 'local variable assigned to but not used' warning...   or do any C/C++
> compilers do that?

          int fn () __attribute__ ((warn_unused_result));
          int foo ()
          {
            if (fn () < 0) return -1;
            (void) fn ();
            return 0;
          }

gcc (4.3.x, 4.4) still warns about the unused return value.

hotspot currently cannot be built with -Wunused or -Wunused-variable.



More information about the distro-pkg-dev mailing list