[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question on FAT Code



Hi,

Coverity (#183) reported an issue in
cpukit/libfs/src/dosfs/msdos_format.c.
Th

1081         case FAT_FAT16:
1082           /* FAT entry 0: 0xff00|media_type */
Event result_independent_of_operands: (0xff00 | fmt_params.media_code) 
 >> 8 is 0xff regardless of the values of its operands [non-specific 
operand of assignment].
1083           FAT_SET_VAL16(tmp_sec,0,0xff00|fmt_params.media_code);

Looking at the definition of FAT_SET_VAL16(),
I can see what it doesn't like.

#define FAT_SET_VAL16(x, ofs,val) do {              \
                  FAT_SET_VAL8((x),(ofs),(val));     \
                  FAT_SET_VAL8((x),(ofs)+1,(val)>>8);\
                  } while (0)

In the case of line 1083, offset 1 is always 0xff.
Would this code better written as?

FAT_SET_VAL8(tmp_sec,0,fmt_params.media_code);
FAT_SET_VAL8(tmp_sec,1,0xff);

It avoids the evaluation to a constant for offset 1.

I know this is picky but the Coverity Scanner is correct
that offset 1 is always 0xff and we have written something
complicated to produce that.

Comments?

-- 
Joel Sherrill, Ph.D.             Director of Research&  Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
    Support Available             (256) 722-9985