-1

我有两种情况我无法解决这些警告.. 这些是重复警告

1) Warning 634: Strong type mismatch (type 'SPI_FSH_HANDLE') in equality or conditional 


            #define SPI_NULL NULL
            SPI_FSH_HANDLE  flash;
            if (flash != SPI_NULL)

我试图检查 NULL 条件,但仍然存在警告。

2)Warning 613: Possible use of null pointer 'flash' in left argument to operator '->'

部分代码:

if (strstr(flash->name, "M25P")!= SPI_NULL) 

我怎样才能避免这两个警告???

4

1 回答 1

0

The second should be fixable by testing flash before dereferencing it.

The first looks like a stupid warning. If you can't disable it, perhaps could be fixed by testing if (flash), if MISRA doesn't have a stupid rule preventing that, or if (flash != SPI_FSH_HANDLE(SPI_NULL)) otherwise. Or perhaps make SPI_NULL a constant of type SPI_FSH_HANDLE or void*, rather than an evil macro that (probably) expands to 0.

于 2014-01-23T12:03:21.213 回答