Lint: calling the function 'memcpy (void *, const void *, std :: size_t)' violates the semantics of '(3n> 4)'

This is part of my code base. I do not understand the meaning of the warning and therefore can not resolve this ... code:

struct ParamsTube{
    uint8                Colours01[4];
    uint8                Colours02[4];
    uint8                Colours03[4];
};

void sample_fun(const uint8 *diagData){
    ParamsTube Record;
    memcpy(&Record.Colours01[0], &diagData[0], 4); //Line 1
    memcpy(&Record.Colours02[0], &diagData[4], 4); //Line 2
    memcpy(&Record.Colours03[0], &diagData[8], 4); //Line 3
}

and warning 426 LINT for this logic in lines 1,2 and 3

Call to function 'memcpy(void *, const void *, std::size_t)' violates semantic '(3n>4)'

Can you tell me what exactly this means?

+3
source share
2 answers

(3n > 4)means that the third argument used for the call memcpy()must be greater than 4, and your calls violate this semantics. It is believed that semantics state that memcpy()it should not be used to copy data smaller than a machine word (usually 4). That is why the bird warns you. Whether semantics are appropriate or not is another question.


426:

426 "" "String". , ( -sem) . "String" - , . :

//lint -sem( f, 1n > 10 && 2n > 10 )  
        void f( int, int );  
        ...  
        f( 2, 20 );  

:

Call to function 'f(int, int)' violates semantic '(1n>10)'

, memcpy() , , lint:

// lint -sem(memcpy, 3n > 4)
void* memcpy(void* s1, const void* s2, std::size_t n);

, , , :

memcpy(&Record.Colours01[0], &diagData[0], 4); //Line 1
memcpy(&Record.Colours02[1], &diagData[4], 4); //Line 2
memcpy(&Record.Colours03[2], &diagData[8], 4); //Line 3

:

memcpy(&Record, diagData, sizeof(Record));  

, .

+7

Lint , memcpy 4 .

.

memcpy . GCC Clang, , , x86 4- memcpy mov. (, , mov .)

, , - , , . , :

*((uint32_t*)&Record.Colours01[0]) = *((uint32_t*)&diagData[0]);

x86, , . diagData[0] 4- ( , ), (ARM , IA-64 Alpha , ).

, Colours01 . , ; .

memcpy , , , , , (, mov x86, , , ).

, , Lint memcpy. , ; .

+1

All Articles